You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

AI.py 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import PyAPI.structures as THUAI6
  2. from PyAPI.Interface import IStudentAPI, ITrickerAPI, IAI
  3. from typing import Union, Final, cast
  4. class Setting:
  5. # 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新
  6. @staticmethod
  7. def asynchronous() -> bool:
  8. return False
  9. # 选手必须修改该函数的返回值来选择自己的阵营
  10. @staticmethod
  11. def playerType() -> THUAI6.PlayerType:
  12. return THUAI6.PlayerType.StudentPlayer
  13. # 选手需要将两个都定义,本份代码中不选择的阵营任意定义即可
  14. @staticmethod
  15. def studentType() -> THUAI6.StudentType:
  16. return THUAI6.StudentType.Athlete
  17. @staticmethod
  18. def trickerType() -> THUAI6.TrickerType:
  19. return THUAI6.TrickerType.Assassin
  20. # 辅助函数
  21. numOfGridPerCell: Final[int] = 1000
  22. class AssistFunction:
  23. @staticmethod
  24. def CellToGrid(cell: int) -> int:
  25. return cell * numOfGridPerCell + numOfGridPerCell // 2
  26. @staticmethod
  27. def GridToCell(grid: int) -> int:
  28. return grid // numOfGridPerCell
  29. class AI(IAI):
  30. # 选手在这里实现自己的逻辑,要求和上面选择的阵营保持一致
  31. def StudentPlay(self, api: IStudentAPI) -> None:
  32. studentSelfInfo = api.GetSelfInfo()
  33. if studentSelfInfo.playerID == 0:
  34. api.SendMessage(1, "Hello, I'm player 0 using python interface!")
  35. if studentSelfInfo.playerID == 1:
  36. api.SendMessage(0, "Hello, I'm player 1 using python interface!")
  37. if api.HaveMessage():
  38. message = api.GetMessage()
  39. api.Print(
  40. f"Recieved Message from player {message[0]}: {message[1]}")
  41. return
  42. def TrickerPlay(self, api: ITrickerAPI) -> None:
  43. return