From 9efeb3be10d34e19729696117588065f1d3b8a62 Mon Sep 17 00:00:00 2001 From: huangjielun <2872405629@qq.com> Date: Thu, 27 Oct 2022 16:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DLS.py | 111 ++++- src/main.py | 34 +- src/main_an.py | 1078 ++++++++++++++++++++++++++++-------------------- 3 files changed, 735 insertions(+), 488 deletions(-) diff --git a/src/DLS.py b/src/DLS.py index e0f5dc0..a39b9a0 100644 --- a/src/DLS.py +++ b/src/DLS.py @@ -200,12 +200,16 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1): if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: + #print("laoshu") return 1 else: return 0 + #print("other animals") return 1 if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + #print("xianjing") return 1 + #print("grass") return 1 elif old_x == x and abs(y - old_y) == 1 and ( MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( @@ -213,12 +217,16 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1): if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: + #print("laoshu2") return 1 else: return 0 + #print("other aniamls 2") return 1 if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + #print("xianjing2") return 1 + #print("grass2") return 1 elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): @@ -229,26 +237,34 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1): if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: + #print("laoshu3") return 1 else: return 0 + #print("other animals 3") return 1 if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + #print("xianjing3") return 1 + #print("grass 3") return 1 else: for i in range(y + 1, old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1: + if MAP[x][i] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: + #print("laoshu4") return 1 else: return 0 + #print("other animals 4") return 1 if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + #print("xianjing4") return 1 + #print("grass 4") return 1 elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): @@ -259,26 +275,36 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1): if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: + #print("laoshu5") return 1 else: return 0 + #print("other animals 5") return 1 if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + #print("xianjing5") return 1 + #print("grass 5") return 1 else: for i in range(x + 1, old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1: + if MAP[i][y] != 20 : + #if x == 1 and y == 6: + #print("why?") return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: + #print("laoshu6") return 1 else: return 0 + #print("other animals 6") return 1 if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + #print("xianjing6") return 1 + #print("grass 6") return 1 else: return 0 @@ -716,9 +742,13 @@ def getMovement(Id, Animals, ID): move = (Id, x, y) Movements.append(move) elif 8 <= Id <= 14: + if Id == 13 and o_x == 3 and o_y == 6: + print("---------------") if left_move(o_x, o_y, x, y, Id, MAP, MAP1): move = (Id, x, y) Movements.append(move) + if Id == 13 and o_x == 3 and o_y == 6: + print("---------------") return Movements @@ -936,7 +966,7 @@ def findWayToDes(Animals, id, Des, ID): y = ways[index][2] cal_dis = abs(x - d_x) + abs(y - d_y) if cal_dis < distance: - print(cal_dis) + #print(cal_dis) distance = cal_dis target_i = index return ways[target_i] @@ -986,21 +1016,28 @@ def defendHome(Animals, ID, turn): AnimalsPos = getAnimalsPos(Animals, ID) # set the position and eat the trapped if turn == 0: + for id in range(1,8): + for i in range(0,9): + for j in range(0,7): + if ID[id] and right_move(AnimalsPos[id][0],AnimalsPos[id][1],i,j,id,MAP,MAP1) : + if 8<=MAP[i][j]<=14: + des = (id,i,j) + return findWayToDes(Animals, id, des, ID) # eat the trap enemyID = [8, 9, 10, 11, 12, 13, 14] if MAP[0][2] in enemyID: - if AnimalsPos[5]: + if AnimalsPos[5] != (-1,-1): des = (5, 0, 2) return findWayToDes(Animals, 5, des, ID) if MAP[1][3] in enemyID: - if AnimalsPos[4]: + if AnimalsPos[4] != (-1,-1): des = (4, 1, 3) return findWayToDes(Animals, 4, des, ID) - elif AnimalsPos[3]: + elif AnimalsPos[3] != (-1,-1): des = (3, 1, 3) return findWayToDes(Animals, 3, des, ID) if MAP[0][4] in enemyID: - if AnimalsPos[5]: + if AnimalsPos[5] != (-1,-1): des = (5, 0, 4) return findWayToDes(Animals, 5, des, ID) if MAP[0][5] in enemyID: @@ -1022,20 +1059,27 @@ def defendHome(Animals, ID, turn): if turn == 1: # eat the trapped + for id in range(8,15): + for i in range(0,9): + for j in range(0,7): + if ID[id] and left_move(AnimalsPos[id][0],AnimalsPos[id][1],i,j,id,MAP,MAP1): + if 1<=MAP[i][j]<=7: + des = (id,i,j) + return findWayToDes(Animals, id, des, ID) enemyID = [1, 2, 3, 4, 5, 6, 7] if MAP[8][4] in enemyID: - if AnimalsPos[12]: + if AnimalsPos[12] != (-1,-1): des = (12, 8, 4) return findWayToDes(Animals, 12, des, ID) if MAP[7][3] in enemyID: - if AnimalsPos[11]: + if AnimalsPos[11] != (-1,-1): des = (11, 7, 3) return findWayToDes(Animals, 11, des, ID) - elif AnimalsPos[10]: + elif AnimalsPos[10] != (-1,-1): des = (12, 7, 3) return findWayToDes(Animals, 12, des, ID) if MAP[8][2] in enemyID: - if AnimalsPos[12]: + if AnimalsPos[12] != (-1,-1): des = (11, 8, 2) return findWayToDes(Animals, 12, des, ID) if MAP[8][1] in enemyID: @@ -1059,10 +1103,17 @@ def defendHome(Animals, ID, turn): def lionAttack(Animals, ID, turn): AnimalsPos = getAnimalsPos(Animals, ID) + MAP = getMAP(Animals, ID) if turn == 0: if ID[6]: - print('in') + #print('in') print('AnimalsPos:', AnimalsPos[6]) + for i in range(0,9): + for j in range(0,7): + if right_move(AnimalsPos[6][0],AnimalsPos[6][1],i,j,6,MAP,MAP1): + if 8<=MAP[i][j]<=14: + des = (6,i,j) + return findWayToDes(Animals, 6, des, ID) if AnimalsPos[6][0] == 8: des = (6, 8, 3) return findWayToDes(Animals, 6, des, ID) @@ -1078,10 +1129,15 @@ def lionAttack(Animals, ID, turn): des = (6, 3, 3) return findWayToDes(Animals, 6, des, ID) else: - return None else: if ID[13]: + for i in range(0,9): + for j in range(0,7): + if left_move(AnimalsPos[13][0],AnimalsPos[13][1],i,j,13,MAP,MAP1): + if 1<=MAP[i][j]<=7: + des = (6,i,j) + return findWayToDes(Animals, 13, des, ID) if AnimalsPos[13][0] == 0: des = (13, 0, 3) return findWayToDes(Animals, 13, des, ID) @@ -1103,8 +1159,15 @@ def lionAttack(Animals, ID, turn): def elephantAttack(Animals, ID, turn): AnimalsPos = getAnimalsPos(Animals, ID) + MAP = getMAP(Animals, ID) if turn == 0: if ID[7]: + for i in range(0,9): + for j in range(0,7): + if right_move(AnimalsPos[7][0],AnimalsPos[7][1],i,j,7,MAP,MAP1): + if 8<=MAP[i][j]<=14: + des = (7,i,j) + return findWayToDes(Animals, 7, des, ID) if AnimalsPos[7][1] == 3: des = (7, 8, 3) return findWayToDes(Animals, 7, des, ID) @@ -1116,6 +1179,12 @@ def elephantAttack(Animals, ID, turn): return None else: if ID[14]: + for i in range(0,9): + for j in range(0,7): + if right_move(AnimalsPos[14][0],AnimalsPos[14][1],i,j,14,MAP,MAP1): + if 1<=MAP[i][j]<=7: + des = (14,i,j) + return findWayToDes(Animals, 14, des, ID) if AnimalsPos[14][1] == 3: des = (14, 0, 3) return findWayToDes(Animals, 14, des, ID) @@ -1128,12 +1197,26 @@ def elephantAttack(Animals, ID, turn): def eagleToHome(Animals, ID, turn): + AnimalsPos = getAnimalsPos(Animals, ID) + MAP = getMAP(Animals, ID) if turn == 0: if ID[2]: + for i in range(0,9): + for j in range(0,7): + if right_move(AnimalsPos[2][0],AnimalsPos[2][1],i,j,2,MAP,MAP1): + if 8<=MAP[i][j]<=14: + des = (2,i,j) + return findWayToDes(Animals, 2, des, ID) des = [2, 8, 3] return findWayToDes(Animals, 2, des, ID) else: if ID[9]: + for i in range(0,9): + for j in range(0,7): + if left_move(AnimalsPos[9][0],AnimalsPos[9][1],i,j,9,MAP,MAP1): + if 1<=MAP[i][j]<=7: + des = (9,i,j) + return findWayToDes(Animals, 9, des, ID) des = [9, 0, 3] return findWayToDes(Animals, 9, des, ID) return None @@ -1163,7 +1246,7 @@ def main(): Axis = s.Chessmen_axis(axis) Animals = Axis.axis ID = [1 for i in range(20)] - print(depthLimitedSearch2(Animals, 0, ID)) + #print(depthLimitedSearch2(Animals, 0, ID)) x, y, z = depthLimitedSearch2(Animals, 0, ID) diff --git a/src/main.py b/src/main.py index 128dfbb..0b6134d 100644 --- a/src/main.py +++ b/src/main.py @@ -883,7 +883,7 @@ def ismove(old_x, old_y, x, y, id, MAP, MAP1): MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if y > old_y: for i in range(old_y + 1, y): - if MAP[x][i] != 20 and MAP[x][i] != 8: + if MAP[x][i] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -903,7 +903,7 @@ def ismove(old_x, old_y, x, y, id, MAP, MAP1): return 1 else: for i in range(y + 1, old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1: + if MAP[x][i] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -925,7 +925,7 @@ def ismove(old_x, old_y, x, y, id, MAP, MAP1): MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if x > old_x: for i in range(old_x + 1, x): - if MAP[i][y] != 20 and MAP[i][y] != 1: + if MAP[i][y] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -945,7 +945,7 @@ def ismove(old_x, old_y, x, y, id, MAP, MAP1): return 1 else: for i in range(x + 1, old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1: + if MAP[i][y] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1259,7 +1259,7 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1): MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if y > old_y: for i in range(old_y + 1, y): - if MAP[x][i] != 20 and MAP[x][i] != 8: + if MAP[x][i] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1273,7 +1273,7 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1): return 1 else: for i in range(y + 1, old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1: + if MAP[x][i] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1289,7 +1289,7 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1): MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if x > old_x: for i in range(old_x + 1, x): - if MAP[i][y] != 20 and MAP[i][y] != 1: + if MAP[i][y] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1303,7 +1303,7 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1): return 1 else: for i in range(x + 1, old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1: + if MAP[i][y] != 20 : return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1608,7 +1608,7 @@ def right_move(old_x, old_y, x, y, id, MAP, MAP1): MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if y > old_y: for i in range(old_y + 1, y): - if MAP[x][i] != 20 and MAP[x][i] != 1: + if MAP[x][i] != 20 : return 0 if 8 <= MAP[x][y] <= 14: if MAP[x][y] == 8: @@ -1622,7 +1622,7 @@ def right_move(old_x, old_y, x, y, id, MAP, MAP1): return 1 else: for i in range(y + 1, old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1: + if MAP[x][i] != 20 : return 0 if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: @@ -1638,7 +1638,7 @@ def right_move(old_x, old_y, x, y, id, MAP, MAP1): MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if x > old_x: for i in range(old_x + 1, x): - if MAP[i][y] != 20 and MAP[i][y] != 1: + if MAP[i][y] != 20 : return 0 if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: @@ -1652,7 +1652,7 @@ def right_move(old_x, old_y, x, y, id, MAP, MAP1): return 1 else: for i in range(x + 1, old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1: + if MAP[i][y] != 20 : return 0 if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: @@ -1747,7 +1747,7 @@ def server_thread(conn, addr): id = num + 1 if side == 0: id = id + 7 - print("turn,id:",side , id) + #print("turn,id:",side , id) player.game_id = game_id player.status_2 = status_2 Axis.axis[id]['old_x'] = old_x @@ -1825,7 +1825,7 @@ def time_thread(): class Config: - SOCKET_HOST = '192.168.43.108' # Symbolic name meaning all available interfaces + SOCKET_HOST = '192.168.43.170' # Symbolic name meaning all available interfaces SOCKET_PORT = 50005 # Arbitrary non-privileged port MAX_WAITING_TIME = 180 MAX_THNIKING_TIME = 60 @@ -2321,7 +2321,7 @@ def main(): 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) + #print(counterpart_id) if counterpart_id == 1: if MAP[counterpart_x][counterpart_y] != counterpart_id: if 8 <= MAP[counterpart_x][counterpart_y] <= 14: @@ -2464,7 +2464,7 @@ def main(): player.invalid = 0 elif demo == 2 and turn == player.side: id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side, ID) # TODO:AI algorithm - print((id,x,y)) + #print((id,x,y)) if id == 1: if 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 @@ -2694,7 +2694,7 @@ def main(): pygame.display.update() if (player.status_2 == 2 or player.status_2 == 3) and demo == 1: C.ack_exit_game(client, 1 - player.side) - + print(ID) time.sleep(10) # os.system("pause") return start_game.starting_screen() diff --git a/src/main_an.py b/src/main_an.py index 8997f61..4388444 100644 --- a/src/main_an.py +++ b/src/main_an.py @@ -13,23 +13,22 @@ from threading import Thread, Lock import socket_client as s import DLS -if(sys.version[:1] == "3"): +if (sys.version[:1] == "3"): import queue as Queue from _thread import * else: import Queue from _thread import * -WIDTH , HEIGHT = 1200 , 800 +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") -SPACE = pygame.transform.scale(pygame.image.load('images/map.png'),(WIDTH,HEIGHT)) -CHESSSIZE_X=120 -CHESSSIZE_Y=100 #棋子大小 +WIN = pygame.display.set_mode((WIDTH, HEIGHT)) +# pygame.display.set_caption("Jungle") +SPACE = pygame.transform.scale(pygame.image.load('images/map.png'), (WIDTH, HEIGHT)) +CHESSSIZE_X = 120 +CHESSSIZE_Y = 100 # 棋子大小 ################################################################## ###########背景音乐########### @@ -44,61 +43,68 @@ Fox = pygame.mixer.Sound('audio/Fox.mp3') Eagle = pygame.mixer.Sound('audio/Eagle.mp3') pygame.mixer.music.set_volume(0.5) #################################################### -#mark -hint = pygame.transform.scale(pygame.image.load("images/hint.png"),(CHESSSIZE_X,CHESSSIZE_Y)) -capture_hint = pygame.transform.scale(pygame.image.load("images/capture-hint.png"),(CHESSSIZE_X,CHESSSIZE_Y)) -left_turn = pygame.transform.scale(pygame.image.load("images/left_turn.png"),(CHESSSIZE_X,CHESSSIZE_Y)) -right_turn = pygame.transform.scale(pygame.image.load("images/right_turn.png"),(CHESSSIZE_X,CHESSSIZE_Y)) -#animals img -#Left -L_mouse = pygame.transform.scale(pygame.image.load('images/animals/left/1MouseLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -L_eagle = pygame.transform.scale(pygame.image.load('images/animals/left/2EagleLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -L_wolf = pygame.transform.scale(pygame.image.load('images/animals/left/3WolfLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -L_leopard = pygame.transform.scale(pygame.image.load('images/animals/left/4LeopardLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -L_tiger = pygame.transform.scale(pygame.image.load('images/animals/left/5TigerLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -L_lion = pygame.transform.scale(pygame.image.load('images/animals/left/6LionLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -L_elephant = pygame.transform.scale(pygame.image.load('images/animals/left/7ElephantLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -L_fox = pygame.transform.scale(pygame.image.load('images/animals/left/8FoxLeft.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +# mark +hint = pygame.transform.scale(pygame.image.load("images/hint.png"), (CHESSSIZE_X, CHESSSIZE_Y)) +capture_hint = pygame.transform.scale(pygame.image.load("images/capture-hint.png"), (CHESSSIZE_X, CHESSSIZE_Y)) +left_turn = pygame.transform.scale(pygame.image.load("images/left_turn.png"), (CHESSSIZE_X, CHESSSIZE_Y)) +right_turn = pygame.transform.scale(pygame.image.load("images/right_turn.png"), (CHESSSIZE_X, CHESSSIZE_Y)) +# animals img +# Left +L_mouse = pygame.transform.scale(pygame.image.load('images/animals/left/1MouseLeft.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +L_eagle = pygame.transform.scale(pygame.image.load('images/animals/left/2EagleLeft.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +L_wolf = pygame.transform.scale(pygame.image.load('images/animals/left/3WolfLeft.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +L_leopard = pygame.transform.scale(pygame.image.load('images/animals/left/4LeopardLeft.png'), + (CHESSSIZE_X, CHESSSIZE_Y)) +L_tiger = pygame.transform.scale(pygame.image.load('images/animals/left/5TigerLeft.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +L_lion = pygame.transform.scale(pygame.image.load('images/animals/left/6LionLeft.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +L_elephant = pygame.transform.scale(pygame.image.load('images/animals/left/7ElephantLeft.png'), + (CHESSSIZE_X, CHESSSIZE_Y)) +L_fox = pygame.transform.scale(pygame.image.load('images/animals/left/8FoxLeft.png'), (CHESSSIZE_X, CHESSSIZE_Y)) -#Right -R_mouse = pygame.transform.scale(pygame.image.load('images/animals/right/1MouseRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -R_eagle = pygame.transform.scale(pygame.image.load('images/animals/right/2EagleRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -R_wolf = pygame.transform.scale(pygame.image.load('images/animals/right/3WolfRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -R_leopard = pygame.transform.scale(pygame.image.load('images/animals/right/4LeopardRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -R_tiger = pygame.transform.scale(pygame.image.load('images/animals/right/5TigerRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -R_lion = pygame.transform.scale(pygame.image.load('images/animals/right/6LionRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -R_elephant = pygame.transform.scale(pygame.image.load('images/animals/right/7ElephantRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) -R_fox = pygame.transform.scale(pygame.image.load('images/animals/right/8FoxRight.png'),(CHESSSIZE_X,CHESSSIZE_Y)) +# Right +R_mouse = pygame.transform.scale(pygame.image.load('images/animals/right/1MouseRight.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +R_eagle = pygame.transform.scale(pygame.image.load('images/animals/right/2EagleRight.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +R_wolf = pygame.transform.scale(pygame.image.load('images/animals/right/3WolfRight.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +R_leopard = pygame.transform.scale(pygame.image.load('images/animals/right/4LeopardRight.png'), + (CHESSSIZE_X, CHESSSIZE_Y)) +R_tiger = pygame.transform.scale(pygame.image.load('images/animals/right/5TigerRight.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +R_lion = pygame.transform.scale(pygame.image.load('images/animals/right/6LionRight.png'), (CHESSSIZE_X, CHESSSIZE_Y)) +R_elephant = pygame.transform.scale(pygame.image.load('images/animals/right/7ElephantRight.png'), + (CHESSSIZE_X, CHESSSIZE_Y)) +R_fox = pygame.transform.scale(pygame.image.load('images/animals/right/8FoxRight.png'), (CHESSSIZE_X, CHESSSIZE_Y)) ############################################################################### -#colour########################################################### -BLACK = (0,0,0) -LIGHTBLUE = (40,191,255) -LIGHTBLUE2 = (0,0,255) -BGCOLOR = (230,230,250) -MAGENTA = (255,0,255) -LIGHTYELLOW= (255,225,0) -MYCOLOR = (255,165,0) -WHITE = (255,255,255) -GREEN = (0,255,0) -RED = (255,0,0) -BLUE = (0,0,255) -Crimson=(220,20,60) -LightPink=(255,182,193) -DeepSkyBlue=(0,191,255) +# colour########################################################### +BLACK = (0, 0, 0) +LIGHTBLUE = (40, 191, 255) +LIGHTBLUE2 = (0, 0, 255) +BGCOLOR = (230, 230, 250) +MAGENTA = (255, 0, 255) +LIGHTYELLOW = (255, 225, 0) +MYCOLOR = (255, 165, 0) +WHITE = (255, 255, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) +BLUE = (0, 0, 255) +Crimson = (220, 20, 60) +LightPink = (255, 182, 193) +DeepSkyBlue = (0, 191, 255) + + ############################################################# -#TEXT -def print_text(WIN,font,x,y,text,fcolor=WHITE): - imgText = font .render(text,True,fcolor) - WIN.blit(imgText,(x,y)) +# TEXT +def print_text(WIN, font, x, y, text, fcolor=WHITE): + imgText = font.render(text, True, fcolor) + WIN.blit(imgText, (x, y)) + ###################################### -def draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox): +def draw_left_animals(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox): if ID[7]: - WIN.blit(L_elephant,(l_elephant.x,l_elephant.y)) + WIN.blit(L_elephant, (l_elephant.x, l_elephant.y)) if ID[2]: WIN.blit(L_eagle, (l_eagle.x, l_eagle.y)) if ID[4]: @@ -112,13 +118,14 @@ def draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox): if ID[3]: WIN.blit(L_fox, (l_fox.x, l_fox.y)) -def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox): + +def draw_right_animals(r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_mouse, r_fox): if ID[14]: WIN.blit(R_elephant, (r_elephant.x, r_elephant.y)) if ID[9]: WIN.blit(R_eagle, (r_eagle.x, r_eagle.y)) if ID[11]: - WIN.blit(R_wolf, (r_wolf.x,r_wolf.y)) + WIN.blit(R_wolf, (r_wolf.x, r_wolf.y)) if ID[13]: WIN.blit(R_lion, (r_lion.x, r_lion.y)) if ID[12]: @@ -129,45 +136,50 @@ def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) WIN.blit(R_fox, (r_fox.x, r_fox.y)) -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): +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)) + WIN.blit(SPACE, (0, 0)) if turn == 1: - WIN.blit(left_turn,init.tran(8,3)) + WIN.blit(left_turn, init.tran(8, 3)) elif turn == 0: - WIN.blit(right_turn,init.tran(0,3)) - draw_left_animals(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox) - draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) + WIN.blit(right_turn, init.tran(0, 3)) + draw_left_animals(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox) + draw_right_animals(r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_mouse, r_fox) path(id, x, y, status, MAP, MAP1, turn) pygame.display.update() -#animals rect -l_elephant = pygame.Rect(281,10,CHESSSIZE_Y,CHESSSIZE_Y) -l_eagle = pygame.Rect(157,120,CHESSSIZE_Y,CHESSSIZE_Y) -l_wolf = pygame.Rect(284,229,CHESSSIZE_Y,CHESSSIZE_Y) -l_lion = pygame.Rect(282,343,CHESSSIZE_Y,CHESSSIZE_Y) -l_leopard = pygame.Rect(285,450,CHESSSIZE_Y,CHESSSIZE_Y) -l_mouse = pygame.Rect(285,665,CHESSSIZE_Y,CHESSSIZE_Y) -l_fox = pygame.Rect(157,557,CHESSSIZE_Y,CHESSSIZE_Y) -r_elephant = pygame.Rect(795,673,CHESSSIZE_Y,CHESSSIZE_Y) -r_eagle = pygame.Rect(925,570,CHESSSIZE_Y,CHESSSIZE_Y) -r_wolf = pygame.Rect(803,458,CHESSSIZE_Y,CHESSSIZE_Y) -r_lion = pygame.Rect(802,347,CHESSSIZE_Y,CHESSSIZE_Y) -r_leopard = pygame.Rect(796,232,CHESSSIZE_Y,CHESSSIZE_Y) -r_fox = pygame.Rect(920,123,CHESSSIZE_Y,CHESSSIZE_Y) -r_mouse = pygame.Rect(793,16,CHESSSIZE_Y,CHESSSIZE_Y) +# animals rect +l_elephant = pygame.Rect(281, 10, CHESSSIZE_Y, CHESSSIZE_Y) +l_eagle = pygame.Rect(157, 120, CHESSSIZE_Y, CHESSSIZE_Y) +l_wolf = pygame.Rect(284, 229, CHESSSIZE_Y, CHESSSIZE_Y) +l_lion = pygame.Rect(282, 343, CHESSSIZE_Y, CHESSSIZE_Y) +l_leopard = pygame.Rect(285, 450, CHESSSIZE_Y, CHESSSIZE_Y) +l_mouse = pygame.Rect(285, 665, CHESSSIZE_Y, CHESSSIZE_Y) +l_fox = pygame.Rect(157, 557, CHESSSIZE_Y, CHESSSIZE_Y) + +r_elephant = pygame.Rect(795, 673, CHESSSIZE_Y, CHESSSIZE_Y) +r_eagle = pygame.Rect(925, 570, CHESSSIZE_Y, CHESSSIZE_Y) +r_wolf = pygame.Rect(803, 458, CHESSSIZE_Y, CHESSSIZE_Y) +r_lion = pygame.Rect(802, 347, CHESSSIZE_Y, CHESSSIZE_Y) +r_leopard = pygame.Rect(796, 232, CHESSSIZE_Y, CHESSSIZE_Y) +r_fox = pygame.Rect(920, 123, CHESSSIZE_Y, CHESSSIZE_Y) +r_mouse = pygame.Rect(793, 16, CHESSSIZE_Y, CHESSSIZE_Y) ############################################# -l_animals =r_animals = 7 +l_animals = r_animals = 7 -def ismove(old_x,old_y,x,y,id,MAP,MAP1): + +def ismove(old_x, old_y, x, y, id, MAP, MAP1): global l_animals global r_animals if id == 1: if MAP[x][y] == 16: return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or MAP[x][y] == 8): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][ + y] == 14 or (MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or MAP[x][y] == 8): if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: return 0 if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: @@ -178,14 +190,16 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y] <= 14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 if MAP1[x][y] == 15 and not (8 <= MAP[x][y] <= 14): return 0 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or MAP[x][y] == 8): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][ + y] == 14 or (MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or MAP[x][y] == 8): if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: return 0 if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: @@ -201,17 +215,19 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): r_animals -= 1 return 1 return 1 - else : + else: return 0 elif id == 2: - if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][y] != 15 and (9 < MAP[x][y] <= 14): + if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][ + y] != 15 and (9 < MAP[x][y] <= 14): return 0 - if x == old_x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=9): + if x == old_x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 9): if y > old_y: - for i in range(old_y+1,y): - if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 16 and MAP[x][i] != 18): + for i in range(old_y + 1, y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 16 and MAP[x][i] != 18): return 0 - if 8<=MAP[x][y]<=9: + if 8 <= MAP[x][y] <= 9: if MAP[x][y] == 8: if MAP1[x][y] != 20: ID[MAP[x][y]] = 0 @@ -219,19 +235,19 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): return 1 else: return 0 - ID[MAP[x][y]]=0 + ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 else: - for i in range(y+1,old_y): - if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 16 and MAP[x][i] != 18 ): + for i in range(y + 1, old_y): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 16 and MAP[x][i] != 18): return 0 - if 8<=MAP[x][y]<=9: + if 8 <= MAP[x][y] <= 9: if MAP[x][y] == 8: if MAP1[x][y] != 20: ID[MAP[x][y]] = 0 @@ -239,20 +255,21 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): return 1 else: return 0 - ID[MAP[x][y]]=0 + ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=9): + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 9): if x > old_x: - for i in range(old_x+1,x): - if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 16 and MAP[i][y] != 18): + for i in range(old_x + 1, x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 16 and MAP[i][y] != 18): return 0 - if 8<=MAP[x][y]<=9: + if 8 <= MAP[x][y] <= 9: if MAP[x][y] == 8: if MAP1[x][y] != 20: ID[MAP[x][y]] = 0 @@ -260,19 +277,19 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): return 1 else: return 0 - ID[MAP[x][y]]=0 + ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - else : - for i in range(x+1,old_x): - if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 16 and MAP[i][y] != 18): + else: + for i in range(x + 1, old_x): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 16 and MAP[i][y] != 18): return 0 - if 8<=MAP[x][y]<=9: + if 8 <= MAP[x][y] <= 9: if MAP[x][y] == 8: if MAP1[x][y] != 20: ID[MAP[x][y]] = 0 @@ -280,18 +297,20 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): return 1 else: return 0 - ID[MAP[x][y]]=0 + ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - else : + else: return 0 elif id == 3: - if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=10): + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 10): if 8 <= MAP[x][y] <= 10: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -303,7 +322,7 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 @@ -312,9 +331,11 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): elif id == 4: if MAP[x][y] == 16: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=11): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 11): if 8 <= MAP[x][y] <= 11: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -326,12 +347,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=11): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 11): if 8 <= MAP[x][y] <= 11: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -343,19 +366,21 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - else : + else: return 0 elif id == 5: if MAP[x][y] == 16: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=12): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 12): if 8 <= MAP[x][y] <= 12: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -367,13 +392,15 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=12): - if 8 <= MAP[x][y] <= 12 : + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 12): + if 8 <= MAP[x][y] <= 12: if MAP[x][y] == 8: if MAP1[x][y] != 20: ID[MAP[x][y]] = 0 @@ -384,19 +411,21 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - else : + else: return 0 elif id == 6: if MAP[x][y] == 16: return 0 if MAP[x][y] == 20: return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=13): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -408,12 +437,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=13): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -425,15 +456,16 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=13): + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if y > old_y: - for i in range(old_y+1,y): - if MAP[x][i] != 20 and MAP[x][i] != 1 : + for i in range(old_y + 1, y): + if MAP[x][i] != 20 and MAP[x][i] != 1: return 0 if 8 <= MAP[x][y] <= 14: if MAP[x][y] == 8: @@ -446,14 +478,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 else: - for i in range(y+1,old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1 : + for i in range(y + 1, old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1: return 0 if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: @@ -466,15 +498,16 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 8<=MAP[x][y]<=13): + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if x > old_x: - for i in range(old_x+1,x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(old_x + 1, x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: @@ -487,14 +520,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 else: - for i in range(x+1,old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(x + 1, old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: @@ -507,7 +540,7 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 @@ -517,9 +550,11 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): elif id == 7: if MAP[x][y] == 16: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 9<=MAP[x][y]<=14): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 9 <= MAP[x][y] <= 14): if 9 <= MAP[x][y] <= 14: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -531,12 +566,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or 9<=MAP[x][y]<=14): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 9 <= MAP[x][y] <= 14): if 9 <= MAP[x][y] <= 14: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -548,17 +585,19 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 r_animals -= 1 return 1 - if MAP1[x][y] == 15 and 8<=MAP[x][y]<=14: + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 r_animals -= 1 return 1 return 1 - else : + else: return 0 elif id == 8: if MAP[x][y] == 18: return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or MAP[x][y] == 1): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][ + y] == 7 or (MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or MAP[x][y] == 1): if MAP[x][y] == 7: if MAP1[old_x][old_y] != 20: ID[7] = 0 @@ -570,12 +609,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[1] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or MAP[x][y] == 1): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][ + y] == 7 or (MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or MAP[x][y] == 1): if MAP[x][y] == 7: if MAP1[old_x][old_y] != 20: ID[7] = 0 @@ -592,15 +633,17 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): l_animals -= 1 return 1 return 1 - else : + else: return 0 elif id == 9: - if MAP[x][y] == 18 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 16 and MAP1[x][y] != 17 and (2 old_y: for i in range(old_y + 1, y): - if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[x][i] != 18): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[x][i] != 18): return 0 if 1 <= MAP[x][y] <= 2: if MAP[x][y] == 1: @@ -613,14 +656,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 else: for i in range(y + 1, old_y): - if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[x][i] != 18): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[x][i] != 18): return 0 if 1 <= MAP[x][y] <= 2: if MAP[x][y] == 1: @@ -633,15 +676,16 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=2): + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 2): if x > old_x: for i in range(old_x + 1, x): - if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 18): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 18): return 0 if 1 <= MAP[x][y] <= 2: if MAP[x][y] == 1: @@ -654,14 +698,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 else: for i in range(x + 1, old_x): - if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 18): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 18): return 0 if 1 <= MAP[x][y] <= 2: if MAP[x][y] == 1: @@ -674,7 +718,7 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 @@ -682,7 +726,9 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 elif id == 10: - if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=3): + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 3): if 1 <= MAP[x][y] <= 3: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -694,7 +740,7 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 @@ -703,9 +749,11 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): elif id == 11: if MAP[x][y] == 18: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=4): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 4): if 1 <= MAP[x][y] <= 4: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -717,12 +765,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=4): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 4): if 1 <= MAP[x][y] <= 4: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -734,19 +784,21 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - else : + else: return 0 elif id == 12: if MAP[x][y] == 18: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=5): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 5): if 1 <= MAP[x][y] <= 5: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -758,12 +810,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=5): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 5): if 1 <= MAP[x][y] <= 5: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -775,19 +829,21 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - else : + else: return 0 elif id == 13: if MAP[x][y] == 18: return 0 if MAP[x][y] == 20: return 0 - if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=6): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -799,12 +855,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=6): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -816,15 +874,16 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=6): + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if y > old_y: - for i in range(old_y+1,y): - if MAP[x][i] != 20 and MAP[x][i] != 8 : + for i in range(old_y + 1, y): + if MAP[x][i] != 20 and MAP[x][i] != 8: return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -837,14 +896,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 else: - for i in range(y+1,old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1 : + for i in range(y + 1, old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1: return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -857,15 +916,16 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=6): + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if x > old_x: - for i in range(old_x+1,x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(old_x + 1, x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -878,14 +938,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 else: - for i in range(x+1,old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(x + 1, old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -898,7 +958,7 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 @@ -908,9 +968,11 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): elif id == 14: if MAP[x][y] == 18: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 2<=MAP[x][y]<=7): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 2 <= MAP[x][y] <= 7): if 2 <= MAP[x][y] <= 7: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -922,12 +984,14 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 2<=MAP[x][y]<=7): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 2 <= MAP[x][y] <= 7): if 2 <= MAP[x][y] <= 7: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -939,50 +1003,55 @@ def ismove(old_x,old_y,x,y,id,MAP,MAP1): ID[MAP[x][y]] = 0 l_animals -= 1 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: ID[MAP[x][y]] = 0 l_animals -= 1 return 1 return 1 - else : + else: return 0 + def path(id, x, y, status, MAP, MAP1, turn): if status: movement = [] for i in range(9): for j in range(7): if turn == 0: - if right_move(x, y, i, j, id, MAP,MAP1): + if right_move(x, y, i, j, id, MAP, MAP1): movement.append([i, j]) else: - if left_move(x, y, i, j, id, MAP,MAP1): + if left_move(x, y, i, j, id, MAP, MAP1): movement.append([i, j]) for i, j in movement: - WIN.blit(hint, init.tran(i,j)) - WIN.blit(capture_hint,init.tran(x,y)) + WIN.blit(hint, init.tran(i, j)) + WIN.blit(capture_hint, init.tran(x, y)) + -def left_win(x,y,MAP,MAP1): +def left_win(x, y, MAP, MAP1): global r_animals if r_animals == 0: return 1 - if MAP1[x][y] == 18 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 18 and 1 <= MAP[x][y] <= 7: return 1 isWin = 0 - for i in range(8,15): + for i in range(8, 15): if ID[i] == 1: - isWin = left_Wall(i,MAP,MAP1) + isWin = left_Wall(i, MAP, MAP1) if isWin == 0: return 0 if isWin == 1: return 1 return 0 -def left_move(old_x,old_y,x,y,id,MAP,MAP1): + +def left_move(old_x, old_y, x, y, id, MAP, MAP1): if id == 8: if MAP[x][y] == 18: return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or MAP[x][y] == 1): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][ + y] == 7 or (MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or MAP[x][y] == 1): if MAP[x][y] == 7: if MAP1[old_x][old_y] != 20: return 1 @@ -990,10 +1059,12 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): return 0 if MAP[x][y] == 1: return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][y] == 7 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or MAP[x][y] == 1): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or MAP[x][ + y] == 7 or (MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or MAP[x][y] == 1): if MAP[x][y] == 7: if MAP1[old_x][old_y] != 20: return 1 @@ -1004,15 +1075,17 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - else : + else: return 0 elif id == 9: - if MAP[x][y] == 18 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 16 and MAP1[x][y] != 17 and (2 old_y: for i in range(old_y + 1, y): - if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[x][i] != 18): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[x][i] != 18): return 0 if 1 <= MAP[x][y] <= 2: if MAP[x][y] == 1: @@ -1021,12 +1094,12 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 else: for i in range(y + 1, old_y): - if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[x][i] != 18): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 17 and MAP[x][i] != 18): return 0 if 1 <= MAP[x][y] <= 2: if MAP[x][y] == 1: @@ -1035,13 +1108,14 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=2): + elif y == old_y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 2): if x > old_x: for i in range(old_x + 1, x): - if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 18): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 17 and MAP[i][y] != 18): return 0 if 1 <= MAP[x][y] <= 2: if MAP[x][y] == 1: @@ -1050,7 +1124,7 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 else: @@ -1064,13 +1138,15 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 else: return 0 elif id == 10: - if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=3): + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 3): if 1 <= MAP[x][y] <= 3: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1078,16 +1154,18 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 return 0 elif id == 11: if MAP[x][y] == 18: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=4): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 4): if 1 <= MAP[x][y] <= 4: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1095,10 +1173,12 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=4): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 4): if 1 <= MAP[x][y] <= 4: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1106,17 +1186,19 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - else : + else: return 0 elif id == 12: if MAP[x][y] == 18: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=5): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 5): if 1 <= MAP[x][y] <= 5: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1124,10 +1206,12 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=5): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 5): if 1 <= MAP[x][y] <= 5: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1135,17 +1219,19 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - else : + else: return 0 elif id == 13: if MAP[x][y] == 18: return 0 if MAP[x][y] == 20: return 0 - if abs(x - old_x) ==1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=6): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1153,10 +1239,12 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=6): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1164,13 +1252,14 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=6): + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if y > old_y: - for i in range(old_y+1,y): - if MAP[x][i] != 20 and MAP[x][i] != 8 : + for i in range(old_y + 1, y): + if MAP[x][i] != 20 and MAP[x][i] != 8: return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1179,12 +1268,12 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 else: - for i in range(y+1,old_y): - if MAP[x][i] != 20 and MAP[x][i] != 1 : + for i in range(y + 1, old_y): + if MAP[x][i] != 20 and MAP[x][i] != 1: return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1193,13 +1282,14 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=6): + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6): if x > old_x: - for i in range(old_x+1,x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(old_x + 1, x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1208,12 +1298,12 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 else: - for i in range(x+1,old_x): - if MAP[i][y] != 20 and MAP[i][y] != 1 : + for i in range(x + 1, old_x): + if MAP[i][y] != 20 and MAP[i][y] != 1: return 0 if 1 <= MAP[x][y] <= 6: if MAP[x][y] == 1: @@ -1222,7 +1312,7 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 else: @@ -1230,9 +1320,11 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): elif id == 14: if MAP[x][y] == 18: return 0 - if(MAP[x][y] == 20): + if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 2<=MAP[x][y]<=7): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 2 <= MAP[x][y] <= 7): if 2 <= MAP[x][y] <= 7: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1240,10 +1332,12 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 2<=MAP[x][y]<=7): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or ( + MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 2 <= MAP[x][y] <= 7): if 2 <= MAP[x][y] <= 7: if MAP[x][y] == 1: if MAP1[x][y] != 20: @@ -1251,16 +1345,17 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 return 1 - if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: return 1 return 1 - else : + else: return 0 -def left_Wall(id,MAP,MAP1): - if 8<=id<=14: + +def left_Wall(id, MAP, MAP1): + if 8 <= id <= 14: if id == 8: - old_x,old_y = init.calc(r_mouse.x,r_mouse.y) + old_x, old_y = init.calc(r_mouse.x, r_mouse.y) elif id == 9: old_x, old_y = init.calc(r_eagle.x, r_eagle.y) elif id == 10: @@ -1273,14 +1368,16 @@ def left_Wall(id,MAP,MAP1): old_x, old_y = init.calc(r_lion.x, r_lion.y) elif id == 14: old_x, old_y = init.calc(r_elephant.x, r_elephant.y) - for x in range(0,9): - for y in range(0,7): - if left_move(old_x,old_y,x,y,id,MAP,MAP1): + for x in range(0, 9): + for y in range(0, 7): + if left_move(old_x, old_y, x, y, id, MAP, MAP1): return 0 return 1 else: return 0 -def right_win(x,y,MAP,MAP1): + + +def right_win(x, y, MAP, MAP1): isWin = 0 global l_animals if l_animals == 0: @@ -1289,19 +1386,21 @@ def right_win(x,y,MAP,MAP1): return 1 for i in range(1, 8): if ID[i] == 1: - isWin = right_Wall(i,MAP,MAP1) + isWin = right_Wall(i, MAP, MAP1) if isWin == 0: return 0 if isWin == 1: return 1 return 0 -def right_move(old_x,old_y,x,y,id,MAP,MAP1): + +def right_move(old_x, old_y, x, y, id, MAP, MAP1): if id == 1: if MAP[x][y] == 16: return 0 if abs(x - old_x) == 1 and old_y == y and ( - MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14) or MAP[x][y] == 8): + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][ + y] == 14 or (MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or MAP[x][y] == 8): if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: return 0 if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: @@ -1312,7 +1411,8 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 1 return 1 elif old_x == x and abs(y - old_y) == 1 and ( - MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][y] == 14 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or MAP[x][y] == 8): + MAP[x][y] == 0 or MAP[x][y] == 20 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or MAP[x][ + y] == 14 or (MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or MAP[x][y] == 8): if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20: return 0 if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: @@ -1325,10 +1425,12 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 elif id == 2: - if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][y] != 15 and (9 < MAP[x][y] <= 14): + if MAP[x][y] == 16 and MAP[x][y] != 0 and MAP[x][y] != 15 and MAP[x][y] != 17 and MAP[x][y] != 18 and MAP1[x][ + y] != 15 and (9 < MAP[x][y] <= 14): return 0 if x == old_x and ( - MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 9): + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 9): if y > old_y: for i in range(old_y + 1, y): if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 16 and MAP[x][i] != 18): @@ -1345,7 +1447,7 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 1 else: for i in range(y + 1, old_y): - if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 16 and MAP[x][i] != 18): + if (MAP[x][i] != 0 and MAP[x][i] != 20 and MAP[x][i] != 15 and MAP[x][i] != 16 and MAP[x][i] != 18): return 0 if 8 <= MAP[x][y] <= 9: if MAP[x][y] == 8: @@ -1358,10 +1460,11 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 1 return 1 elif y == old_y and ( - MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 9): + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 9): if x > old_x: for i in range(old_x + 1, x): - if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 16 and MAP[i][y] != 18): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 16 and MAP[i][y] != 18): return 0 if 8 <= MAP[x][y] <= 9: if MAP[x][y] == 8: @@ -1375,7 +1478,7 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 1 else: for i in range(x + 1, old_x): - if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 16 and MAP[i][y] != 18): + if (MAP[i][y] != 0 and MAP[i][y] != 20 and MAP[i][y] != 15 and MAP[i][y] != 16 and MAP[i][y] != 18): return 0 if 8 <= MAP[x][y] <= 9: if MAP[x][y] == 8: @@ -1390,7 +1493,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 elif id == 3: - if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 10): + if abs(x - old_x) <= 1 and abs(y - old_y) <= 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 10): if 8 <= MAP[x][y] <= 10: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1407,7 +1512,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 0 if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 11): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 11): if 8 <= MAP[x][y] <= 11: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1418,7 +1525,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 11): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 11): if 8 <= MAP[x][y] <= 11: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1436,7 +1545,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 0 if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 12): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 12): if 8 <= MAP[x][y] <= 12: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1447,7 +1558,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 12): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 12): if 8 <= MAP[x][y] <= 12: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1465,7 +1578,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 0 if MAP[x][y] == 20: return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 13): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1476,7 +1591,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 13): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if 8 <= MAP[x][y] <= 13: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1487,7 +1604,8 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 13): + elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if y > old_y: for i in range(old_y + 1, y): if MAP[x][i] != 20 and MAP[x][i] != 1: @@ -1516,7 +1634,8 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 8 <=MAP[x][y] <= 13): + elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 8 <= MAP[x][y] <= 13): if x > old_x: for i in range(old_x + 1, x): if MAP[i][y] != 20 and MAP[i][y] != 1: @@ -1552,7 +1671,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 0 if (MAP[x][y] == 20): return 0 - if abs(x - old_x) == 1 and old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 9 <=MAP[x][y] <= 14): + if abs(x - old_x) == 1 and old_y == y and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 9 <= MAP[x][y] <= 14): if 9 <= MAP[x][y] <= 14: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1563,7 +1684,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: return 1 return 1 - elif old_x == x and abs(y - old_y) == 1 and (MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or (MAP1[x][y] == 15 and 8<=MAP[x][y]<=14)or 9 <=MAP[x][y] <= 14): + elif old_x == x and abs(y - old_y) == 1 and ( + MAP[x][y] == 0 or MAP[x][y] == 15 or MAP[x][y] == 17 or MAP[x][y] == 18 or ( + MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14) or 9 <= MAP[x][y] <= 14): if 9 <= MAP[x][y] <= 14: if MAP[x][y] == 8: if MAP1[x][y] != 20: @@ -1576,10 +1699,12 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): return 1 else: return 0 -def right_Wall(id,MAP,MAP1): - if 1<=id<=7: + + +def right_Wall(id, MAP, MAP1): + if 1 <= id <= 7: if id == 1: - old_x,old_y = init.calc(l_mouse.x,l_mouse.y) + old_x, old_y = init.calc(l_mouse.x, l_mouse.y) elif id == 2: old_x, old_y = init.calc(l_eagle.x, l_eagle.y) elif id == 3: @@ -1592,20 +1717,23 @@ def right_Wall(id,MAP,MAP1): old_x, old_y = init.calc(l_lion.x, l_lion.y) elif id == 7: old_x, old_y = init.calc(l_elephant.x, l_elephant.y) - for x in range(0,9): - for y in range(0,7): - if right_move(old_x,old_y,x,y,id,MAP,MAP1): + for x in range(0, 9): + for y in range(0, 7): + if right_move(old_x, old_y, x, y, id, MAP, MAP1): return 0 return 1 else: return 0 + player = s.Player() 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) -def server_thread(conn,addr) : - global player,Axis + + +def server_thread(conn, addr): + global player, Axis while True: try: msg = conn.recv(1024) @@ -1613,13 +1741,13 @@ def server_thread(conn,addr) : break print(msg) msg = json.loads(msg) - #TODO : side的确定 + # TODO : side的确定 if not 'status' in msg: - status_2,game_id,side,old_x,old_y,x,y, num = C.handle_move(msg) + 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 + if side == 0: + id = id + 7 + #print("turn,id:",side , id) player.game_id = game_id player.status_2 = status_2 Axis.axis[id]['old_x'] = old_x @@ -1630,7 +1758,7 @@ def server_thread(conn,addr) : player.invalid = 1 continue elif msg["status"] == 1: - status_2,counterpart_name,game_id,side,think_time,total_time = C.handle_new_player(msg) + status_2, counterpart_name, game_id, side, think_time, total_time = C.handle_new_player(msg) player.game_id = game_id player.status_2 = status_2 player.side = 1 - side @@ -1640,7 +1768,7 @@ def server_thread(conn,addr) : player.invalid = 1 continue elif msg["status"] == 2: - status_2,request,game_id,side = C.handle_exit_game(msg) + status_2, request, game_id, side = C.handle_exit_game(msg) player.status_2 = status_2 player.request = request player.game_id = game_id @@ -1677,6 +1805,8 @@ def server_thread(conn,addr) : mutex_playing = Lock() + + def time_thread(): mutex_playing.acquire() is_over_time = 0 @@ -1690,19 +1820,20 @@ def time_thread(): player.total_time -= 1 if is_over_time: return False - else : + else: return True + class Config: - SOCKET_HOST = '127.0.0.1'#Symbolic name meaning all available interfaces - SOCKET_PORT = 50005#Arbitrary non-privileged port + 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 MAX_TOTAL_TIME = 600 def main(): - global l_animals,r_animals + global l_animals, r_animals global player, Axis BGM.play(-1) MAP = init.calc_map() @@ -1710,9 +1841,9 @@ def main(): game_status = start_game.starting_screen() Left_win = Right_win = 0 demo = 0 # 标识是否为网络版 - pause = 0 # 标识是否请求暂停游戏 - exit = 0 # 标识是否请求退出游戏 - report = 0 # 标识是否举报对方 + pause = 0 # 标识是否请求暂停游戏 + exit = 0 # 标识是否请求退出游戏 + report = 0 # 标识是否举报对方 if not game_status: return False elif game_status == 1: @@ -1723,8 +1854,8 @@ def main(): demo = 2 run = True clock = pygame.time.Clock() - font = pygame.font.SysFont('kaiti',40) - status = id = old_x = old_y = x = y = 0 + font = pygame.font.SysFont('kaiti', 40) + status = id = old_x = old_y = x = y = 0 turn = 1 if (demo == 1 or demo == 2): name = input("Please tell us your name:") @@ -1739,10 +1870,10 @@ def main(): C.conn_to_server(client, name) while run: clock.tick(FPS) - #print(turn,player.side) + # 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) + 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: @@ -1752,13 +1883,13 @@ def main(): if right_win(x, y, MAP, MAP1) or ((demo == 1 or demo == 2) and Right_win == 1): run = False if demo == 1 or demo == 2: - C.start_new_thread(server_thread, (client,Address)) + C.start_new_thread(server_thread, (client, Address)) Right_win = player.Right_win Left_win = player.Left_win for event in pygame.event.get(): if event.type == pygame.QUIT: run = False - elif event.type == pygame.KEYDOWN and demo == 1: # and demo == 1 + elif event.type == pygame.KEYDOWN and demo == 1: # and demo == 1 if event.key == pygame.K_ESCAPE: flag = start_game.starting_menu() if flag == 1: @@ -1773,14 +1904,15 @@ def main(): elif event.type == pygame.MOUSEBUTTONDOWN: b1, b2, b3 = pygame.mouse.get_pressed() if b1 and not b3: - mouse_x , mouse_y = event.pos + mouse_x, mouse_y = event.pos old_x = x old_y = y - x = int((mouse_x+10) / WIDTH * 9) - y = int((mouse_y+10) / HEIGHT * 7) - if status == 0 : + x = int((mouse_x + 10) / WIDTH * 9) + y = int((mouse_y + 10) / HEIGHT * 7) + if status == 0: id = MAP[x][y] - if (0 < id < 8 and turn == 0 and demo == 0) or (0 < id < 8 and demo == 1 and turn == player.side): + if (0 < id < 8 and turn == 0 and demo == 0) or ( + 0 < id < 8 and demo == 1 and turn == player.side): if id == 1: Mouse.play() elif id == 2: @@ -1796,7 +1928,8 @@ def main(): elif id == 7: Elephant.play() status = 1 - elif (7 < id <15 and turn == 1 and demo == 0) or (7 < id <15 and demo == 1 and turn == player.side): + elif (7 < id < 15 and turn == 1 and demo == 0) or ( + 7 < id < 15 and demo == 1 and turn == player.side): if id == 8: Mouse.play() if id == 9: @@ -1813,352 +1946,382 @@ def main(): Elephant.play() status = 2 else: - if (id == 1 and turn == 0 and status == 1 and demo == 0) or (id == 1 and demo == 1 and status == 1 and turn == player.side and turn == 0): + if (id == 1 and turn == 0 and status == 1 and demo == 0) or ( + id == 1 and demo == 1 and status == 1 and turn == player.side and turn == 0): if MAP[x][y] == id: status = 1 else: - if(ismove(old_x,old_y,x,y,id,MAP,MAP1)): - l_mouse.x,l_mouse.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + l_mouse.x, l_mouse.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 - if(demo == 1): - C.move(client,player.game_id,1 - player.side,(id+7) % 14,old_x,old_y,x,y) + if (demo == 1): + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) 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): + 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): if MAP[x][y] == id: status = 1 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - l_eagle.x , l_eagle.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + l_eagle.x, l_eagle.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 1 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - l_fox.x , l_fox.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + l_fox.x, l_fox.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 1 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - l_wolf.x , l_wolf.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + l_wolf.x, l_wolf.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 1 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - l_leopard.x , l_leopard.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + l_leopard.x, l_leopard.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 1 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - l_lion.x , l_lion.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + l_lion.x, l_lion.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 1 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - l_elephant.x , l_elephant.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + l_elephant.x, l_elephant.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 2 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - r_mouse.x , r_mouse.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + r_mouse.x, r_mouse.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 2 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - r_eagle.x , r_eagle.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + r_eagle.x, r_eagle.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 2 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - r_fox.x , r_fox.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + r_fox.x, r_fox.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 2 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - r_wolf.x , r_wolf.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + r_wolf.x, r_wolf.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 2 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - r_leopard.x , r_leopard.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + r_leopard.x, r_leopard.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 2 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - r_lion.x , r_lion.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + r_lion.x, r_lion.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + 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): + 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): if MAP[x][y] == id: status = 2 else: - if (ismove(old_x,old_y,x,y,id,MAP,MAP1)) : - r_elephant.x , r_elephant.y = init.tran(x,y) + if (ismove(old_x, old_y, x, y, id, MAP, MAP1)): + r_elephant.x, r_elephant.y = init.tran(x, y) MAP[old_x][old_y] = MAP1[old_x][old_y] MAP[x][y] = id status = 0 if (demo == 1): - C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, + y) turn = 1 - turn - else : + else: status = 0 - elif (demo == 1) 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 - 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 : + 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: 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) + l_mouse.x, l_mouse.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 2 : + 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) + l_eagle.x, l_eagle.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 3 : + 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) + l_fox.x, l_fox.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 4 : + 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) + l_wolf.x, l_wolf.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 5 : + 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) + l_leopard.x, l_leopard.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 6 : + 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) + l_lion.x, l_lion.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 7 : + 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) + l_elephant.x, l_elephant.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 8 : + 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) + r_mouse.x, r_mouse.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 9 : + 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) + r_eagle.x, r_eagle.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 10 : + 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) + r_fox.x, r_fox.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 11 : + 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) + r_wolf.x, r_wolf.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 12 : + 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) + r_leopard.x, r_leopard.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 13 : + 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) + r_lion.x, r_lion.y = init.tran(counterpart_x, counterpart_y) + turn = (1 - turn) player.invalid = 0 - elif counterpart_id == 14 : + 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) + 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") + # 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_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) + #print(counterpart_id) if counterpart_id == 1: if MAP[counterpart_x][counterpart_y] != counterpart_id: if 8 <= MAP[counterpart_x][counterpart_y] <= 14: @@ -2299,9 +2462,9 @@ def main(): 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: + elif demo == 2 and turn == player.side: id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side, ID) # TODO:AI algorithm - print((id,x,y)) + #print((id,x,y)) if id == 1: if 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 @@ -2500,48 +2663,49 @@ def main(): 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) - if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1) or (demo == 1 and player.status_2 == -1 and player.invalid == 0 and left_win(counterpart_x,counterpart_y,MAP,MAP1)): + if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1) or ( + demo == 1 and player.status_2 == -1 and player.invalid == 0 and left_win(counterpart_x, counterpart_y, + MAP, MAP1)): run = False Left_win = 1 - if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1) or (demo == 1 and player.status_2 == -1 and player.invalid == 0 and right_win(counterpart_x,counterpart_y,MAP,MAP1)): + if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1) or ( + demo == 1 and player.status_2 == -1 and player.invalid == 0 and right_win(counterpart_x, counterpart_y, + MAP, MAP1)): run = False Right_win = 1 if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1): if demo == 1 and player.side == 0: if pause == 1: request = "stop" - C.exit_game(client,request,player.game_id,player.side) + C.exit_game(client, request, player.game_id, player.side) print_text(WIN, font, 500, 400, "Blue Win!", BLUE) pygame.display.update() - if (player.status_2 == 2 or player.status_2 ==3) and demo == 1 : - C.ack_exit_game(client, 1- player.side) - + if (player.status_2 == 2 or player.status_2 == 3) and demo == 1: + C.ack_exit_game(client, 1 - player.side) if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1): if demo == 1 and player.side == 1: if pause == 1: request = "stop" - C.exit_game(client,request,player.game_id,player.side) + C.exit_game(client, request, player.game_id, player.side) print_text(WIN, font, 500, 400, "Red Win!", RED) pygame.display.update() - if (player.status_2 == 2 or player.status_2 ==3) and demo == 1 : - C.ack_exit_game(client,1 - player.side) - + if (player.status_2 == 2 or player.status_2 == 3) and demo == 1: + C.ack_exit_game(client, 1 - player.side) time.sleep(10) - #os.system("pause") + # os.system("pause") return start_game.starting_screen() if __name__ == "__main__": again = 1 while again > 0: - 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_fox, r_mouse=init.refresh() + 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_fox, r_mouse = init.refresh() 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,0,0,0,0,0,0,0) + r_leopard, r_mouse, r_fox, 0, 0, 0, 0, 0, 0, 0) again = main() l_animals = r_animals = 7 ID = [1 for i in range(20)]