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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import PyAPI.structures as THUAI6
  2. from PyAPI.Interface import IStudentAPI, ITrickerAPI, IAI
  3. from typing import Union, Final, cast
  4. from PyAPI.constants import Constants
  5. import queue
  6. import time
  7. class Setting:
  8. # 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新
  9. @staticmethod
  10. def asynchronous() -> bool:
  11. return True
  12. # 选手必须修改该函数的返回值来选择自己的阵营
  13. @staticmethod
  14. def playerType() -> THUAI6.PlayerType:
  15. return THUAI6.PlayerType.StudentPlayer
  16. # 选手需要将两个都定义,本份代码中不选择的阵营任意定义即可
  17. @staticmethod
  18. def studentType() -> THUAI6.StudentType:
  19. return THUAI6.StudentType.Athlete
  20. @staticmethod
  21. def trickerType() -> THUAI6.TrickerType:
  22. return THUAI6.TrickerType.Assassin
  23. # 辅助函数
  24. numOfGridPerCell: Final[int] = 1000
  25. class AssistFunction:
  26. @staticmethod
  27. def CellToGrid(cell: int) -> int:
  28. return cell * numOfGridPerCell + numOfGridPerCell // 2
  29. @staticmethod
  30. def GridToCell(grid: int) -> int:
  31. return grid // numOfGridPerCell
  32. path = []
  33. cur = 0
  34. fixedclass = []
  35. class AI(IAI):
  36. # 选手在这里实现自己的逻辑,要求和上面选择的阵营保持一致
  37. def StudentPlay(self, api: IStudentAPI) -> None:
  38. # global fixedclass
  39. # selfInfo = api.GetSelfInfo()
  40. # available = [THUAI6.PlaceType.Land,
  41. # THUAI6.PlaceType.Grass, THUAI6.PlaceType.Door3, THUAI6.PlaceType.Door6, THUAI6.PlaceType.Door5, THUAI6.PlaceType.Gate]
  42. # def bfs(x, y):
  43. # if api.GetPlaceType(x, y) not in available:
  44. # return []
  45. # def GetSuccessors(x, y):
  46. # successors = []
  47. # if x > 0 and api.GetPlaceType(x - 1, y) in available:
  48. # successors.append((x - 1, y))
  49. # if x < 49 and api.GetPlaceType(x + 1, y) in available:
  50. # successors.append((x + 1, y))
  51. # if y > 0 and api.GetPlaceType(x, y - 1) in available:
  52. # successors.append((x, y - 1))
  53. # if y < 49 and api.GetPlaceType(x, y + 1) in available:
  54. # successors.append((x, y + 1))
  55. # return successors
  56. # selfX = AssistFunction.GridToCell(api.GetSelfInfo().x)
  57. # selfY = AssistFunction.GridToCell(api.GetSelfInfo().y)
  58. # frontier = queue.Queue()
  59. # frontier.put((selfX, selfY, []))
  60. # visited = []
  61. # while not frontier.empty():
  62. # currentX, currentY, path = frontier.get()
  63. # if currentX == x and currentY == y:
  64. # return path
  65. # for nextX, nextY in GetSuccessors(currentX, currentY):
  66. # if (nextX, nextY) not in visited:
  67. # visited.append((nextX, nextY))
  68. # frontier.put((nextX, nextY, path + [(nextX, nextY)]))
  69. # return []
  70. # def GoTo(x, y):
  71. # global path, cur
  72. # if path != [] and cur < len(path):
  73. # selfX = api.GetSelfInfo().x
  74. # selfY = api.GetSelfInfo().y
  75. # nextX, nextY = path[cur]
  76. # nextX = AssistFunction.CellToGrid(nextX)
  77. # nextY = AssistFunction.CellToGrid(nextY)
  78. # if selfX < nextX - 100:
  79. # api.MoveDown(10)
  80. # time.sleep(0.01)
  81. # return
  82. # if selfX > nextX + 100:
  83. # api.MoveUp(10)
  84. # time.sleep(0.01)
  85. # return
  86. # if selfY < nextY - 100:
  87. # api.MoveRight(10)
  88. # time.sleep(0.01)
  89. # return
  90. # if selfY > nextY + 100:
  91. # api.MoveLeft(10)
  92. # time.sleep(0.01)
  93. # return
  94. # cur += 1
  95. # return
  96. # else:
  97. # path = bfs(x, y)
  98. # cur = 0
  99. # return
  100. # if (AssistFunction.GridToCell(api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y)) == (6, 6) and api.GetGateProgress(5, 6) < 18000:
  101. # api.StartOpenGate()
  102. # return
  103. # if (AssistFunction.GridToCell(api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y)) == (6, 6) and api.GetGateProgress(5, 6) >= 18000:
  104. # api.Graduate()
  105. # return
  106. # if len(fixedclass) == 7:
  107. # GoTo(6, 6)
  108. # return
  109. # if api.GetPlaceType(AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) == THUAI6.PlaceType.ClassRoom:
  110. # api.Print("Trying to fix!")
  111. # if api.GetClassroomProgress(AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) < 103000:
  112. # api.StartLearning()
  113. # return
  114. # else:
  115. # if (AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) not in fixedclass:
  116. # fixedclass.append(
  117. # (AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)))
  118. # for i in range(50):
  119. # for j in range(50):
  120. # if api.GetPlaceType(i, j) == THUAI6.PlaceType.ClassRoom and (i, j) not in fixedclass:
  121. # if api.GetPlaceType(i - 1, j) in available:
  122. # GoTo(i - 1, j)
  123. # return
  124. api.PrintTricker()
  125. def TrickerPlay(self, api: ITrickerAPI) -> None:
  126. api.UseSkill(0)
  127. api.UseSkill(1)
  128. api.PrintSelfInfo()
  129. return