diff --git a/src/DLS.py b/src/DLS.py index 4bfccca..df1962c 100644 --- a/src/DLS.py +++ b/src/DLS.py @@ -4,15 +4,21 @@ import pygame import heapq import socket_client as s import init +import random + inf = 99999999 MAP1 = init.clac_MAP1() -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 @@ -20,10 +26,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 @@ -34,15 +42,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: @@ -51,12 +61,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: @@ -65,13 +75,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: @@ -80,7 +91,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: @@ -94,13 +105,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: @@ -108,16 +121,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: @@ -125,10 +140,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: @@ -136,17 +153,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: @@ -154,10 +173,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: @@ -165,17 +186,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: @@ -183,10 +206,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: @@ -194,13 +219,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: @@ -209,12 +235,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: @@ -223,13 +249,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: @@ -238,12 +265,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: @@ -252,7 +279,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: @@ -260,9 +287,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: @@ -270,10 +299,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: @@ -281,18 +312,20 @@ 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 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: @@ -303,7 +336,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: @@ -316,10 +350,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): @@ -336,7 +372,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: @@ -349,10 +385,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: @@ -366,7 +403,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: @@ -381,7 +418,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: @@ -398,7 +437,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: @@ -409,7 +450,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: @@ -427,7 +470,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: @@ -438,7 +483,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: @@ -456,7 +503,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: @@ -467,7 +516,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: @@ -478,7 +529,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: @@ -507,7 +559,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: @@ -543,7 +596,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: @@ -554,7 +609,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: @@ -568,11 +625,53 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1): else: return 0 -def getMAP(Animals): + +def getMAP(Animals, ID): copyMAP = [[0 for i in range(7)] for j in range(9)] + x, y = init.calc(87, 278) + copyMAP[x][y] = 15 + x, y = init.calc(211, 378) + copyMAP[x][y] = 15 + x, y = init.calc(85, 496) + copyMAP[x][y] = 15 + x, y = init.calc(81, 388) + copyMAP[x][y] = 16 + x, y = init.calc(1105, 282) + copyMAP[x][y] = 17 + x, y = init.calc(976, 381) + copyMAP[x][y] = 17 + x, y = init.calc(1114, 497) + copyMAP[x][y] = 17 + x, y = init.calc(1102, 379) + copyMAP[x][y] = 18 + x, y = init.calc(468, 185) + copyMAP[x][y] = 20 + x, y = init.calc(597, 180) + copyMAP[x][y] = 20 + x, y = init.calc(714, 184) + copyMAP[x][y] = 20 + x, y = init.calc(472, 273) + copyMAP[x][y] = 20 + x, y = init.calc(595, 275) + copyMAP[x][y] = 20 + x, y = init.calc(705, 275) + copyMAP[x][y] = 20 + x, y = init.calc(479, 505) + copyMAP[x][y] = 20 + x, y = init.calc(591, 504) + copyMAP[x][y] = 20 + x, y = init.calc(718, 514) + copyMAP[x][y] = 20 + x, y = init.calc(467, 598) + copyMAP[x][y] = 20 + x, y = init.calc(593, 604) + copyMAP[x][y] = 20 + x, y = init.calc(719, 604) + copyMAP[x][y] = 20 for animalId in range(1, len(Animals)): - x, y = Animals[animalId]['x'], Animals[animalId]['y'] - copyMAP[x][y] = animalId + if ID[animalId]: + x, y = Animals[animalId]['x'], Animals[animalId]['y'] + copyMAP[x][y] = animalId return copyMAP @@ -608,50 +707,51 @@ class PriorityQueue: self.push(item, priority) -def getMovement(Id, Animals): - MAP = getMAP(Animals) +def getMovement(Id, Animals, ID): + MAP = getMAP(Animals, ID) Movements = [] - o_x, o_y = Animals[Id]['old_x'], Animals[Id]['old_y'] + o_x, o_y = Animals[Id]['x'], Animals[Id]['y'] for x in range(len(MAP)): for y in range(len(MAP[0])): if 1 <= Id <= 7: if right_move(o_x, o_y, x, y, Id, MAP, MAP1): - move = (Id, x - o_x, y - o_y) + move = (Id, x, y) Movements.append(move) - else: + elif 8 <= Id <= 14: if left_move(o_x, o_y, x, y, Id, MAP, MAP1): - move = (Id, x - o_x, y - o_y) + move = (Id, x, y) Movements.append(move) return Movements -def getSuccessors(Animals, turn: int): +def getSuccessors(Animals, turn: int, ID): Successors = [] Actions = [] if turn == 0: # 1 ~ 7 for Id in range(1, 8): - Move = getMovement(Id, Animals) - for oneStep in Move: - Actions.append(oneStep) + if ID[Id]: + Move = getMovement(Id, Animals,ID) + for oneStep in Move: + Actions.append(oneStep) else: # 8 ~ 14 for Id in range(8, 15): - Move = getMovement(Id, Animals) - for oneStep in Move: - Actions.append(oneStep) - + if ID[Id]: + Move = getMovement(Id, Animals,ID) + for oneStep in Move: + Actions.append(oneStep) # update the map for action in Actions: - Id, dx, dy = action[0], action[1], action[2] + Id, n_x, n_y = action[0], action[1], action[2] t_Animals = copy.deepcopy(Animals) - x = Animals[Id]['old_x'] + dx - y = Animals[Id]['old_y'] + dy + x = n_x + y = n_y t_Animals[Id]['x'] = x t_Animals[Id]['y'] = y target = (Id, x, y) - #print(t_Animals) + # print(t_Animals) Successors.append((t_Animals, target)) # updateMAP() return Successors @@ -659,22 +759,22 @@ def getSuccessors(Animals, turn: int): class Information: def __init__(self): - self.piece_score = {1: 100, 8: 100, - 2: 70, 9: 70, + self.piece_score = {1: 40, 8: 40, + 2: 50, 9: 50, 3: 60, 10: 60, 4: 80, 11: 80, 5: 90, 12: 90, - 6: 120, 13: 120, + 6: 150, 13: 150, 7: 120, 14: 120 } self.mouse_score = [[11, 25, 50, 100000, 50, 25, 13], [11, 20, 25, 50, 25, 20, 13], [10, 15, 20, 20, 20, 15, 13], [8, 9, 9, 11, 12, 13, 13], - [8, 8, 8, 9, 11, 12, 12], - [8, 8, 8, 9, 11, 12, 11], - [8, 8, 8, 9, 10, 10, 10], - [8, 8, 8, 9, 9, 9, 9], + [8, 18, 18, 9, 18, 19, 12], + [8, 18, 19, 9, 18, 19, 11], + [8, 18, 18, 9, 18, 18, 10], + [8, 8, 8, 9, 9, 15, 9], [8, 8, 8, 0, 8, 8, 8]] self.eagle_score = [[11, 15, 50, 100000, 50, 15, 11], @@ -684,8 +784,8 @@ class Information: [12, 0, 0, 12, 0, 0, 12], [11, 0, 0, 11, 0, 0, 11], [10, 10, 10, 10, 10, 10, 10], - [8, 8, 8, 8, 8, 8, 8], - [8, 8, 8, 0, 8, 8, 8]] + [8, 8, 8, 0, 8, 8, 8], + [8, 8, 0, 0, 0, 8, 8]] self.fox_score = [[11, 15, 50, 100000, 50, 15, 11], [12, 12, 20, 50, 20, 15, 12], @@ -694,8 +794,8 @@ class Information: [12, 0, 0, 12, 0, 0, 12], [11, 0, 0, 11, 0, 0, 11], [10, 10, 10, 11, 10, 10, 10], - [8, 8, 9, 10, 9, 8, 8], - [8, 8, 10, 0, 10, 8, 8]] + [8, 8, 9, 100, 9, 8, 8], + [8, 8, 100, 0, 100, 8, 8]] self.wolf_score = [[11, 15, 50, 100000, 50, 15, 11], [12, 12, 20, 50, 20, 15, 12], @@ -708,8 +808,8 @@ class Information: [8, 8, 10, 0, 10, 8, 8]] self.leopard_score = [[11, 15, 50, 100000, 50, 15, 11], - [12, 12, 20, 50, 20, 15, 12], - [14, 15, 20, 20, 20, 14, 14], + [12, 12, 20, 50, 200, 15, 12], + [14, 15, 20, 20, 200, 14, 14], [13, 0, 0, 13, 0, 0, 13], [12, 0, 0, 12, 0, 0, 12], [11, 0, 0, 11, 0, 0, 11], @@ -719,21 +819,21 @@ class Information: self.lion_score = [[20, 40, 50, 100000, 50, 40, 20], [20, 25, 40, 50, 40, 25, 20], - [18, 30, 30, 20, 30, 30, 18], - [15, 0, 0, 15, 0, 0, 15], - [12, 0, 0, 15, 0, 0, 12], - [11, 0, 0, 15, 0, 0, 11], + [48, 30, 30, 47, 30, 30, 48], + [35, 0, 0, 37, 0, 0, 37], + [22, 0, 0, 27, 0, 0, 27], + [17, 0, 0, 17, 0, 0, 17], [14, 16, 16, 9, 16, 16, 14], [12, 12, 12, 12, 12, 12, 12], [5, 12, 12, 0, 12, 12, 5]] self.elephant_score = [[20, 40, 50, 100000, 50, 40, 20], - [20, 25, 40, 50, 40, 25, 20], - [18, 30, 30, 20, 30, 30, 18], - [15, 0, 0, 15, 0, 0, 15], - [12, 0, 0, 15, 0, 0, 12], - [11, 0, 0, 15, 0, 0, 11], - [14, 16, 16, 9, 16, 16, 14], + [20, 25, 40, 50, 400, 25, 20], + [18, 30, 30, 20, 300, 30, 18], + [18, 0, 0, 70, 0, 0, 19], + [17, 0, 0, 60, 0, 0, 20], + [15, 0, 0, 55, 0, 0, 22], + [14, 30, 40, 50, 40, 30, 20], [12, 12, 12, 12, 12, 12, 12], [5, 12, 12, 0, 12, 12, 5]] @@ -755,11 +855,12 @@ class Information: def Heuristic(Animals, pTurn): + global last_step score = 0 information = Information() piece_score = information.piece_score for animalId in range(1, len(Animals)): - x,y = Animals[animalId]['x'], Animals[animalId]['y'] + x, y = Animals[animalId]['x'], Animals[animalId]['y'] if 1 <= animalId <= 14: animalIdValue = information.position_score[animalId][x][y] @@ -773,19 +874,44 @@ def Heuristic(Animals, pTurn): score -= (animalIdValue + piece_score[animalId]) else: score += (animalIdValue + piece_score[animalId]) + return score -def depthLimitedSearch2(curAnimals, turn): # depth = 2 - Successors = getSuccessors(curAnimals, turn) - tempNextMove = [(Successor, inf) for Successor in Successors] +def depthLimitedSearch2(curAnimals, turn, ID): # depth = 2 + Successors = getSuccessors(curAnimals, turn, ID) + tempNextMove = [Successor for Successor in Successors] + + x = defendHome(curAnimals, ID, turn) + if x: + return x + else: + x = lionAttack(curAnimals, ID, turn) + if x: + return x + + else: + x = eagleToHome(curAnimals, ID, turn) + if x: + return x + + else: + x = killTheMouth(curAnimals, ID, turn) + if x: + return x + + else: + x = elephantAttack(curAnimals, ID, turn) + if x: + return x + nextMove = [] - if turn: + if turn == 1: turn2 = 0 - else: + elif turn == 0: turn2 = 1 for Move in tempNextMove: - Successors2 = getSuccessors(Move[0][0], turn2) + Successors2 = getSuccessors(Move[0], turn2, ID) nextMove2 = [(Successor2, Heuristic(Successor2[0], turn2)) for Successor2 in Successors2] max2 = -inf for action2 in nextMove2: @@ -798,13 +924,233 @@ def depthLimitedSearch2(curAnimals, turn): # depth = 2 if nextMove[i][1] < min1: min1 = nextMove[i][1] index = i - return nextMove[index][0][0][1] + return nextMove[index][0][1] + + +def findWayToDes(Animals, id, Des, ID): + ways = getMovement(id, Animals, ID) + distance = 17 + d_x = Des[1] + d_y = Des[2] + target_i = 0 + for index in range(len(ways)): + x = ways[index][1] + y = ways[index][2] + cal_dis = abs(x - d_x) + abs(y - d_y) + if cal_dis < distance: + print(cal_dis) + distance = cal_dis + target_i = index + return ways[target_i] + + +def killtheAnimal(Animals, ID, turn, killerID, victimID): + if turn == 0: + if ID[victimID] == 0: + return None + else: + if ID[killerID]: + d_x = Animals[victimID]['x'] + d_y = Animals[victimID]['y'] + Des = (killerID, d_x, d_y) + act = findWayToDes(Animals, killerID, Des, ID) + return act + else: + if ID[victimID] == 0: + return None + else: + if ID[killerID]: + d_x = Animals[victimID]['old_x'] + d_y = Animals[victimID]['old_y'] + Des = (killerID, d_x, d_y) + act = findWayToDes(Animals, killerID, Des, ID) + return act + +def getAnimalsPos(Animals, ID): + AnimalsPos = [] + + for index in range(15): + if index == 0: + AnimalsPos.append((-1, -1)) + continue + if ID[index]: + x = Animals[index]['x'] + y = Animals[index]['y'] + else: + x, y = -1, -1 + AnimalsPos.append((x,y)) + return AnimalsPos + +def defendHome(Animals, ID, turn): + MAP = getMAP(Animals, ID) + AnimalsPos = getAnimalsPos(Animals, ID) + # set the position and eat the trapped + if turn == 0: + # eat the trap + enemyID = [8,9,10,11,12,13,14] + if MAP[0][2] in enemyID: + if AnimalsPos[5]: + des = (5, 0 ,2) + return findWayToDes(Animals, 5, des, ID) + if MAP[1][3] in enemyID: + if AnimalsPos[4]: + des = (4, 1, 3) + return findWayToDes(Animals, 4, des, ID) + elif AnimalsPos[3]: + des = (3, 1, 3) + return findWayToDes(Animals, 3, des, ID) + if MAP[0][4] in enemyID: + if AnimalsPos[5]: + des = (5, 0, 4) + return findWayToDes(Animals, 5, des, ID) + + if ID[3]: + if AnimalsPos[3] != (0, 4): + des = (3, 0, 4) + return findWayToDes(Animals, 3, des, ID) + if ID[5]: + if AnimalsPos[5] != (1, 4): + des = (5, 1, 4) + return findWayToDes(Animals, 5, des, ID) + if ID[4]: + if AnimalsPos[4] != (1, 2): + des = (4, 1, 2) + return findWayToDes(Animals, 4, des, ID) + + if turn == 1: + # eat the trapped + enemyID = [1,2,3,4,5,6,7] + if MAP[8][4] in enemyID: + if AnimalsPos[12]: + des = (12, 8, 4) + return findWayToDes(Animals, 12, des, ID) + if MAP[7][3] in enemyID: + if AnimalsPos[11]: + des = (11, 7, 3) + return findWayToDes(Animals, 11, des, ID) + elif AnimalsPos[10]: + des = (12, 7, 3) + return findWayToDes(Animals, 12, des, ID) + if MAP[8][2] in enemyID: + if AnimalsPos[12]: + des = (11, 8, 2) + return findWayToDes(Animals, 12, des, ID) + + if ID[10]: + if AnimalsPos[10] != (8, 2): + des = (10, 8, 2) + return findWayToDes(Animals, 10, des, ID) + if ID[12]: + if AnimalsPos[12] != (7, 2): + des = (12, 7, 2) + return findWayToDes(Animals, 12, des, ID) + if ID[11]: + if AnimalsPos[11] != (7, 4): + des = (11, 7, 4) + return findWayToDes(Animals, 11, des, ID) + return None +def lionAttack(Animals, ID, turn): + AnimalsPos = getAnimalsPos(Animals, ID) + if turn == 0: + if ID[6]: + print('in') + print('AnimalsPos:', AnimalsPos[6]) + if AnimalsPos[6][0] == 8: + des = (6, 8, 3) + return findWayToDes(Animals, 6, des, ID) + + if AnimalsPos[6][1] == 0: + des = (6, 8, 0) + return findWayToDes(Animals, 6, des, ID) + + if AnimalsPos[6][1] != 0 and AnimalsPos[6][0] > 2: + des = (6, 3, 0) + return findWayToDes(Animals, 6, des, ID) + if AnimalsPos[6][0] == 2: + des = (6, 3, 3) + return findWayToDes(Animals, 6, des, ID) + else: + + return None + else: + if ID[13]: + if AnimalsPos[13][0] == 0: + des = (13, 0, 3) + return findWayToDes(Animals, 13, des, ID) + + if AnimalsPos[13][1] == 6: + des = (13, 0, 6) + return findWayToDes(Animals, 13, des, ID) + + if AnimalsPos[13][1] != 6: + des = (13, 5, 6) + return findWayToDes(Animals, 13, des, ID) + + if AnimalsPos[13][0] == 6: + des = (13, 5, 3) + return findWayToDes(Animals, 13, des, ID) + else: + return None +def elephantAttack(Animals, ID, turn): + AnimalsPos = getAnimalsPos(Animals, ID) + if turn == 0: + if ID[7]: + if AnimalsPos[7][1] == 3: + des = (7, 8, 3) + return findWayToDes(Animals, 7, des, ID) + + if AnimalsPos[7][1] != 3: + des = (7, 3, 3) + return findWayToDes(Animals, 7, des, ID) + else: + return None + else: + if ID[14]: + if AnimalsPos[14][1] == 3: + des = (14, 0, 3) + return findWayToDes(Animals, 14, des, ID) + + if AnimalsPos[14][1] != 3: + des = (14, 5, 3) + return findWayToDes(Animals, 14, des, ID) + else: + return None + +def eagleToHome(Animals, ID, turn): + if turn == 0: + if ID[2]: + des = [2, 8, 3] + return findWayToDes(Animals, 2, des, ID) + else: + if ID[9]: + des = [9, 0, 3] + return findWayToDes(Animals, 9, des, ID) + return None +def killTheMouth(Animals, ID, turn): + AnimalsPos = getAnimalsPos(Animals, ID) + pool = [(3,1),(4,1),(5,1),(3,2),(4,2),(5,2),(3,4),(4,4),(5,4),(3,5),(4,5),(5,5)] + if turn == 0 and ID[2] and ID[8]: + if AnimalsPos[8] in pool: + return None + x = killtheAnimal(curAnimals, ID, turn, 2, 8) + if x: + return x + if turn == 1 and ID[9] and ID[1]: + if AnimalsPos[1] in pool: + return None + x = killtheAnimal(Animals, ID, turn, 9, 1) + if x: + return x + return None def main(): - axis = [(0, 0), (2, 6), (1, 1), (1, 5), (2, 2), (2, 4), (2, 3), (2, 0), (6, 0), (7, 5), (7, 1), (6, 4), (6, 2), + axis = [(0, 0), (2, 6), (1, 3), (1, 5), (2, 2), (2, 4), (2, 3), (2, 0), (6, 0), (7, 5), (7, 1), (6, 4), (6, 2), (6, 3), (6, 6)] Axis = s.Chessmen_axis(axis) Animals = Axis.axis - print(depthLimitedSearch2(Animals, 0)) + ID = [1 for i in range(20)] + print(depthLimitedSearch2(Animals, 0, ID)) + x, y, z = depthLimitedSearch2(Animals, 0, ID) + if __name__ == '__main__': main() diff --git a/src/__pycache__/Client_connection.cpython-38.pyc b/src/__pycache__/Client_connection.cpython-38.pyc index 05df422..d7275da 100644 Binary files a/src/__pycache__/Client_connection.cpython-38.pyc and b/src/__pycache__/Client_connection.cpython-38.pyc differ diff --git a/src/__pycache__/Client_connection.cpython-39.pyc b/src/__pycache__/Client_connection.cpython-39.pyc index 82bbde3..dfae994 100644 Binary files a/src/__pycache__/Client_connection.cpython-39.pyc and b/src/__pycache__/Client_connection.cpython-39.pyc differ diff --git a/src/__pycache__/init.cpython-38.pyc b/src/__pycache__/init.cpython-38.pyc index 4cbfb6a..1e638c0 100644 Binary files a/src/__pycache__/init.cpython-38.pyc and b/src/__pycache__/init.cpython-38.pyc differ diff --git a/src/__pycache__/socket_client.cpython-38.pyc b/src/__pycache__/socket_client.cpython-38.pyc index 1753250..abf292a 100644 Binary files a/src/__pycache__/socket_client.cpython-38.pyc and b/src/__pycache__/socket_client.cpython-38.pyc differ diff --git a/src/__pycache__/start_game.cpython-38.pyc b/src/__pycache__/start_game.cpython-38.pyc index 3ab0c59..a07e1a8 100644 Binary files a/src/__pycache__/start_game.cpython-38.pyc and b/src/__pycache__/start_game.cpython-38.pyc differ diff --git a/src/main.py b/src/main.py index 6a7cd5d..8332f5e 100644 --- a/src/main.py +++ b/src/main.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,11 +1741,11 @@ 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 + id = (id + 7) % 14 if id == 0: id = 14 player.game_id = game_id @@ -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,350 +1946,380 @@ 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) if counterpart_id == 1: @@ -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: - id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side) # TODO:AI algorithm - #print((id,x,y)) + elif demo == 2 and turn == player.side: + id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side, ID) # TODO:AI algorithm + 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)] diff --git a/src/main_an.py b/src/main_an.py index 6a7cd5d..8997f61 100644 --- a/src/main_an.py +++ b/src/main_an.py @@ -2300,8 +2300,8 @@ def main(): turn = (1 - turn) player.invalid = 0 elif demo == 2 and turn == player.side: - id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side) # TODO:AI algorithm - #print((id,x,y)) + id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side, ID) # TODO:AI algorithm + print((id,x,y)) if id == 1: if 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0