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.8 kB

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