From 0f46fb20a0da5ebf9bb49d29f541fede13406a35 Mon Sep 17 00:00:00 2001 From: DragonAura Date: Mon, 24 Apr 2023 20:08:12 +0800 Subject: [PATCH] fix(CAPI): :bug: fix wrong __init__ --- CAPI/python/PyAPI/AI.py | 2 +- CAPI/python/PyAPI/State.py | 30 +++++++---- CAPI/python/PyAPI/structures.py | 91 +++++++++++++++++++++++++++++---- CAPI/python/PyAPI/utils.py | 6 --- CAPI/python/run.sh | 10 ++-- 5 files changed, 108 insertions(+), 31 deletions(-) diff --git a/CAPI/python/PyAPI/AI.py b/CAPI/python/PyAPI/AI.py index 010a3dc..efa1a1a 100644 --- a/CAPI/python/PyAPI/AI.py +++ b/CAPI/python/PyAPI/AI.py @@ -11,7 +11,7 @@ class Setting: # 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新 @staticmethod def asynchronous() -> bool: - return True + return False # 选手需要依次将player0到player4的职业都定义 @staticmethod diff --git a/CAPI/python/PyAPI/State.py b/CAPI/python/PyAPI/State.py index f2eb339..d493617 100644 --- a/CAPI/python/PyAPI/State.py +++ b/CAPI/python/PyAPI/State.py @@ -3,21 +3,33 @@ import PyAPI.structures as THUAI6 class State: + def __init__(self, **kwargs) -> None: + self.teamScore = 0 + self.self = THUAI6.Student() + self.students = [] + self.trickers = [] + self.props = [] + self.gameMap = [] + self.bullets = [] + self.bombedBullets = [] + self.mapInfo = THUAI6.GameMap() + self.gameInfo = THUAI6.GameInfo() + self.guids = [] teamScore: int self: Union[THUAI6.Student, THUAI6.Tricker] - students: List[THUAI6.Student] = [] - trickers: List[THUAI6.Tricker] = [] + students: List[THUAI6.Student] + trickers: List[THUAI6.Tricker] - props: List[THUAI6.Prop] = [] + props: List[THUAI6.Prop] - gameMap: List[List[THUAI6.PlaceType]] = [] + gameMap: List[List[THUAI6.PlaceType]] - bullets: List[THUAI6.Bullet] = [] - bombedBullets: List[THUAI6.BombedBullet] = [] + bullets: List[THUAI6.Bullet] + bombedBullets: List[THUAI6.BombedBullet] - mapInfo: THUAI6.GameMap = THUAI6.GameMap() + mapInfo: THUAI6.GameMap - gameInfo: THUAI6.GameInfo = THUAI6.GameInfo() + gameInfo: THUAI6.GameInfo - guids: List[int] = [] + guids: List[int] diff --git a/CAPI/python/PyAPI/structures.py b/CAPI/python/PyAPI/structures.py index 939f452..d37e607 100644 --- a/CAPI/python/PyAPI/structures.py +++ b/CAPI/python/PyAPI/structures.py @@ -143,6 +143,22 @@ class HiddenGateState(Enum): class Player: + def __init__(self, **kwargs) -> None: + self.x = 0 + self.y = 0 + self.speed = 0 + self.viewRange = 0 + self.playerID = 0 + self.guid = 0 + self.radius = 0 + self.score = 0 + self.facingDirection = 0.0 + self.timeUntilSkillAvailable = [] + self.playerType = PlayerType.NullPlayerType + self.prop = [] + self.place = PlaceType.NullPlaceType + self.bulletType = BulletType.NullBulletType + self.playerState = PlayerState.NullState x: int y: int speed: int @@ -152,15 +168,26 @@ class Player: radius: int score: int facingDirection: float - timeUntilSkillAvailable: List[float] = [] + timeUntilSkillAvailable: List[float] playerType: PlayerType - prop: List[PropType] = [] + prop: List[PropType] place: PlaceType bulletType: BulletType playerState: PlayerState class Student(Player): + def __init__(self, **kwargs) -> None: + super().__init__() + self.studentType = StudentType.NullStudentType + self.determination = 0 + self.addiction = 0 + self.encourageProgress = 0 + self.rouseProgress = 0 + self.learningSpeed = 0 + self.encourageSpeed = 0 + self.dangerAlert = 0.0 + self.buff = [] studentType: StudentType determination: int addiction: int @@ -169,17 +196,30 @@ class Student(Player): learningSpeed: int encourageSpeed: int dangerAlert: float - buff: List[StudentBuffType] = [] + buff: List[StudentBuffType] class Tricker(Player): + def __init__(self, **kwargs) -> None: + super().__init__() + self.trickerType = TrickerType.NullTrickerType + self.trickDesire = 0.0 + self.classVolume = 0.0 + self.buff = [] trickerType: TrickerType trickDesire: float classVolume: float - buff: List[TrickerBuffType] = [] + buff: List[TrickerBuffType] class Prop: + def __init__(self, **kwargs) -> None: + self.x = 0 + self.y = 0 + self.guid = 0 + self.type = PropType.NullPropType + self.place = PlaceType.NullPlaceType + self.facingDirection = 0.0 x: int y: int guid: int @@ -189,6 +229,16 @@ class Prop: class Bullet: + def __init__(self, **kwargs) -> None: + self.bulletType = BulletType.NullBulletType + self.x = 0 + self.y = 0 + self.facingDirection = 0.0 + self.guid = 0 + self.team = PlayerType.NullPlayerType + self.place = PlaceType.NullPlaceType + self.bombRange = 0.0 + self.speed = 0 bulletType: BulletType x: int y: int @@ -201,6 +251,13 @@ class Bullet: class BombedBullet: + def __init__(self, **kwargs) -> None: + self.bulletType = BulletType.NullBulletType + self.x = 0 + self.y = 0 + self.facingDirection = 0.0 + self.mappingID = 0 + self.bombRange = 0.0 bulletType: BulletType x: int y: int @@ -210,15 +267,29 @@ class BombedBullet: class GameMap: - classroomState: Dict[Tuple[int, int], int] = {} - gateState: Dict[Tuple[int, int], int] = {} - chestState: Dict[Tuple[int, int], int] = {} - doorState: Dict[Tuple[int, int], bool] = {} - doorProgress: Dict[Tuple[int, int], int] = {} - hiddenGateState: Dict[Tuple[int, int], HiddenGateState] = {} + def __init__(self, **kwargs) -> None: + self.classroomState = {} + self.gateState = {} + self.chestState = {} + self.doorState = {} + self.doorProgress = {} + self.hiddenGateState = {} + classroomState: Dict[Tuple[int, int], int] + gateState: Dict[Tuple[int, int], int] + chestState: Dict[Tuple[int, int], int] + doorState: Dict[Tuple[int, int], bool] + doorProgress: Dict[Tuple[int, int], int] + hiddenGateState: Dict[Tuple[int, int], HiddenGateState] class GameInfo: + def __init__(self, **kwargs) -> None: + self.gameTime = 0 + self.subjectFinished = 0 + self.studentGraduated = 0 + self.studentQuited = 0 + self.studentScore = 0 + self.trickerScore = 0 gameTime: int subjectFinished: int studentGraduated: int diff --git a/CAPI/python/PyAPI/utils.py b/CAPI/python/PyAPI/utils.py index e286212..f713229 100644 --- a/CAPI/python/PyAPI/utils.py +++ b/CAPI/python/PyAPI/utils.py @@ -177,12 +177,10 @@ class Proto2THUAI6(NoInstance): tricker.trickDesire = trickerMsg.trick_desire tricker.classVolume = trickerMsg.class_volume tricker.bulletType = Proto2THUAI6.bulletTypeDict[trickerMsg.bullet_type] - tricker.timeUntilSkillAvailable.clear() for time in trickerMsg.time_until_skill_available: tricker.timeUntilSkillAvailable.append(time) tricker.place = Proto2THUAI6.placeTypeDict[trickerMsg.place] tricker.playerState = Proto2THUAI6.playerStateDict[trickerMsg.player_state] - tricker.prop.clear() for item in trickerMsg.prop: tricker.prop.append(Proto2THUAI6.propTypeDict[item]) tricker.trickerType = Proto2THUAI6.trickerTypeDict[trickerMsg.tricker_type] @@ -190,7 +188,6 @@ class Proto2THUAI6(NoInstance): tricker.playerID = trickerMsg.player_id tricker.viewRange = trickerMsg.view_range tricker.radius = trickerMsg.radius - tricker.buff.clear() for buff in trickerMsg.buff: tricker.buff.append(Proto2THUAI6.trickerBuffTypeDict[buff]) tricker.playerType = THUAI6.PlayerType.TrickerPlayer @@ -212,11 +209,9 @@ class Proto2THUAI6(NoInstance): student.encourageProgress = studentMsg.treat_progress student.rouseProgress = studentMsg.rescue_progress student.dangerAlert = studentMsg.danger_alert - student.timeUntilSkillAvailable.clear() for time in studentMsg.time_until_skill_available: student.timeUntilSkillAvailable.append(time) student.place = Proto2THUAI6.placeTypeDict[studentMsg.place] - student.prop.clear() for item in studentMsg.prop: student.prop.append(Proto2THUAI6.propTypeDict[item]) student.studentType = Proto2THUAI6.studentTypeDict[studentMsg.student_type] @@ -225,7 +220,6 @@ class Proto2THUAI6(NoInstance): student.playerID = studentMsg.player_id student.viewRange = studentMsg.view_range student.radius = studentMsg.radius - student.buff.clear() for buff in studentMsg.buff: student.buff.append(Proto2THUAI6.studentBuffTypeDict[buff]) student.playerType = THUAI6.PlayerType.StudentPlayer diff --git a/CAPI/python/run.sh b/CAPI/python/run.sh index f41c458..5efb5a6 100755 --- a/CAPI/python/run.sh +++ b/CAPI/python/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 0 -d -o & -python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 1 -d & -python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 2 -d & -python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 3 -d & -# python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 4 -d & \ No newline at end of file +python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 0 -d -o& +python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 1& +# python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 2& +# python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 3& +# python PyAPI/main.py -I 172.22.32.1 -P 8888 -p 4& \ No newline at end of file