|
|
|
@@ -50,138 +50,101 @@ fixedclass = [] |
|
|
|
class AI(IAI): |
|
|
|
# 选手在这里实现自己的逻辑,要求和上面选择的阵营保持一致 |
|
|
|
def StudentPlay(self, api: IStudentAPI) -> None: |
|
|
|
global fixedclass |
|
|
|
selfInfo = api.GetSelfInfo() |
|
|
|
available = [THUAI6.PlaceType.Land, |
|
|
|
THUAI6.PlaceType.Grass, THUAI6.PlaceType.Door3, THUAI6.PlaceType.Door6, THUAI6.PlaceType.Door5, THUAI6.PlaceType.Gate] |
|
|
|
|
|
|
|
def bfs(x, y): |
|
|
|
if api.GetPlaceType(x, y) not in available: |
|
|
|
return [] |
|
|
|
|
|
|
|
def GetSuccessors(x, y): |
|
|
|
successors = [] |
|
|
|
if x > 0 and api.GetPlaceType(x - 1, y) in available: |
|
|
|
successors.append((x - 1, y)) |
|
|
|
if x < 49 and api.GetPlaceType(x + 1, y) in available: |
|
|
|
successors.append((x + 1, y)) |
|
|
|
if y > 0 and api.GetPlaceType(x, y - 1) in available: |
|
|
|
successors.append((x, y - 1)) |
|
|
|
if y < 49 and api.GetPlaceType(x, y + 1) in available: |
|
|
|
successors.append((x, y + 1)) |
|
|
|
return successors |
|
|
|
selfX = AssistFunction.GridToCell(api.GetSelfInfo().x) |
|
|
|
selfY = AssistFunction.GridToCell(api.GetSelfInfo().y) |
|
|
|
frontier = queue.Queue() |
|
|
|
frontier.put((selfX, selfY, [])) |
|
|
|
visited = [] |
|
|
|
while not frontier.empty(): |
|
|
|
currentX, currentY, path = frontier.get() |
|
|
|
if currentX == x and currentY == y: |
|
|
|
return path |
|
|
|
for nextX, nextY in GetSuccessors(currentX, currentY): |
|
|
|
if (nextX, nextY) not in visited: |
|
|
|
visited.append((nextX, nextY)) |
|
|
|
frontier.put((nextX, nextY, path + [(nextX, nextY)])) |
|
|
|
return [] |
|
|
|
|
|
|
|
def GoTo(x, y): |
|
|
|
global path, cur |
|
|
|
if path != [] and cur < len(path): |
|
|
|
selfX = api.GetSelfInfo().x |
|
|
|
selfY = api.GetSelfInfo().y |
|
|
|
nextX, nextY = path[cur] |
|
|
|
nextX = AssistFunction.CellToGrid(nextX) |
|
|
|
nextY = AssistFunction.CellToGrid(nextY) |
|
|
|
if selfX < nextX - 100: |
|
|
|
api.MoveDown(10) |
|
|
|
time.sleep(0.01) |
|
|
|
return |
|
|
|
if selfX > nextX + 100: |
|
|
|
api.MoveUp(10) |
|
|
|
time.sleep(0.01) |
|
|
|
return |
|
|
|
if selfY < nextY - 100: |
|
|
|
api.MoveRight(10) |
|
|
|
time.sleep(0.01) |
|
|
|
return |
|
|
|
if selfY > nextY + 100: |
|
|
|
api.MoveLeft(10) |
|
|
|
time.sleep(0.01) |
|
|
|
return |
|
|
|
cur += 1 |
|
|
|
return |
|
|
|
else: |
|
|
|
path = bfs(x, y) |
|
|
|
cur = 0 |
|
|
|
return |
|
|
|
|
|
|
|
if (AssistFunction.GridToCell(api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y)) == (6, 6) and api.GetGateProgress(5, 6) < 18000: |
|
|
|
api.StartOpenGate() |
|
|
|
return |
|
|
|
|
|
|
|
if (AssistFunction.GridToCell(api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y)) == (6, 6) and api.GetGateProgress(5, 6) >= 18000: |
|
|
|
api.Graduate() |
|
|
|
return |
|
|
|
|
|
|
|
if len(fixedclass) == 7: |
|
|
|
GoTo(6, 6) |
|
|
|
return |
|
|
|
|
|
|
|
if api.GetPlaceType(AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) == THUAI6.PlaceType.ClassRoom: |
|
|
|
if api.GetSelfInfo().playerID == 0: |
|
|
|
api.Print("Trying to fix!") |
|
|
|
if api.GetClassroomProgress(AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) < 103000: |
|
|
|
api.StartLearning() |
|
|
|
return |
|
|
|
else: |
|
|
|
if (AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) not in fixedclass: |
|
|
|
fixedclass.append( |
|
|
|
(AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y))) |
|
|
|
elif api.GetSelfInfo().playerID == 1: |
|
|
|
if api.GetClassroomProgress(AssistFunction.GridToCell(api.GetSelfInfo().x) - 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) < 103000: |
|
|
|
api.StartLearning() |
|
|
|
return |
|
|
|
else: |
|
|
|
fixedclass.append((AssistFunction.GridToCell( |
|
|
|
api.GetSelfInfo().x) - 1, AssistFunction.GridToCell(api.GetSelfInfo().y))) |
|
|
|
elif api.GetSelfInfo().playerID == 2: |
|
|
|
if api.GetClassroomProgress(AssistFunction.GridToCell(api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y) + 1) < 103000: |
|
|
|
api.StartLearning() |
|
|
|
return |
|
|
|
else: |
|
|
|
fixedclass.append((AssistFunction.GridToCell( |
|
|
|
api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y) + 1)) |
|
|
|
elif api.GetSelfInfo().playerID == 3: |
|
|
|
if api.GetClassroomProgress(AssistFunction.GridToCell(api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y) - 1) < 103000: |
|
|
|
api.StartLearning() |
|
|
|
return |
|
|
|
else: |
|
|
|
fixedclass.append((AssistFunction.GridToCell( |
|
|
|
api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y) - 1)) |
|
|
|
|
|
|
|
for i in range(50): |
|
|
|
for j in range(50): |
|
|
|
if api.GetSelfInfo().playerID == 0: |
|
|
|
if api.GetPlaceType(i, j) == THUAI6.PlaceType.ClassRoom and (i, j) not in fixedclass: |
|
|
|
if api.GetPlaceType(i - 1, j) in available: |
|
|
|
GoTo(i - 1, j) |
|
|
|
return |
|
|
|
elif api.GetSelfInfo().playerID == 1: |
|
|
|
if api.GetPlaceType(i, j) == THUAI6.PlaceType.ClassRoom and (i, j) not in fixedclass: |
|
|
|
if api.GetPlaceType(i + 1, j) in available: |
|
|
|
GoTo(i + 1, j) |
|
|
|
return |
|
|
|
elif api.GetSelfInfo().playerID == 2: |
|
|
|
if api.GetPlaceType(i, j) == THUAI6.PlaceType.ClassRoom and (i, j) not in fixedclass: |
|
|
|
if api.GetPlaceType(i, j - 1) in available: |
|
|
|
GoTo(i, j - 1) |
|
|
|
return |
|
|
|
elif api.GetSelfInfo().playerID == 3: |
|
|
|
if api.GetPlaceType(i, j) == THUAI6.PlaceType.ClassRoom and (i, j) not in fixedclass: |
|
|
|
if api.GetPlaceType(i, j + 1) in available: |
|
|
|
GoTo(i, j + 1) |
|
|
|
return |
|
|
|
# global fixedclass |
|
|
|
# selfInfo = api.GetSelfInfo() |
|
|
|
# available = [THUAI6.PlaceType.Land, |
|
|
|
# THUAI6.PlaceType.Grass, THUAI6.PlaceType.Door3, THUAI6.PlaceType.Door6, THUAI6.PlaceType.Door5, THUAI6.PlaceType.Gate] |
|
|
|
|
|
|
|
# def bfs(x, y): |
|
|
|
# if api.GetPlaceType(x, y) not in available: |
|
|
|
# return [] |
|
|
|
|
|
|
|
# def GetSuccessors(x, y): |
|
|
|
# successors = [] |
|
|
|
# if x > 0 and api.GetPlaceType(x - 1, y) in available: |
|
|
|
# successors.append((x - 1, y)) |
|
|
|
# if x < 49 and api.GetPlaceType(x + 1, y) in available: |
|
|
|
# successors.append((x + 1, y)) |
|
|
|
# if y > 0 and api.GetPlaceType(x, y - 1) in available: |
|
|
|
# successors.append((x, y - 1)) |
|
|
|
# if y < 49 and api.GetPlaceType(x, y + 1) in available: |
|
|
|
# successors.append((x, y + 1)) |
|
|
|
# return successors |
|
|
|
# selfX = AssistFunction.GridToCell(api.GetSelfInfo().x) |
|
|
|
# selfY = AssistFunction.GridToCell(api.GetSelfInfo().y) |
|
|
|
# frontier = queue.Queue() |
|
|
|
# frontier.put((selfX, selfY, [])) |
|
|
|
# visited = [] |
|
|
|
# while not frontier.empty(): |
|
|
|
# currentX, currentY, path = frontier.get() |
|
|
|
# if currentX == x and currentY == y: |
|
|
|
# return path |
|
|
|
# for nextX, nextY in GetSuccessors(currentX, currentY): |
|
|
|
# if (nextX, nextY) not in visited: |
|
|
|
# visited.append((nextX, nextY)) |
|
|
|
# frontier.put((nextX, nextY, path + [(nextX, nextY)])) |
|
|
|
# return [] |
|
|
|
|
|
|
|
# def GoTo(x, y): |
|
|
|
# global path, cur |
|
|
|
# if path != [] and cur < len(path): |
|
|
|
# selfX = api.GetSelfInfo().x |
|
|
|
# selfY = api.GetSelfInfo().y |
|
|
|
# nextX, nextY = path[cur] |
|
|
|
# nextX = AssistFunction.CellToGrid(nextX) |
|
|
|
# nextY = AssistFunction.CellToGrid(nextY) |
|
|
|
# if selfX < nextX - 100: |
|
|
|
# api.MoveDown(10) |
|
|
|
# time.sleep(0.01) |
|
|
|
# return |
|
|
|
# if selfX > nextX + 100: |
|
|
|
# api.MoveUp(10) |
|
|
|
# time.sleep(0.01) |
|
|
|
# return |
|
|
|
# if selfY < nextY - 100: |
|
|
|
# api.MoveRight(10) |
|
|
|
# time.sleep(0.01) |
|
|
|
# return |
|
|
|
# if selfY > nextY + 100: |
|
|
|
# api.MoveLeft(10) |
|
|
|
# time.sleep(0.01) |
|
|
|
# return |
|
|
|
# cur += 1 |
|
|
|
# return |
|
|
|
# else: |
|
|
|
# path = bfs(x, y) |
|
|
|
# cur = 0 |
|
|
|
# return |
|
|
|
|
|
|
|
# if (AssistFunction.GridToCell(api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y)) == (6, 6) and api.GetGateProgress(5, 6) < 18000: |
|
|
|
# api.StartOpenGate() |
|
|
|
# return |
|
|
|
|
|
|
|
# if (AssistFunction.GridToCell(api.GetSelfInfo().x), AssistFunction.GridToCell(api.GetSelfInfo().y)) == (6, 6) and api.GetGateProgress(5, 6) >= 18000: |
|
|
|
# api.Graduate() |
|
|
|
# return |
|
|
|
|
|
|
|
# if len(fixedclass) == 7: |
|
|
|
# GoTo(6, 6) |
|
|
|
# return |
|
|
|
|
|
|
|
# if api.GetPlaceType(AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) == THUAI6.PlaceType.ClassRoom: |
|
|
|
# api.Print("Trying to fix!") |
|
|
|
# if api.GetClassroomProgress(AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) < 103000: |
|
|
|
# api.StartLearning() |
|
|
|
# return |
|
|
|
# else: |
|
|
|
# if (AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y)) not in fixedclass: |
|
|
|
# fixedclass.append( |
|
|
|
# (AssistFunction.GridToCell(api.GetSelfInfo().x) + 1, AssistFunction.GridToCell(api.GetSelfInfo().y))) |
|
|
|
|
|
|
|
# for i in range(50): |
|
|
|
# for j in range(50): |
|
|
|
# if api.GetPlaceType(i, j) == THUAI6.PlaceType.ClassRoom and (i, j) not in fixedclass: |
|
|
|
# if api.GetPlaceType(i - 1, j) in available: |
|
|
|
# GoTo(i - 1, j) |
|
|
|
# return |
|
|
|
api.PrintTricker() |
|
|
|
|
|
|
|
def TrickerPlay(self, api: ITrickerAPI) -> None: |
|
|
|
return |