From e9e8bf0402052861c0fdb1a8a0e009fe1905eaa3 Mon Sep 17 00:00:00 2001 From: huangjielun <2872405629@qq.com> Date: Sun, 9 Oct 2022 10:31:50 +0800 Subject: [PATCH] =?UTF-8?q?AI=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DLS.py | 2 +- src/main.py | 497 ++++++++++++++++++++++++++++++++----------------- src/main_an.py | 486 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 742 insertions(+), 243 deletions(-) diff --git a/src/DLS.py b/src/DLS.py index 406ac7c..4bfccca 100644 --- a/src/DLS.py +++ b/src/DLS.py @@ -571,7 +571,7 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): def getMAP(Animals): copyMAP = [[0 for i in range(7)] for j in range(9)] for animalId in range(1, len(Animals)): - x, y = Animals[animalId]['old_x'], Animals[animalId]['old_y'] + x, y = Animals[animalId]['x'], Animals[animalId]['y'] copyMAP[x][y] = animalId return copyMAP diff --git a/src/main.py b/src/main.py index 7d4faa6..6a7cd5d 100644 --- a/src/main.py +++ b/src/main.py @@ -1618,6 +1618,8 @@ def server_thread(conn,addr) : status_2,game_id,side,old_x,old_y,x,y, num = C.handle_move(msg) id = num + 1 id = (id+7) % 14 + if id == 0: + id = 14 player.game_id = game_id player.status_2 = status_2 Axis.axis[id]['old_x'] = old_x @@ -1737,6 +1739,7 @@ def main(): C.conn_to_server(client, name) while run: clock.tick(FPS) + #print(turn,player.side) if (demo == 1 or demo == 2) and exit == 1: request = "quit" C.exit_game(client,request,player.game_id,1 - player.side) @@ -1750,7 +1753,6 @@ def main(): run = False if demo == 1 or demo == 2: C.start_new_thread(server_thread, (client,Address)) - print(turn,player.side) Right_win = player.Right_win Left_win = player.Left_win for event in pygame.event.get(): @@ -2007,8 +2009,7 @@ def main(): turn = 1 - turn else : status = 0 - elif (demo == 1 or demo == 2) and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1: - print("in") + elif (demo == 1) and turn != player.side and player.invalid == 1 and player.status_2 == -1: counterpart_id = player.id counterpart_old_x , counterpart_old_y = Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y'] counterpart_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y'] @@ -2152,206 +2153,352 @@ def main(): r_elephant.x , r_elephant.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif demo == 2 and player.side and turn == player.side: - id,x,y = DLS.depthLimitedSearch2(Axis.axis,player.side)#TODO:AI algorithm - print(id,x,y) - if id == 1: - if 8 <= MAP[x][y] <= 14: - ID[MAP[x][y]] = 0 + if (demo == 2) and turn != player.side and player.invalid == 1 and player.status_2 == -1: + #print("in") + counterpart_id = player.id + counterpart_old_x, counterpart_old_y = Axis.axis[counterpart_id]['old_x'], Axis.axis[counterpart_id]['old_y'] + counterpart_x, counterpart_y = Axis.axis[counterpart_id]['x'], Axis.axis[counterpart_id]['y'] + print(counterpart_id) + if counterpart_id == 1: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - l_mouse.x, l_mouse.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_mouse.x, l_mouse.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id ==2: - if 8 <= MAP[x][y] <= 14: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 2: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - l_eagle.x, l_eagle.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_eagle.x, l_eagle.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id ==3: - if 8 <= MAP[x][y] <= 14: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 3: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: r_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - l_fox.x, l_fox.y = init.tran(x, y) + ID[MAP[counterpart_x][counterpart_y]] = 0 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_fox.x, l_fox.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id ==4: - if 8 <= MAP[x][y] <= 14: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 4: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - l_wolf.x, l_wolf.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_wolf.x, l_wolf.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id ==5: - if 8 <= MAP[x][y] <= 14: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 5: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - l_leopard.x, l_leopard.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_leopard.x, l_leopard.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id ==6: - if 8 <= MAP[x][y] <= 14: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 6: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - l_lion.x, l_lion.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_lion.x, l_lion.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id ==7: - if 8 <= MAP[x][y] <= 14: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 7: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - l_elephant.x, l_elephant.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_elephant.x, l_elephant.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id == 8: - if 1 <= MAP[x][y] <= 7: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 8: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - r_mouse.x, r_mouse.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_mouse.x, r_mouse.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id == 9: - if 1 <= MAP[x][y] <= 7: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 9: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - r_eagle.x, r_eagle.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_eagle.x, r_eagle.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id == 10: - if 1 <= MAP[x][y] <= 7: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 10: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - r_fox.x, r_fox.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_fox.x, r_fox.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id == 11: - if 1 <= MAP[x][y] <= 7: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 11: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - r_wolf.x, r_wolf.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_wolf.x, r_wolf.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id == 12: - if 1 <= MAP[x][y] <= 7: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 12: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - r_leopard.x, r_leopard.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_leopard.x, r_leopard.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id == 13: - if 1 <= MAP[x][y] <= 7: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 13: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - r_lion.x, r_lion.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_lion.x, r_lion.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - elif id == 14: - if 1 <= MAP[x][y] <= 7: - ID[MAP[x][y]] = 0 + player.invalid = 0 + elif counterpart_id == 14: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 - MAP[x][y] = id - old_x = Axis.axis[id]["x"] - old_y = Axis.axis[id]["y"] - MAP[old_x][old_y] = MAP1[old_x][old_y] - Axis.axis[id]["old_x"] = old_x - Axis.axis[id]["old_y"] = old_y - Axis.axis[id]["x"] = x - Axis.axis[id]["y"] = y - r_elephant.x, r_elephant.y = init.tran(x, y) + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_elephant.x, r_elephant.y = init.tran(counterpart_x, counterpart_y) turn = (1 - turn) - C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, y) + player.invalid = 0 + elif demo == 2 and turn == player.side: + id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side) # TODO:AI algorithm + #print((id,x,y)) + if id == 1: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_mouse.x, l_mouse.y = init.tran(x, y) + turn = (1 - turn) + elif id == 2: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_eagle.x, l_eagle.y = init.tran(x, y) + turn = (1 - turn) + elif id == 3: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_fox.x, l_fox.y = init.tran(x, y) + turn = (1 - turn) + elif id == 4: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_wolf.x, l_wolf.y = init.tran(x, y) + turn = (1 - turn) + elif id == 5: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_leopard.x, l_leopard.y = init.tran(x, y) + turn = (1 - turn) + elif id == 6: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_lion.x, l_lion.y = init.tran(x, y) + turn = (1 - turn) + elif id == 7: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_elephant.x, l_elephant.y = init.tran(x, y) + turn = (1 - turn) + elif id == 8: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_mouse.x, r_mouse.y = init.tran(x, y) + turn = (1 - turn) + elif id == 9: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_eagle.x, r_eagle.y = init.tran(x, y) + turn = (1 - turn) + elif id == 10: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_fox.x, r_fox.y = init.tran(x, y) + turn = (1 - turn) + elif id == 11: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_wolf.x, r_wolf.y = init.tran(x, y) + turn = (1 - turn) + elif id == 12: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_leopard.x, r_leopard.y = init.tran(x, y) + turn = (1 - turn) + elif id == 13: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_lion.x, r_lion.y = init.tran(x, y) + turn = (1 - turn) + elif id == 14: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_elephant.x, r_elephant.y = init.tran(x, y) + turn = (1 - turn) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, y) draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, diff --git a/src/main_an.py b/src/main_an.py index 6d4facf..6a7cd5d 100644 --- a/src/main_an.py +++ b/src/main_an.py @@ -11,7 +11,7 @@ import uuid import time from threading import Thread, Lock import socket_client as s -import pygame_menu +import DLS if(sys.version[:1] == "3"): import queue as Queue @@ -26,7 +26,7 @@ WIDTH , HEIGHT = 1200 , 800 ID = [1 for i in range(20)] FPS = 60 WIN = pygame.display.set_mode((WIDTH,HEIGHT)) -pygame.display.set_caption("Jungle") +#pygame.display.set_caption("Jungle") SPACE = pygame.transform.scale(pygame.image.load('images/map.png'),(WIDTH,HEIGHT)) CHESSSIZE_X=120 CHESSSIZE_Y=100 #棋子大小 @@ -130,6 +130,7 @@ def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) def draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox,id, x, y, status, MAP, MAP1,turn): + pygame.display.set_caption("Jungle") WIN.blit(SPACE,(0,0)) if turn == 1: WIN.blit(left_turn,init.tran(8,3)) @@ -1617,6 +1618,8 @@ def server_thread(conn,addr) : status_2,game_id,side,old_x,old_y,x,y, num = C.handle_move(msg) id = num + 1 id = (id+7) % 14 + if id == 0: + id = 14 player.game_id = game_id player.status_2 = status_2 Axis.axis[id]['old_x'] = old_x @@ -1672,18 +1675,6 @@ def server_thread(conn,addr) : except: return -def time_ShowAndCheck(player: player): - time.sleep(1) - clock = str(player.think_time) + '秒' - largeText = pygame.font.SysFont('comicsansms', 25) - TextSurf, TextRect = text_objects(clock, largeText) - if player.side == 1: - TextRect = init.tran(0,3) - else: - TextRect = init.tran(8,3) - gameDisplay.blit(TextSurf, TextRect) - pygame.display.update() - mutex_playing = Lock() def time_thread(): @@ -1696,7 +1687,6 @@ def time_thread(): break else: player.think_time -= 1 - time_ShowAndCheck(player) player.total_time -= 1 if is_over_time: return False @@ -1704,7 +1694,7 @@ def time_thread(): return True class Config: - SOCKET_HOST = '192.168.43.201'#Symbolic name meaning all available interfaces + SOCKET_HOST = '127.0.0.1'#Symbolic name meaning all available interfaces SOCKET_PORT = 50005#Arbitrary non-privileged port MAX_WAITING_TIME = 180 MAX_THNIKING_TIME = 60 @@ -1729,38 +1719,40 @@ def main(): demo = 0 elif game_status == 2: demo = 1 + elif game_status == 3: + demo = 2 run = True clock = pygame.time.Clock() font = pygame.font.SysFont('kaiti',40) status = id = old_x = old_y = x = y = 0 turn = 1 - if demo == 1: + if (demo == 1 or demo == 2): name = input("Please tell us your name:") player.name = name Left_win = player.Left_win Right_win = player.Right_win Address = (Config.SOCKET_HOST, Config.SOCKET_PORT) - if demo == 1: + if (demo == 1 or demo == 2): C.load_config() client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect((Config.SOCKET_HOST, Config.SOCKET_PORT)) C.conn_to_server(client, name) while run: clock.tick(FPS) - if demo == 1 and exit == 1: + #print(turn,player.side) + if (demo == 1 or demo == 2) and exit == 1: request = "quit" C.exit_game(client,request,player.game_id,1 - player.side) if player.side == 0: player.Right_win = Right_win = 1 elif player.side == 1: player.Left_win = Left_win = 1 - if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1): + if left_win(x, y, MAP, MAP1) or ((demo == 1 or demo == 2) and Left_win == 1): run = False - if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1): + if right_win(x, y, MAP, MAP1) or ((demo == 1 or demo == 2) and Right_win == 1): run = False - if demo == 1: + if demo == 1 or demo == 2: C.start_new_thread(server_thread, (client,Address)) - C.server_thread(time_thread,()) Right_win = player.Right_win Left_win = player.Left_win for event in pygame.event.get(): @@ -1832,7 +1824,7 @@ def main(): status = 0 if(demo == 1): C.move(client,player.game_id,1 - player.side,(id+7) % 14,old_x,old_y,x,y) - turn = 1 + turn = 1 - turn else: status = 0 elif (id == 2 and turn == 0 and status == 1 and demo == 0) or (id == 2 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1846,7 +1838,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 3 and turn == 0 and status == 1 and demo == 0) or (id == 3 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1860,7 +1852,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 4 and turn == 0 and status == 1 and demo == 0) or (id == 4 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1874,7 +1866,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 5 and turn == 0 and status == 1 and demo == 0) or (id == 5 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1888,7 +1880,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 6 and turn == 0 and status == 1 and demo == 0) or (id == 6 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1902,7 +1894,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 7 and turn == 0 and status == 1 and demo == 0) or (id == 7 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1916,7 +1908,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 8 and turn == 1 and status == 2 and demo == 0) or (id == 8 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1930,7 +1922,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 9 and turn == 1 and status == 2 and demo == 0) or (id == 9 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1944,7 +1936,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 10 and turn == 1 and status == 2 and demo == 0) or (id == 10 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1958,7 +1950,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 11 and turn == 1 and status == 2 and demo == 0) or (id == 11 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1972,7 +1964,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 12 and turn == 1 and status == 2 and demo == 0) or (id == 12 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1986,7 +1978,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 13 and turn == 1 and status == 2 and demo == 0) or (id == 13 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -2000,7 +1992,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 14 and turn == 1 and status == 2 and demo == 0) or (id == 14 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -2014,140 +2006,500 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 - elif demo == 1 and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1: + elif (demo == 1) and turn != player.side and player.invalid == 1 and player.status_2 == -1: counterpart_id = player.id - print(turn,counterpart_id) counterpart_old_x , counterpart_old_y = Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y'] counterpart_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y'] - if counterpart_id == 1 and turn == 0: + if counterpart_id == 1 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id l_mouse.x , l_mouse.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 2 and turn == 0: + elif counterpart_id == 2 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id l_eagle.x , l_eagle.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 3 and turn == 0: + elif counterpart_id == 3 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + r_animals -= 1 ID[MAP[counterpart_x][counterpart_y]] = 0 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id l_fox.x , l_fox.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 4 and turn == 0: + elif counterpart_id == 4 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id l_wolf.x , l_wolf.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 5 and turn == 0: + elif counterpart_id == 5 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id l_leopard.x , l_leopard.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 6 and turn == 0: + elif counterpart_id == 6 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id l_lion.x , l_lion.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 7 and turn == 0: + elif counterpart_id == 7 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id l_elephant.x , l_elephant.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 8 and turn == 1: + elif counterpart_id == 8 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id r_mouse.x , r_mouse.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 9 and turn == 1: + elif counterpart_id == 9 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id r_eagle.x , r_eagle.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 10 and turn == 1: + elif counterpart_id == 10 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id r_fox.x , r_fox.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 11 and turn == 1: + elif counterpart_id == 11 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id r_wolf.x , r_wolf.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 12 and turn == 1: + elif counterpart_id == 12 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id r_leopard.x , r_leopard.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 13 and turn == 1: + elif counterpart_id == 13 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id r_lion.x , r_lion.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 14 and turn == 1: + elif counterpart_id == 14 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_x][counterpart_y] = counterpart_id r_elephant.x , r_elephant.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 + if (demo == 2) and turn != player.side and player.invalid == 1 and player.status_2 == -1: + #print("in") + counterpart_id = player.id + counterpart_old_x, counterpart_old_y = Axis.axis[counterpart_id]['old_x'], Axis.axis[counterpart_id]['old_y'] + counterpart_x, counterpart_y = Axis.axis[counterpart_id]['x'], Axis.axis[counterpart_id]['y'] + print(counterpart_id) + if counterpart_id == 1: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_mouse.x, l_mouse.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 2: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_eagle.x, l_eagle.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 3: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + r_animals -= 1 + ID[MAP[counterpart_x][counterpart_y]] = 0 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_fox.x, l_fox.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 4: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_wolf.x, l_wolf.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 5: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_leopard.x, l_leopard.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 6: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_lion.x, l_lion.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 7: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: + ID[MAP[counterpart_x][counterpart_y]] = 0 + r_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + l_elephant.x, l_elephant.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 8: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_mouse.x, r_mouse.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 9: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_eagle.x, r_eagle.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 10: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_fox.x, r_fox.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 11: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_wolf.x, r_wolf.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 12: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_leopard.x, r_leopard.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 13: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_lion.x, r_lion.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif counterpart_id == 14: + if MAP[counterpart_x][counterpart_y] != counterpart_id: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: + ID[MAP[counterpart_x][counterpart_y]] = 0 + l_animals -= 1 + MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] + MAP[counterpart_x][counterpart_y] = counterpart_id + r_elephant.x, r_elephant.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) + player.invalid = 0 + elif demo == 2 and turn == player.side: + id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side) # TODO:AI algorithm + #print((id,x,y)) + if id == 1: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_mouse.x, l_mouse.y = init.tran(x, y) + turn = (1 - turn) + elif id == 2: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_eagle.x, l_eagle.y = init.tran(x, y) + turn = (1 - turn) + elif id == 3: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_fox.x, l_fox.y = init.tran(x, y) + turn = (1 - turn) + elif id == 4: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_wolf.x, l_wolf.y = init.tran(x, y) + turn = (1 - turn) + elif id == 5: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_leopard.x, l_leopard.y = init.tran(x, y) + turn = (1 - turn) + elif id == 6: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_lion.x, l_lion.y = init.tran(x, y) + turn = (1 - turn) + elif id == 7: + if 8 <= MAP[x][y] <= 14: + ID[MAP[x][y]] = 0 + r_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + l_elephant.x, l_elephant.y = init.tran(x, y) + turn = (1 - turn) + elif id == 8: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_mouse.x, r_mouse.y = init.tran(x, y) + turn = (1 - turn) + elif id == 9: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_eagle.x, r_eagle.y = init.tran(x, y) + turn = (1 - turn) + elif id == 10: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_fox.x, r_fox.y = init.tran(x, y) + turn = (1 - turn) + elif id == 11: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_wolf.x, r_wolf.y = init.tran(x, y) + turn = (1 - turn) + elif id == 12: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_leopard.x, r_leopard.y = init.tran(x, y) + turn = (1 - turn) + elif id == 13: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_lion.x, r_lion.y = init.tran(x, y) + turn = (1 - turn) + elif id == 14: + if 1 <= MAP[x][y] <= 7: + ID[MAP[x][y]] = 0 + l_animals -= 1 + MAP[x][y] = id + old_x = Axis.axis[id]["x"] + old_y = Axis.axis[id]["y"] + MAP[old_x][old_y] = MAP1[old_x][old_y] + Axis.axis[id]["old_x"] = old_x + Axis.axis[id]["old_y"] = old_y + Axis.axis[id]["x"] = x + Axis.axis[id]["y"] = y + r_elephant.x, r_elephant.y = init.tran(x, y) + turn = (1 - turn) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, y) + draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_mouse, r_fox, id, x, y, status, MAP, MAP1, turn)