diff --git a/doc/网络版.md b/doc/网络版.md new file mode 100644 index 0000000..589af7c --- /dev/null +++ b/doc/网络版.md @@ -0,0 +1,18 @@ +使用demo来标识是否为网络版(通过开始函数返回) + +增加Player类,成员有status_2,game_id, side,MAP(记录各个棋子的坐标-以id为索引,要保持双方的坐标一致),counterpart_name,think_time,total_time,用以记录双方的信息 + +定义了一个函数server_thread用来监听服务器发送的数据 + +在移动的时候,使用side与turn区分是哪一方移动(用demo区分单机与网络,单机版只以turn为条件(demo = 0),而网络版比较side与turn是否相同(demo = 1)) + +question:如何知道客户端接受到了一个报文(maybe:不断比较Player类中的坐标与本地MAP中坐标是否相同,不同则修改对面的棋子,并翻转turn 或 在Player中加入一个变量去记录,在客户端发送了报文(己方已经下好棋)后置0,然后不断询问是否为1,为1后停止,并修改对方的棋子坐标) + +该移动规则还需要修改path函数,以致可以得到正确的路径显示 + + + + + + + diff --git a/src/.idea/.gitignore b/src/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/src/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/src/.idea/.name b/src/.idea/.name new file mode 100644 index 0000000..11a5d8e --- /dev/null +++ b/src/.idea/.name @@ -0,0 +1 @@ +main.py \ No newline at end of file diff --git a/src/.idea/inspectionProfiles/profiles_settings.xml b/src/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/src/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/src/.idea/misc.xml b/src/.idea/misc.xml new file mode 100644 index 0000000..d56657a --- /dev/null +++ b/src/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/.idea/modules.xml b/src/.idea/modules.xml new file mode 100644 index 0000000..f669a0e --- /dev/null +++ b/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/.idea/src.iml b/src/.idea/src.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/src/.idea/src.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/.idea/vcs.xml b/src/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/src/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/DLS.py b/src/DLS.py new file mode 100644 index 0000000..e2ad0df --- /dev/null +++ b/src/DLS.py @@ -0,0 +1,251 @@ +import copy +from typing import List, Tuple +import pygame +import heapq +import socket_client as s +from main import right_move, left_move +import init + +inf = 99999999 +MAP1 = init.clac_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'] + copyMAP[x][y] = animalId + return copyMAP + + +class PriorityQueue: + + def __init__(self): + self.heap = [] + self.count = 0 + + def push(self, item, priority): + entry = (priority, self.count, item) + heapq.heappush(self.heap, entry) + self.count += 1 + + def pop(self): + (_, _, item) = heapq.heappop(self.heap) + return item + + def isEmpty(self): + return len(self.heap) == 0 + + def update(self, item, priority): + + for index, (p, c, i) in enumerate(self.heap): + if i == item: + if p <= priority: + break + del self.heap[index] + self.heap.append((priority, c, item)) + heapq.heapify(self.heap) + break + else: + self.push(item, priority) + + +def getMovement(Id, Animals): + MAP = getMAP(Animals) + Movements = [] + o_x, o_y = Animals[Id]['old_x'], Animals[Id]['old_y'] + for x in range(len(MAP)): + for y in range(len(MAP[0])): + if 1 <= Id <= 7: + if right_move(o_x, o_y, x, y, Id, MAP, MAP1): + move = (Id, x - o_x, y - o_y) + Movements.append(move) + else: + if left_move(o_x, o_y, x, y, Id, MAP, MAP1): + move = (Id, x - o_x, y - o_y) + Movements.append(move) + return Movements + + +def getSuccessors(Animals, turn: int): + Successors = [] + Actions = [] + if turn == 0: + # 1 ~ 7 + for Id in range(1, 8): + Move = getMovement(Id, Animals) + for oneStep in Move: + Actions.append(oneStep) + + else: + # 8 ~ 14 + for Id in range(8, 15): + Move = getMovement(Id, Animals) + for oneStep in Move: + Actions.append(oneStep) + + # update the map + for action in Actions: + Id, dx, dy = action[0], action[1], action[2] + t_Animals = copy.deepcopy(Animals) + x = Animals[Id]['old_x'] + dx + y = Animals[Id]['old_y'] + dy + t_Animals[Id]['x'] = x + t_Animals[Id]['y'] = y + target = (Id, x, y) + #print(t_Animals) + Successors.append((t_Animals, target)) + # updateMAP() + return Successors + + +class Information: + def __init__(self): + self.piece_score = {1: 100, 8: 100, + 2: 70, 9: 70, + 3: 60, 10: 60, + 4: 80, 11: 80, + 5: 90, 12: 90, + 6: 120, 13: 120, + 7: 120, 14: 120 + } + self.mouse_score = [[11, 25, 50, 100000, 50, 25, 13], + [11, 20, 25, 50, 25, 20, 13], + [10, 15, 20, 20, 20, 15, 13], + [8, 9, 9, 11, 12, 13, 13], + [8, 8, 8, 9, 11, 12, 12], + [8, 8, 8, 9, 11, 12, 11], + [8, 8, 8, 9, 10, 10, 10], + [8, 8, 8, 9, 9, 9, 9], + [8, 8, 8, 0, 8, 8, 8]] + + self.eagle_score = [[11, 15, 50, 100000, 50, 15, 11], + [12, 12, 20, 50, 20, 15, 12], + [14, 15, 20, 20, 20, 14, 14], + [13, 0, 0, 13, 0, 0, 13], + [12, 0, 0, 12, 0, 0, 12], + [11, 0, 0, 11, 0, 0, 11], + [10, 10, 10, 10, 10, 10, 10], + [8, 8, 8, 8, 8, 8, 8], + [8, 8, 8, 0, 8, 8, 8]] + + self.fox_score = [[11, 15, 50, 100000, 50, 15, 11], + [12, 12, 20, 50, 20, 15, 12], + [14, 15, 20, 20, 20, 14, 14], + [13, 0, 0, 13, 0, 0, 13], + [12, 0, 0, 12, 0, 0, 12], + [11, 0, 0, 11, 0, 0, 11], + [10, 10, 10, 11, 10, 10, 10], + [8, 8, 9, 10, 9, 8, 8], + [8, 8, 10, 0, 10, 8, 8]] + + self.wolf_score = [[11, 15, 50, 100000, 50, 15, 11], + [12, 12, 20, 50, 20, 15, 12], + [14, 15, 20, 20, 20, 14, 14], + [13, 0, 0, 13, 0, 0, 13], + [12, 0, 0, 12, 0, 0, 12], + [11, 0, 0, 11, 0, 0, 11], + [10, 10, 10, 11, 10, 10, 10], + [8, 8, 9, 10, 9, 8, 8], + [8, 8, 10, 0, 10, 8, 8]] + + self.leopard_score = [[11, 15, 50, 100000, 50, 15, 11], + [12, 12, 20, 50, 20, 15, 12], + [14, 15, 20, 20, 20, 14, 14], + [13, 0, 0, 13, 0, 0, 13], + [12, 0, 0, 12, 0, 0, 12], + [11, 0, 0, 11, 0, 0, 11], + [10, 10, 10, 11, 10, 10, 10], + [8, 8, 9, 10, 9, 8, 8], + [8, 8, 10, 0, 10, 8, 8]] + + self.lion_score = [[20, 40, 50, 100000, 50, 40, 20], + [20, 25, 40, 50, 40, 25, 20], + [18, 30, 30, 20, 30, 30, 18], + [15, 0, 0, 15, 0, 0, 15], + [12, 0, 0, 15, 0, 0, 12], + [11, 0, 0, 15, 0, 0, 11], + [14, 16, 16, 9, 16, 16, 14], + [12, 12, 12, 12, 12, 12, 12], + [5, 12, 12, 0, 12, 12, 5]] + + self.elephant_score = [[20, 40, 50, 100000, 50, 40, 20], + [20, 25, 40, 50, 40, 25, 20], + [18, 30, 30, 20, 30, 30, 18], + [15, 0, 0, 15, 0, 0, 15], + [12, 0, 0, 15, 0, 0, 12], + [11, 0, 0, 15, 0, 0, 11], + [14, 16, 16, 9, 16, 16, 14], + [12, 12, 12, 12, 12, 12, 12], + [5, 12, 12, 0, 12, 12, 5]] + + self.position_score = {1: self.mouse_score, + 8: self.mouse_score[::-1], + 2: self.eagle_score, + 9: self.eagle_score[::-1], + 3: self.fox_score, + 10: self.fox_score[::-1], + 4: self.wolf_score, + 11: self.wolf_score[::-1], + 5: self.leopard_score, + 12: self.leopard_score[::-1], + 6: self.lion_score, + 13: self.lion_score[::-1], + 7: self.elephant_score, + 14: self.elephant_score[::-1] + } + + +def Heuristic(Animals, pTurn): + score = 0 + information = Information() + piece_score = information.piece_score + for animalId in range(1, len(Animals)): + x,y = Animals[animalId]['x'], Animals[animalId]['y'] + + if 1 <= animalId <= 14: + animalIdValue = information.position_score[animalId][x][y] + if pTurn == 0: + if 1 <= animalId <= 7: + score += (animalIdValue + piece_score[animalId]) + else: + score -= (animalIdValue + piece_score[animalId]) + else: + if 1 <= animalId <= 7: + score -= (animalIdValue + piece_score[animalId]) + else: + score += (animalIdValue + piece_score[animalId]) + return score + + +def depthLimitedSearch2(curAnimals, turn): # depth = 2 + Successors = getSuccessors(curAnimals, turn) + tempNextMove = [(Successor, inf) for Successor in Successors] + nextMove = [] + if turn: + turn2 = 0 + else: + turn2 = 1 + for Move in tempNextMove: + Successors2 = getSuccessors(Move[0][0], turn2) + nextMove2 = [(Successor2, Heuristic(Successor2[0], turn2)) for Successor2 in Successors2] + max2 = -inf + for action2 in nextMove2: + if action2[1] > max2: + max2 = action2[1] + nextMove.append((Move, max2)) + min1 = inf + index = 0 + for i in range(len(nextMove)): + if nextMove[i][1] < min1: + min1 = nextMove[i][1] + index = i + return nextMove[index][0][0][1] +def main(): + axis = [(0, 0), (2, 6), (1, 1), (1, 5), (2, 2), (2, 4), (2, 3), (2, 0), (6, 0), (7, 5), (7, 1), (6, 4), (6, 2), + (6, 3), (6, 6)] + Axis = s.Chessmen_axis(axis) + Animals = Axis.axis + print(depthLimitedSearch2(Animals, 0)) + +if __name__ == '__main__': + main() diff --git a/src/__pycache__/Client_connection.cpython-39.pyc b/src/__pycache__/Client_connection.cpython-39.pyc new file mode 100644 index 0000000..82bbde3 Binary files /dev/null and b/src/__pycache__/Client_connection.cpython-39.pyc differ diff --git a/src/__pycache__/init.cpython-39.pyc b/src/__pycache__/init.cpython-39.pyc new file mode 100644 index 0000000..4636a92 Binary files /dev/null and b/src/__pycache__/init.cpython-39.pyc differ diff --git a/src/__pycache__/main.cpython-39.pyc b/src/__pycache__/main.cpython-39.pyc new file mode 100644 index 0000000..bcca857 Binary files /dev/null and b/src/__pycache__/main.cpython-39.pyc differ diff --git a/src/__pycache__/move.cpython-39.pyc b/src/__pycache__/move.cpython-39.pyc new file mode 100644 index 0000000..63f06da Binary files /dev/null and b/src/__pycache__/move.cpython-39.pyc differ diff --git a/src/__pycache__/socket_client.cpython-39.pyc b/src/__pycache__/socket_client.cpython-39.pyc new file mode 100644 index 0000000..22784d4 Binary files /dev/null and b/src/__pycache__/socket_client.cpython-39.pyc differ diff --git a/src/__pycache__/start_game.cpython-39.pyc b/src/__pycache__/start_game.cpython-39.pyc new file mode 100644 index 0000000..bd85082 Binary files /dev/null and b/src/__pycache__/start_game.cpython-39.pyc differ diff --git a/src/main.py b/src/main.py index fd4cc8c..27a090c 100644 --- a/src/main.py +++ b/src/main.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 @@ -1721,31 +1721,31 @@ def main(): 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: + 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)) Right_win = player.Right_win Left_win = player.Left_win @@ -2003,7 +2003,7 @@ def main(): turn = 0 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 or demo == 2) and player.id 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'] @@ -2011,6 +2011,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= 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) @@ -2020,6 +2021,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= 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) @@ -2028,6 +2030,7 @@ def main(): elif counterpart_id == 3 and turn == 0: if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= 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 @@ -2038,6 +2041,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= 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) @@ -2047,6 +2051,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= 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) @@ -2056,6 +2061,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= 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) @@ -2065,6 +2071,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= 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) @@ -2074,6 +2081,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= MAP[counterpart_x][counterpart_y] <= 14: 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) @@ -2083,6 +2091,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= MAP[counterpart_x][counterpart_y] <= 14: 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) @@ -2092,6 +2101,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= MAP[counterpart_x][counterpart_y] <= 14: 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) @@ -2101,6 +2111,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= MAP[counterpart_x][counterpart_y] <= 14: 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) @@ -2110,6 +2121,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= MAP[counterpart_x][counterpart_y] <= 14: 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) @@ -2119,6 +2131,7 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= MAP[counterpart_x][counterpart_y] <= 14: 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) @@ -2128,13 +2141,210 @@ def main(): if MAP[counterpart_x][counterpart_y] != counterpart_id: if 1 <= MAP[counterpart_x][counterpart_y] <= 14: 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: - pass + elif demo == 2 and player.id and turn == player.id: + id,x,y = DLS.depthLimitedSearch2(Axis.axis,player.id)#TODO:AI algorithm + 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) 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/path/__pycache__/path.cpython-39.pyc b/src/path/__pycache__/path.cpython-39.pyc new file mode 100644 index 0000000..257dd19 Binary files /dev/null and b/src/path/__pycache__/path.cpython-39.pyc differ diff --git a/src/socket_client.py b/src/socket_client.py index 3610aad..2304b70 100644 --- a/src/socket_client.py +++ b/src/socket_client.py @@ -22,6 +22,8 @@ class Chessmen_axis: old_x, old_y = Axis[i] self.axis[i]["old_x"] = old_x self.axis[i]["old_y"] = old_y + self.axis[i]["x"] = old_x + self.axis[i]["y"] = old_y def set_axix(self, id, old_x, old_y, x, y): self.axis[id]["old_x"] = old_x