diff --git a/server/server.py b/server/server.py index 4bf8c30..6e1d251 100644 --- a/server/server.py +++ b/server/server.py @@ -185,7 +185,7 @@ def timer_thread(): send_msg_to(client1, msg) del playing_ones[game_id] else: - client.time -= 1 + client.time -= 1 client.total -= 1 mutex_playing.release() diff --git a/src/DLS.py b/src/DLS.py index e2ad0df..406ac7c 100644 --- a/src/DLS.py +++ b/src/DLS.py @@ -3,12 +3,571 @@ from typing import List, Tuple import pygame import heapq import socket_client as s -from main import right_move, left_move import init inf = 99999999 MAP1 = init.clac_MAP1() +def 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 MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + return 1 + else: + return 0 + if MAP[x][y] == 1: + return 1 + 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): + if MAP[x][y] == 7: + if MAP1[old_x][old_y] != 20: + return 1 + else: + return 0 + if MAP[x][y] == 1: + return 1 + if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7: + return 1 + return 1 + 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): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + 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): + return 0 + if 1 <= MAP[x][y] <= 2: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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] != 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: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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 1 <= MAP[x][y] <= 3: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + 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 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if 1 <= MAP[x][y] <= 4: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + elif id == 12: + 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]<=5): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if 1 <= MAP[x][y] <= 5: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + 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 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if y > old_y: + 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: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if x > old_x: + 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: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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 : + return 0 + if 1 <= MAP[x][y] <= 6: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else: + return 0 + elif id == 14: + 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 2<=MAP[x][y]<=7): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if 2 <= MAP[x][y] <= 7: + if MAP[x][y] == 1: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 17 and 1<=MAP[x][y]<=7: + return 1 + return 1 + else : + return 0 + +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): + 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: + return 1 + if MAP[x][y] == 8: + return 1 + 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] == 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: + return 1 + if MAP[x][y] == 8: + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + 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): + 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 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): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + 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): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + 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): + 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): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + 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): + return 0 + if 8 <= MAP[x][y] <= 9: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + 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 8 <= MAP[x][y] <= 10: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + return 0 + elif id == 4: + 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] <= 11): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if 8 <= MAP[x][y] <= 11: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 5: + 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] <= 12): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if 8 <= MAP[x][y] <= 12: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + 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 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if 8 <= MAP[x][y] <= 13: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if y > old_y: + 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: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + 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: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if x > old_x: + 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: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + 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: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + elif id == 7: + 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 9 <=MAP[x][y] <= 14): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + 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): + if 9 <= MAP[x][y] <= 14: + if MAP[x][y] == 8: + if MAP1[x][y] != 20: + return 1 + else: + return 0 + return 1 + if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14: + return 1 + return 1 + else: + return 0 + def getMAP(Animals): copyMAP = [[0 for i in range(7)] for j in range(9)] for animalId in range(1, len(Animals)): diff --git a/src/__pycache__/main.cpython-39.pyc b/src/__pycache__/main.cpython-39.pyc deleted file mode 100644 index bcca857..0000000 Binary files a/src/__pycache__/main.cpython-39.pyc and /dev/null differ diff --git a/src/__pycache__/start_game.cpython-39.pyc b/src/__pycache__/start_game.cpython-39.pyc index bd85082..6782e4f 100644 Binary files a/src/__pycache__/start_game.cpython-39.pyc and b/src/__pycache__/start_game.cpython-39.pyc differ diff --git a/src/main.py b/src/main.py index 3f0037d..7d4faa6 100644 --- a/src/main.py +++ b/src/main.py @@ -26,7 +26,7 @@ WIDTH , HEIGHT = 1200 , 800 ID = [1 for i in range(20)] FPS = 60 WIN = pygame.display.set_mode((WIDTH,HEIGHT)) -pygame.display.set_caption("Jungle") +#pygame.display.set_caption("Jungle") SPACE = pygame.transform.scale(pygame.image.load('images/map.png'),(WIDTH,HEIGHT)) CHESSSIZE_X=120 CHESSSIZE_Y=100 #棋子大小 @@ -130,6 +130,7 @@ def draw_right_animals(r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox) def draw_window(l_elephant,l_eagle,l_wolf,l_lion,l_leopard,l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_mouse,r_fox,id, x, y, status, MAP, MAP1,turn): + pygame.display.set_caption("Jungle") WIN.blit(SPACE,(0,0)) if turn == 1: WIN.blit(left_turn,init.tran(8,3)) @@ -1749,6 +1750,7 @@ def main(): run = False if demo == 1 or demo == 2: C.start_new_thread(server_thread, (client,Address)) + print(turn,player.side) Right_win = player.Right_win Left_win = player.Left_win for event in pygame.event.get(): @@ -1820,7 +1822,7 @@ def main(): status = 0 if(demo == 1): C.move(client,player.game_id,1 - player.side,(id+7) % 14,old_x,old_y,x,y) - turn = 1 + turn = 1 - turn else: status = 0 elif (id == 2 and turn == 0 and status == 1 and demo == 0) or (id == 2 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1834,7 +1836,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 3 and turn == 0 and status == 1 and demo == 0) or (id == 3 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1848,7 +1850,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 4 and turn == 0 and status == 1 and demo == 0) or (id == 4 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1862,7 +1864,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 5 and turn == 0 and status == 1 and demo == 0) or (id == 5 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1876,7 +1878,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 6 and turn == 0 and status == 1 and demo == 0) or (id == 6 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1890,7 +1892,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 7 and turn == 0 and status == 1 and demo == 0) or (id == 7 and demo == 1 and status == 1 and turn == player.side and turn == 0): @@ -1904,7 +1906,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 1 + turn = 1 - turn else : status = 0 elif (id == 8 and turn == 1 and status == 2 and demo == 0) or (id == 8 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1918,7 +1920,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 9 and turn == 1 and status == 2 and demo == 0) or (id == 9 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1932,7 +1934,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 10 and turn == 1 and status == 2 and demo == 0) or (id == 10 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1946,7 +1948,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 11 and turn == 1 and status == 2 and demo == 0) or (id == 11 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1960,7 +1962,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 12 and turn == 1 and status == 2 and demo == 0) or (id == 12 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1974,7 +1976,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 13 and turn == 1 and status == 2 and demo == 0) or (id == 13 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -1988,7 +1990,7 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (id == 14 and turn == 1 and status == 2 and demo == 0) or (id == 14 and turn == player.side and status == 2 and demo == 1 and turn == 1): @@ -2002,16 +2004,17 @@ def main(): status = 0 if (demo == 1): C.move(client, player.game_id, 1 - player.side, (id+7) % 14, old_x, old_y, x, y) - turn = 0 + turn = 1 - turn else : status = 0 elif (demo == 1 or demo == 2) and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1: + print("in") counterpart_id = player.id counterpart_old_x , counterpart_old_y = Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y'] counterpart_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y'] - if counterpart_id == 1 and turn == 0: + if counterpart_id == 1 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2019,9 +2022,9 @@ def main(): l_mouse.x , l_mouse.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 2 and turn == 0: + elif counterpart_id == 2 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2029,9 +2032,9 @@ def main(): l_eagle.x , l_eagle.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 3 and turn == 0: + elif counterpart_id == 3 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: r_animals -= 1 ID[MAP[counterpart_x][counterpart_y]] = 0 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2039,9 +2042,9 @@ def main(): l_fox.x , l_fox.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 4 and turn == 0: + elif counterpart_id == 4 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2049,9 +2052,9 @@ def main(): l_wolf.x , l_wolf.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 5 and turn == 0: + elif counterpart_id == 5 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2059,9 +2062,9 @@ def main(): l_leopard.x , l_leopard.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 6 and turn == 0: + elif counterpart_id == 6 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2069,9 +2072,9 @@ def main(): l_lion.x , l_lion.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 7 and turn == 0: + elif counterpart_id == 7 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 8 <= MAP[counterpart_x][counterpart_y] <= 14: ID[MAP[counterpart_x][counterpart_y]] = 0 r_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2079,9 +2082,9 @@ def main(): l_elephant.x , l_elephant.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 8 and turn == 1: + elif counterpart_id == 8 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2089,9 +2092,9 @@ def main(): r_mouse.x , r_mouse.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 9 and turn == 1: + elif counterpart_id == 9 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2099,9 +2102,9 @@ def main(): r_eagle.x , r_eagle.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 10 and turn == 1: + elif counterpart_id == 10 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2109,9 +2112,9 @@ def main(): r_fox.x , r_fox.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 11 and turn == 1: + elif counterpart_id == 11 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2119,9 +2122,9 @@ def main(): r_wolf.x , r_wolf.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 12 and turn == 1: + elif counterpart_id == 12 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2129,9 +2132,9 @@ def main(): r_leopard.x , r_leopard.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 13 and turn == 1: + elif counterpart_id == 13 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2139,9 +2142,9 @@ def main(): r_lion.x , r_lion.y = init.tran(counterpart_x,counterpart_y) turn = (1-turn) player.invalid = 0 - elif counterpart_id == 14 and turn == 1: + elif counterpart_id == 14 : if MAP[counterpart_x][counterpart_y] != counterpart_id: - if 1 <= MAP[counterpart_x][counterpart_y] <= 14: + if 1 <= MAP[counterpart_x][counterpart_y] <= 7: ID[MAP[counterpart_x][counterpart_y]] = 0 l_animals -= 1 MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] @@ -2149,8 +2152,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 player.id and turn == player.id: - id,x,y = DLS.depthLimitedSearch2(Axis.axis,player.id)#TODO:AI algorithm + elif demo == 2 and player.side and turn == player.side: + id,x,y = DLS.depthLimitedSearch2(Axis.axis,player.side)#TODO:AI algorithm + print(id,x,y) if id == 1: if 8 <= MAP[x][y] <= 14: ID[MAP[x][y]] = 0 @@ -2347,6 +2351,7 @@ def main(): Axis.axis[id]["y"] = y r_elephant.x, r_elephant.y = init.tran(x, y) turn = (1 - turn) + C.move(client, player.game_id, 1 - player.side, (id + 7) % 14, old_x, old_y, x, y) draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, diff --git a/src/start_game.py b/src/start_game.py index cd8b055..5325d13 100644 --- a/src/start_game.py +++ b/src/start_game.py @@ -59,11 +59,13 @@ def starting_screen(): play_button = Button('Single Play!', WHITE, None, 350, centered_x=True) Oplay_button = Button('Online Play!', WHITE, None, 400, centered_x=True) - exit_button = Button('Exit!', WHITE, None, 450, centered_x=True) + AIplay_button = Button('AI Play!', WHITE, None, 450, centered_x=True) + exit_button = Button('Exit!', WHITE, None, 500, centered_x=True) play_button.display() Oplay_button.display() exit_button.display() + AIplay_button.display() pygame.display.update() @@ -79,13 +81,19 @@ def starting_screen(): else: Oplay_button = Button('Online Play!', WHITE, None, 400, centered_x=True) + if AIplay_button.check_click(pygame.mouse.get_pos()): + AIplay_button = Button('AI Play!', RED, None, 450, centered_x=True) + else: + AIplay_button = Button('AI Play!', WHITE, None, 450, centered_x=True) + if exit_button.check_click(pygame.mouse.get_pos()): - exit_button = Button('Exit!', RED, None, 450, centered_x=True) + exit_button = Button('Exit!', RED, None, 500, centered_x=True) else: - exit_button = Button('Exit!', WHITE, None, 450, centered_x=True) + exit_button = Button('Exit!', WHITE, None, 500, centered_x=True) play_button.display() Oplay_button.display() + AIplay_button.display() exit_button.display() pygame.display.update() @@ -98,6 +106,8 @@ def starting_screen(): return 1 if Oplay_button.check_click(pygame.mouse.get_pos()): return 2 + if AIplay_button.check_click(pygame.mouse.get_pos()): + return 3 if exit_button.check_click(pygame.mouse.get_pos()): return 0