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 2.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import PyAPI.structures as THUAI6
  2. from PyAPI.Interface import IStudentAPI, ITrickerAPI, IAI
  3. from typing import Union, Final, cast
  4. import time
  5. class Setting:
  6. # 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新
  7. @staticmethod
  8. def asynchronous() -> bool:
  9. return False
  10. # 选手必须修改该函数的返回值来选择自己的阵营
  11. @staticmethod
  12. def playerType() -> THUAI6.PlayerType:
  13. return THUAI6.PlayerType.StudentPlayer
  14. # 选手需要将两个都定义,本份代码中不选择的阵营任意定义即可
  15. @staticmethod
  16. def studentType() -> THUAI6.StudentType:
  17. return THUAI6.StudentType.Athlete
  18. @staticmethod
  19. def trickerType() -> THUAI6.TrickerType:
  20. return THUAI6.TrickerType.Assassin
  21. # 辅助函数
  22. numOfGridPerCell: Final[int] = 1000
  23. class AssistFunction:
  24. @staticmethod
  25. def CellToGrid(cell: int) -> int:
  26. return cell * numOfGridPerCell + numOfGridPerCell // 2
  27. @staticmethod
  28. def GridToCell(grid: int) -> int:
  29. return grid // numOfGridPerCell
  30. arrive: bool = False
  31. class AI(IAI):
  32. # 选手在这里实现自己的逻辑,要求和上面选择的阵营保持一致
  33. def StudentPlay(self, api: IStudentAPI) -> None:
  34. api.Attack(float('nan'))
  35. time.sleep(0.5)
  36. api.PrintSelfInfo()
  37. # api.SendMessage(4, "Hello World!")
  38. # api.PrintSelfInfo()
  39. # global arrive
  40. # if not arrive:
  41. # if api.GetSelfInfo().x < 25500:
  42. # api.MoveDown(50)
  43. # return
  44. # if api.GetSelfInfo().y > 10500:
  45. # api.MoveLeft(50)
  46. # return
  47. # arrive = True
  48. # else:
  49. # api.SkipWindow()
  50. # # time.sleep(1)
  51. # api.PrintSelfInfo()
  52. # if api.GetSelfInfo().y < 18500:
  53. # api.MoveRight(50)
  54. # return
  55. # api.StartLearning()
  56. # if api.GetSelfInfo().y > 7000:
  57. # api.MoveLeft(50)
  58. # return
  59. # if api.GetSelfInfo().x > 20500:
  60. # api.MoveUp(50)
  61. # return
  62. # if api.GetSelfInfo().y > 4500:
  63. # api.MoveLeft(50)
  64. # return
  65. api.PrintTricker()
  66. return
  67. def TrickerPlay(self, api: ITrickerAPI) -> None:
  68. return