Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Grange007 authored Mar 23, 2024
2 parents e93e626 + b16528f commit 3273726
Show file tree
Hide file tree
Showing 74 changed files with 2,752 additions and 414 deletions.
9 changes: 8 additions & 1 deletion CAPI/python/PyAPI/AI.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
class Setting:
# 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新,大致一帧更新一次
@staticmethod
def asynchronous() -> bool:
def Asynchronous() -> bool:
return False

@staticmethod
def SweeperTypes()->List[THUAI7.SweeperType]:
return [THUAI7.SweeperType.CivilianSweeper,
THUAI7.SweeperType.MilitarySweeper,
THUAI7.SweeperType.MilitarySweeper,
THUAI7.SweeperType.FlagSweeper]


numOfGridPerCell: Final[int] = 1000
Expand Down
19 changes: 11 additions & 8 deletions CAPI/python/PyAPI/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def HaveMessage(self) -> bool:
def GetMessage(self) -> Tuple[int, Union[str, bytes]]:
return self.__logic.GetMessage()

def GetShips(self) -> List[THUAI7.Ship]:
def GetShips(self) -> List[THUAI7.Sweeper]:
return self.__logic.GetShips()

def GetEnemyShips(self) -> List[THUAI7.Ship]:
def GetEnemyShips(self) -> List[THUAI7.Sweeper]:
return self.__logic.GetEnemyShips()

def GetBullets(self) -> List[THUAI7.Bullet]:
Expand All @@ -82,8 +82,8 @@ def GetConstructionHp(self, cellX: int, cellY: int) -> int:
def GetWormHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetWormHp(cellX, cellY)

def GetResouceState(self, cellX: int, cellY: int) -> int:
return self.__logic.GetResouceState(cellX, cellY)
def GetResourceState(self, cellX: int, cellY: int) -> int:
return self.__logic.GetResourceState(cellX, cellY)

def GetHomeHp(self) -> int:
return self.__logic.GetHomeHp()
Expand All @@ -94,7 +94,7 @@ def GetGameInfo(self) -> THUAI7.GameInfo:
def GetPlayerGUIDs(self) -> List[int]:
return self.__logic.GetPlayerGUIDs()

def GetSelfInfo(self) -> THUAI7.Ship:
def GetSelfInfo(self) -> THUAI7.Sweeper:
return cast(THUAI7.Ships, self.__logic.GetSelfInfo())

def GetMoney(self) -> int:
Expand All @@ -114,6 +114,9 @@ def Print(self, cont: str) -> None:
def PrintShip(self) -> None:
pass

def PrintTeam(self) -> None:
pass

def PrintSelfInfo(self) -> None:
pass

Expand Down Expand Up @@ -165,10 +168,10 @@ def EndAllAction(self) -> Future[bool]:
def GetBullets(self) -> List[THUAI7.Bullet]:
return self.__logic.GetBullets()

def GetShips(self) -> List[THUAI7.Ship]:
def GetShips(self) -> List[THUAI7.Sweeper]:
return self.__logic.GetShips()

def GetEnemyShips(self) -> List[THUAI7.Ship]:
def GetEnemyShips(self) -> List[THUAI7.Sweeper]:
return self.__logic.GetEnemyShips()

def GetFullMap(self) -> List[List[THUAI7.PlaceType]]:
Expand Down Expand Up @@ -210,7 +213,7 @@ def InstallModule(self, ID: int, type: THUAI7.ModuleType) -> Future[bool]:
def Recycle(self, ID: int) -> Future[bool]:
return self.__pool.submit(self.__logic.Recycle, ID)

def BuildShip(self, shipType: THUAI7.ShipType, cellX: int, cellY: int) -> Future[bool]:
def BuildShip(self, shipType: THUAI7.SweeperType, cellX: int, cellY: int) -> Future[bool]:
return self.__pool.submit(self.__logic.BuildShip, shipType, cellX, cellY)

def Print(self, string: str) -> None:
Expand Down
10 changes: 5 additions & 5 deletions CAPI/python/PyAPI/Communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ def Recycle(self, playerID: int, teamID: int) -> bool:
else:
return recycleResult.act_success

def BuildShip(self, cellX: int, cellY: int, shipType: THUAI7.ShipType, teamID: int) -> bool:
def BuildShip(self, cellX: int, cellY: int, shipType: THUAI7.SweeperType, teamID: int) -> bool:
try:
with self.__mtxLimit:
if self.__counter >= self.__limit:
return False
self.__counter += 1
buildResult: Message2Clients.BoolRes = self.__THUAI7Stub.BuildShip(
THUAI72Proto.THUAI72ProtobufBuildShipMsg(teamID, shipType, cellX, cellY)
THUAI72Proto.THUAI72ProtobufBuildSweeperMsg(teamID, shipType, cellX, cellY)
)
except grpc.RpcError:
return False
Expand All @@ -220,11 +220,11 @@ def GetMessage2Client(self) -> Message2Clients.MessageToClient:
self.__haveNewMessage = False
return self.__message2Client

def AddPlayer(self, playerID: int, teamID: int, cellX: int, cellY: int, shipType: THUAI7.ShipType) -> None:
def AddPlayer(self, playerID: int, teamID: int, shipType: THUAI7.SweeperType) -> None:
def tMessage():
try:
if playerID == 0:
playerMsg = THUAI72Proto.THUAI72ProtobufPlayerMsg(playerID, teamID, shipType, cellX, cellY)
playerMsg = THUAI72Proto.THUAI72ProtobufPlayerMsg(playerID, teamID, shipType)
for msg in self.__THUAI7Stub.AddPlayer(playerMsg):
with self.__cvMessage:
self.__haveNewMessage = True
Expand All @@ -234,7 +234,7 @@ def tMessage():
self.__counter = 0
self.__counterMove = 0
elif playerID >= 1 and playerID <= 8:
playerMsg = THUAI72Proto.THUAI72ProtobufPlayerMsg(playerID, teamID, shipType, cellX, cellY)
playerMsg = THUAI72Proto.THUAI72ProtobufPlayerMsg(playerID, teamID, shipType)
for msg in self.__THUAI7Stub.AddPlayer(playerMsg):
with self.__cvMessage:
self.__haveNewMessage = True
Expand Down
24 changes: 10 additions & 14 deletions CAPI/python/PyAPI/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class ILogic(metaclass=ABCMeta):
'''`IAPI` 统一可用的接口'''

@abstractmethod
def GetShips(self) -> List[THUAI7.Ship]:
def GetShips(self) -> List[THUAI7.Sweeper]:
pass

@abstractmethod
def GetEnemyShips(self) -> List[THUAI7.Ship]:
def GetEnemyShips(self) -> List[THUAI7.Sweeper]:
pass

@abstractmethod
def GetBullets(self) -> List[THUAI7.Bullet]:
pass

@abstractmethod
def GetSelfInfo(self) -> Union[THUAI7.Ship, THUAI7.Team]:
def GetSelfInfo(self) -> Union[THUAI7.Sweeper, THUAI7.Team]:
pass

@abstractmethod
Expand Down Expand Up @@ -127,7 +127,7 @@ def InstallModule(self, playerID: int, moduleType: THUAI7.ModuleType) -> bool:
pass

@abstractmethod
def BuildShip(self, shipType: THUAI7.ShipType, cellX: int, cellY: int) -> bool:
def BuildShip(self, shipType: THUAI7.SweeperType, cellX: int, cellY: int) -> bool:
pass


Expand All @@ -141,11 +141,7 @@ class IAPI(metaclass=ABCMeta):
'''

@abstractmethod
def SendTextMessage(self, toPlayerID: int, message: str) -> Future[bool]:
pass

@abstractmethod
def SendBinaryMessage(self, toPlayerID: int, message: str) -> Future[bool]:
def SendMessage(self, toPlayerID: int, message: Union[str, bytes]) -> Future[bool]:
pass

@abstractmethod
Expand Down Expand Up @@ -176,11 +172,11 @@ def EndAllAction(self) -> Future[bool]:
pass

@abstractmethod
def GetShips(self) -> List[THUAI7.Ship]:
def GetShips(self) -> List[THUAI7.Sweeper]:
pass

@abstractmethod
def GetEnemyShips(self) -> List[THUAI7.Ship]:
def GetEnemyShips(self) -> List[THUAI7.Sweeper]:
pass

@abstractmethod
Expand Down Expand Up @@ -244,7 +240,7 @@ def PrintSelfInfo(self) -> None:
pass

@abstractmethod
def GetSelfInfo(self) -> Union[THUAI7.Ship, THUAI7.Team]:
def GetSelfInfo(self) -> Union[THUAI7.Sweeper, THUAI7.Team]:
pass


Expand Down Expand Up @@ -290,7 +286,7 @@ def Construct(self, constructionType: THUAI7.ConstructionType) -> Future[bool]:
pass

@abstractmethod
def GetSelfInfo(self) -> THUAI7.Ship:
def GetSelfInfo(self) -> THUAI7.Sweeper:
pass

@abstractmethod
Expand All @@ -312,7 +308,7 @@ def Recycle(self, playerID: int) -> Future[bool]:
pass

@abstractmethod
def BuildShip(self, shipType: THUAI7.ShipType, cellX: int, cellY: int) -> Future[bool]:
def BuildShip(self, shipType: THUAI7.SweeperType, cellX: int, cellY: int) -> Future[bool]:
pass


Expand Down
12 changes: 6 additions & 6 deletions CAPI/python/PyAPI/State.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@


class State:
def __init__(self, **kwargs) -> None:
def __init__(self) -> None:
self.teamScore = 0
self.self = THUAI7.Ship()
self.self = THUAI7.Sweeper()
self.ships = []
self.enemyShips = []
self.enemySweepers = []
self.teams = []
self.gameMap = []
self.bullets = []
Expand All @@ -17,10 +17,10 @@ def __init__(self, **kwargs) -> None:
self.guids = []

teamScore: int
self: Union[THUAI7.Ship, THUAI7.Team]
self: Union[THUAI7.Sweeper, THUAI7.Team]

ships: List[THUAI7.Ship]
enemyShips: List[THUAI7.Ship]
ships: List[THUAI7.Sweeper]
enemySweepers: List[THUAI7.Sweeper]

teams: List[THUAI7.Team]

Expand Down
18 changes: 9 additions & 9 deletions CAPI/python/PyAPI/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,53 @@ class Constants:
numofGridPerCell = 1000
rows = 50
cols = 50
maxResourceProgress = 200
maxWormholeHp = 18000
maxGarbageProgress = 200
maxBridgeHp = 18000
robPercent = 0.2
destroyBuildingBonus = 200
recoverMultiplier = 1.2
recycleMultiplier = 0.5

sizeOfShip = 800
sizeOfSweeper = 800


class Home:
maxHp = 24000
energySpeed = 1


class Factory:
class RecycleBank:
maxHp = 8000
energySpeed = 3


class Community:
class ChargeStation:
maxHp = 6000


class Fort:
class SignalTower:
maxHp = 12000
attackRange = 8000
damage = 1200


class CivilianShip:
class CivilianSweeper:
Speed = 3000
basicArmor = 0
basicShield = 0
maxHp = 3000
Cost = 40


class MilitaryShip:
class MilitarySweeper:
Speed = 2800
basicArmor = 400
basicShield = 400
maxHp = 4000
Cost = 120


class FlagShip:
class FlagSweeper:
Speed = 2700
basicArmor = 800
basicShield = 800
Expand Down
Loading

0 comments on commit 3273726

Please sign in to comment.