forked from eesast/THUAI7
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eesast#109 from GuoWQ222/dev
Update Python CAPI
- Loading branch information
Showing
20 changed files
with
9,893 additions
and
8,843 deletions.
There are no files selected for viewing
6,783 changes: 3,977 additions & 2,806 deletions
6,783
CAPI/cpp/proto/Message2Clients.pb.cc
100755 → 100644
Large diffs are not rendered by default.
Oops, something went wrong.
6,010 changes: 2,695 additions & 3,315 deletions
6,010
CAPI/cpp/proto/Message2Clients.pb.h
100755 → 100644
Large diffs are not rendered by default.
Oops, something went wrong.
2,709 changes: 1,558 additions & 1,151 deletions
2,709
CAPI/cpp/proto/Message2Server.pb.cc
100755 → 100644
Large diffs are not rendered by default.
Oops, something went wrong.
1,943 changes: 820 additions & 1,123 deletions
1,943
CAPI/cpp/proto/Message2Server.pb.h
100755 → 100644
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import PyAPI.structures as THUAI7 | ||
from PyAPI.Interface import IShipAPI, ITeamAPI, IAI | ||
from typing import Union, Final, cast, List | ||
from PyAPI.constants import Constants | ||
import queue | ||
|
||
import time | ||
|
||
|
||
class Setting: | ||
# 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新,大致一帧更新一次 | ||
@staticmethod | ||
def asynchronous() -> bool: | ||
return False | ||
|
||
|
||
numOfGridPerCell: Final[int] = 1000 | ||
|
||
|
||
class AssistFunction: | ||
@staticmethod | ||
def CellToGrid(cell: int) -> int: | ||
return cell * numOfGridPerCell + numOfGridPerCell // 2 | ||
|
||
@staticmethod | ||
def GridToCell(grid: int) -> int: | ||
return grid // numOfGridPerCell | ||
|
||
|
||
class AI(IAI): | ||
def __init__(self, pID: int): | ||
self.__playerID = pID | ||
|
||
def ShipPlay(self, api: IShipAPI) -> None: | ||
# 公共操作 | ||
|
||
if self.__playerID == 0: | ||
# player0的操作 | ||
return | ||
elif self.__playerID == 1: | ||
# player1的操作 | ||
return | ||
elif self.__playerID == 2: | ||
# player2的操作 | ||
return | ||
return | ||
|
||
def TeamPlay(self, api: ITeamAPI) -> None: | ||
# 操作 | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,222 @@ | ||
import PyAPI.structures as THUAI6 | ||
from PyAPI.Interface import ILogic, IStudentAPI, ITrickerAPI, IGameTimer, IAI | ||
import PyAPI.structures as THUAI7 | ||
from PyAPI.Interface import ILogic, IShipAPI, ITeamAPI, IGameTimer, IAI | ||
from math import pi | ||
from concurrent.futures import ThreadPoolExecutor, Future | ||
from typing import List, cast, Tuple, Union | ||
|
||
|
||
class ShipAPI(IShipAPI, IGameTimer): | ||
def __init__(self, logic: ILogic) -> None: | ||
self.__logic = logic | ||
self.__pool = ThreadPoolExecutor(20) | ||
|
||
def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.move, timeInMilliseconds, angle) | ||
|
||
def MoveRight(self, timeInMilliseconds: int) -> Future[bool]: | ||
return self.Move(timeInMilliseconds, pi * 0.5) | ||
|
||
def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]: | ||
return self.Move(timeInMilliseconds, pi * 1.5) | ||
|
||
def MoveUp(self, timeInMilliseconds: int) -> Future[bool]: | ||
return self.Move(timeInMilliseconds, pi) | ||
|
||
def MoveDown(self, timeInMilliseconds: int) -> Future[bool]: | ||
return self.Move(timeInMilliseconds, 0) | ||
|
||
def Attack(self, angle: float) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.Attack, angle) | ||
|
||
def Recover(self) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.Recover) | ||
|
||
def Produce(self) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.Produce) | ||
|
||
def Rebuild(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.Rebuild, constructionType) | ||
|
||
def Construct(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.Construct, constructionType) | ||
|
||
def GetFrameCount(self) -> int: | ||
return self.__logic.GetFrameCount() | ||
|
||
def Wait(self) -> bool: | ||
if self.__logic.GetCounter() == -1: | ||
return False | ||
else: | ||
return self.__logic.WaitThread() | ||
|
||
def EndAllAction(self) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.EndAllAction) | ||
|
||
def SendMessage(self, toID: int, message: Union[str, bytes]) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.SendMessage, toID, message) | ||
|
||
def HaveMessage(self) -> bool: | ||
return self.__logic.HaveMessage() | ||
|
||
def GetMessage(self) -> Tuple[int, Union[str, bytes]]: | ||
return self.__logic.GetMessage() | ||
|
||
def GetShips(self) -> List[THUAI7.Ship]: | ||
return self.__logic.GetShips() | ||
|
||
def GetEnemyShips(self) -> List[THUAI7.Ship]: | ||
return self.__logic.GetEnemyShips() | ||
|
||
def GetBullets(self) -> List[THUAI7.Bullet]: | ||
return self.__logic.GetBullets() | ||
|
||
def GetFullMap(self) -> List[List[THUAI7.PlaceType]]: | ||
return self.__logic.GetFullMap() | ||
|
||
def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: | ||
return self.__logic.GetPlaceType(cellX, cellY) | ||
|
||
def GetConstructionHp(self, cellX: int, cellY: int) -> int: | ||
return self.__logic.GetConstructionHp(cellX, cellY) | ||
|
||
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 GetHomeHp(self) -> int: | ||
return self.__logic.GetHomeHp() | ||
|
||
def GetGameInfo(self) -> THUAI7.GameInfo: | ||
return self.__logic.GetGameInfo() | ||
|
||
def GetPlayerGUIDs(self) -> List[int]: | ||
return self.__logic.GetPlayerGUIDs() | ||
|
||
def GetSelfInfo(self) -> THUAI7.Ship: | ||
return cast(THUAI7.Ships, self.__logic.GetSelfInfo()) | ||
|
||
def GetMoney(self) -> int: | ||
return self.__logic.GetMoney() | ||
|
||
def GetScore(self) -> int: | ||
return self.__logic.GetScore() | ||
|
||
def HaveView(self, gridX: int, gridY: int) -> bool: | ||
return self.__logic.HaveView(gridX, gridY, self.GetSelfInfo().x, | ||
self.GetSelfInfo().y, self.GetSelfInfo().viewRange) | ||
|
||
def Print(self, cont: str) -> None: | ||
pass | ||
|
||
def PrintShip(self) -> None: | ||
pass | ||
|
||
def PrintSelfInfo(self) -> None: | ||
pass | ||
|
||
def StartTimer(self) -> None: | ||
pass | ||
|
||
def EndTimer(self) -> None: | ||
pass | ||
|
||
def Play(self, ai: IAI) -> None: | ||
ai.ShipPlay(self) | ||
|
||
|
||
class TeamAPI(ITeamAPI, IGameTimer): | ||
def __init__(self, logic: ILogic) -> None: | ||
self.__logic = logic | ||
self.__pool = ThreadPoolExecutor(20) | ||
|
||
def StartTimer(self) -> None: | ||
pass | ||
|
||
def EndTimer(self) -> None: | ||
pass | ||
|
||
def Play(self, ai: IAI) -> None: | ||
ai.TeamPlay(self) | ||
|
||
def SendMessage(self, toID: int, message: Union[str, bytes]) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.SendMessage, toID, message) | ||
|
||
def HaveMessage(self) -> bool: | ||
return self.__logic.HaveMessage() | ||
|
||
def GetMessage(self) -> Tuple[int, Union[str, bytes]]: | ||
return self.__logic.GetMessage() | ||
|
||
def GetFrameCount(self) -> int: | ||
return self.__logic.GetFrameCount() | ||
|
||
def Wait(self) -> bool: | ||
if self.__logic.GetCounter() == -1: | ||
return False | ||
else: | ||
return self.__logic.WaitThread() | ||
|
||
def EndAllAction(self) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.EndAllAction) | ||
|
||
def GetBullets(self) -> List[THUAI7.Bullet]: | ||
return self.__logic.GetBullets() | ||
|
||
def GetShips(self) -> List[THUAI7.Ship]: | ||
return self.__logic.GetShips() | ||
|
||
def GetEnemyShips(self) -> List[THUAI7.Ship]: | ||
return self.__logic.GetEnemyShips() | ||
|
||
def GetFullMap(self) -> List[List[THUAI7.PlaceType]]: | ||
return self.__logic.GetFullMap() | ||
|
||
def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: | ||
return self.__logic.GetPlaceType(cellX, cellY) | ||
|
||
def GetConstructionHp(self, cellX: int, cellY: int) -> int: | ||
return self.__logic.GetConstructionHp(cellX, cellY) | ||
|
||
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 GetHomeHp(self) -> int: | ||
return self.__logic.GetHomeHp() | ||
|
||
def GetGameInfo(self) -> THUAI7.GameInfo: | ||
return self.__logic.GetGameInfo() | ||
|
||
def GetPlayerGUIDs(self) -> List[int]: | ||
return self.__logic.GetPlayerGUIDs() | ||
|
||
def GetSelfInfo(self) -> THUAI7.Home: | ||
return cast(THUAI7.Home, self.__logic.GetSelfInfo()) | ||
|
||
def GetScore(self) -> int: | ||
return self.__logic.GetScore() | ||
|
||
def GetMoney(self) -> int: | ||
return self.__logic.GetMoney() | ||
|
||
def InstallModule(self, ID: int, type: THUAI7.ModuleType) -> Future[bool]: | ||
return self.__pool.submit(self.__logic.InstallModule, ID, type) | ||
|
||
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]: | ||
return self.__pool.submit(self.__logic.BuildShip, shipType, cellX, cellY) | ||
|
||
def Print(self, string: str) -> None: | ||
pass | ||
|
||
def PrintTeam(self) -> None: | ||
pass | ||
|
||
def PrintSelfInfo(self) -> None: | ||
pass |
Oops, something went wrong.