AI版完成

develop
huangjielun 3 years ago
parent e9e8bf0402
commit fbe4e48e06

@ -4,15 +4,21 @@ import pygame
import heapq import heapq
import socket_client as s import socket_client as s
import init import init
import random
inf = 99999999 inf = 99999999
MAP1 = init.clac_MAP1() 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 id == 8:
if MAP[x][y] == 18: if MAP[x][y] == 18:
return 0 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 MAP[x][y] == 7:
if MAP1[old_x][old_y] != 20: if MAP1[old_x][old_y] != 20:
return 1 return 1
@ -23,7 +29,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
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 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 MAP[x][y] == 7:
if MAP1[old_x][old_y] != 20: if MAP1[old_x][old_y] != 20:
return 1 return 1
@ -37,9 +45,11 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
else: else:
return 0 return 0
elif id == 9: 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<MAP[x][y]<=14): 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 < MAP[x][y] <= 14):
return 0 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] == 16 or (MAP1[x][y] == 17 and 1<=MAP[x][y]<=7) or 1<=MAP[x][y]<=2): if x == old_x 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 y > old_y: if y > old_y:
for i in range(old_y + 1, 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):
@ -68,7 +78,8 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
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 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: if x > old_x:
for i in range(old_x + 1, 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):
@ -100,7 +111,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
else: else:
return 0 return 0
elif id == 10: 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 1 <= MAP[x][y] <= 3:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -117,7 +130,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
return 0 return 0
if (MAP[x][y] == 20): if (MAP[x][y] == 20):
return 0 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 1 <= MAP[x][y] <= 4:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -128,7 +143,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
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 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 1 <= MAP[x][y] <= 4:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -146,7 +163,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
return 0 return 0
if (MAP[x][y] == 20): if (MAP[x][y] == 20):
return 0 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 1 <= MAP[x][y] <= 5:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -157,7 +176,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
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 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 1 <= MAP[x][y] <= 5:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -175,7 +196,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
return 0 return 0
if MAP[x][y] == 20: if MAP[x][y] == 20:
return 0 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 1 <= MAP[x][y] <= 6:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -186,7 +209,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
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 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 1 <= MAP[x][y] <= 6:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -197,7 +222,8 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
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 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: if y > old_y:
for i in range(old_y + 1, y): for i in range(old_y + 1, y):
if MAP[x][i] != 20 and MAP[x][i] != 8: if MAP[x][i] != 20 and MAP[x][i] != 8:
@ -226,7 +252,8 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
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 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: if x > old_x:
for i in range(old_x + 1, x): for i in range(old_x + 1, x):
if MAP[i][y] != 20 and MAP[i][y] != 1: if MAP[i][y] != 20 and MAP[i][y] != 1:
@ -262,7 +289,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
return 0 return 0
if (MAP[x][y] == 20): if (MAP[x][y] == 20):
return 0 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 2 <= MAP[x][y] <= 7:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -273,7 +302,9 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
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 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 2 <= MAP[x][y] <= 7:
if MAP[x][y] == 1: if MAP[x][y] == 1:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -287,12 +318,14 @@ def left_move(old_x,old_y,x,y,id,MAP,MAP1):
else: else:
return 0 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 id == 1:
if MAP[x][y] == 16: if MAP[x][y] == 16:
return 0 return 0
if abs(x - old_x) == 1 and old_y == y and ( 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: if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20:
return 0 return 0
if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: 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
return 1 return 1
elif old_x == x and abs(y - old_y) == 1 and ( 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: if MAP[x][y] == 14 and MAP1[old_x][old_y] == 20:
return 0 return 0
if MAP[x][y] == 14 and MAP1[old_x][old_y] != 20: 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: else:
return 0 return 0
elif id == 2: 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 return 0
if x == old_x and ( 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: if y > old_y:
for i in range(old_y + 1, 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): 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):
@ -349,7 +385,8 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1):
return 1 return 1
return 1 return 1
elif y == old_y and ( 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: if x > old_x:
for i in range(old_x + 1, 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):
@ -381,7 +418,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1):
else: else:
return 0 return 0
elif id == 3: 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 8 <= MAP[x][y] <= 10:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -398,7 +437,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1):
return 0 return 0
if (MAP[x][y] == 20): if (MAP[x][y] == 20):
return 0 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 8 <= MAP[x][y] <= 11:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: 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: if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14:
return 1 return 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 8 <= MAP[x][y] <= 11:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -427,7 +470,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1):
return 0 return 0
if (MAP[x][y] == 20): if (MAP[x][y] == 20):
return 0 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 8 <= MAP[x][y] <= 12:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: 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: if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14:
return 1 return 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): 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 8 <= MAP[x][y] <= 12:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -456,7 +503,9 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1):
return 0 return 0
if MAP[x][y] == 20: if MAP[x][y] == 20:
return 0 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 8 <= MAP[x][y] <= 13:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: 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: if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14:
return 1 return 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 8 <= MAP[x][y] <= 13:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: 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: if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14:
return 1 return 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: if y > old_y:
for i in range(old_y + 1, y): for i in range(old_y + 1, y):
if MAP[x][i] != 20 and MAP[x][i] != 1: 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: if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14:
return 1 return 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: if x > old_x:
for i in range(old_x + 1, x): for i in range(old_x + 1, x):
if MAP[i][y] != 20 and MAP[i][y] != 1: 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 return 0
if (MAP[x][y] == 20): if (MAP[x][y] == 20):
return 0 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 9 <= MAP[x][y] <= 14:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: 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: if MAP1[x][y] == 15 and 8 <= MAP[x][y] <= 14:
return 1 return 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 9 <= MAP[x][y] <= 14:
if MAP[x][y] == 8: if MAP[x][y] == 8:
if MAP1[x][y] != 20: if MAP1[x][y] != 20:
@ -568,9 +625,51 @@ def right_move(old_x,old_y,x,y,id,MAP,MAP1):
else: else:
return 0 return 0
def getMAP(Animals):
def getMAP(Animals, ID):
copyMAP = [[0 for i in range(7)] for j in range(9)] 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)): for animalId in range(1, len(Animals)):
if ID[animalId]:
x, y = Animals[animalId]['x'], Animals[animalId]['y'] x, y = Animals[animalId]['x'], Animals[animalId]['y']
copyMAP[x][y] = animalId copyMAP[x][y] = animalId
return copyMAP return copyMAP
@ -608,46 +707,47 @@ class PriorityQueue:
self.push(item, priority) self.push(item, priority)
def getMovement(Id, Animals): def getMovement(Id, Animals, ID):
MAP = getMAP(Animals) MAP = getMAP(Animals, ID)
Movements = [] 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 x in range(len(MAP)):
for y in range(len(MAP[0])): for y in range(len(MAP[0])):
if 1 <= Id <= 7: if 1 <= Id <= 7:
if right_move(o_x, o_y, x, y, Id, MAP, MAP1): 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) Movements.append(move)
else: elif 8 <= Id <= 14:
if left_move(o_x, o_y, x, y, Id, MAP, MAP1): 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) Movements.append(move)
return Movements return Movements
def getSuccessors(Animals, turn: int): def getSuccessors(Animals, turn: int, ID):
Successors = [] Successors = []
Actions = [] Actions = []
if turn == 0: if turn == 0:
# 1 ~ 7 # 1 ~ 7
for Id in range(1, 8): for Id in range(1, 8):
Move = getMovement(Id, Animals) if ID[Id]:
Move = getMovement(Id, Animals,ID)
for oneStep in Move: for oneStep in Move:
Actions.append(oneStep) Actions.append(oneStep)
else: else:
# 8 ~ 14 # 8 ~ 14
for Id in range(8, 15): for Id in range(8, 15):
Move = getMovement(Id, Animals) if ID[Id]:
Move = getMovement(Id, Animals,ID)
for oneStep in Move: for oneStep in Move:
Actions.append(oneStep) Actions.append(oneStep)
# update the map # update the map
for action in Actions: 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) t_Animals = copy.deepcopy(Animals)
x = Animals[Id]['old_x'] + dx x = n_x
y = Animals[Id]['old_y'] + dy y = n_y
t_Animals[Id]['x'] = x t_Animals[Id]['x'] = x
t_Animals[Id]['y'] = y t_Animals[Id]['y'] = y
target = (Id, x, y) target = (Id, x, y)
@ -659,22 +759,22 @@ def getSuccessors(Animals, turn: int):
class Information: class Information:
def __init__(self): def __init__(self):
self.piece_score = {1: 100, 8: 100, self.piece_score = {1: 40, 8: 40,
2: 70, 9: 70, 2: 50, 9: 50,
3: 60, 10: 60, 3: 60, 10: 60,
4: 80, 11: 80, 4: 80, 11: 80,
5: 90, 12: 90, 5: 90, 12: 90,
6: 120, 13: 120, 6: 150, 13: 150,
7: 120, 14: 120 7: 120, 14: 120
} }
self.mouse_score = [[11, 25, 50, 100000, 50, 25, 13], self.mouse_score = [[11, 25, 50, 100000, 50, 25, 13],
[11, 20, 25, 50, 25, 20, 13], [11, 20, 25, 50, 25, 20, 13],
[10, 15, 20, 20, 20, 15, 13], [10, 15, 20, 20, 20, 15, 13],
[8, 9, 9, 11, 12, 13, 13], [8, 9, 9, 11, 12, 13, 13],
[8, 8, 8, 9, 11, 12, 12], [8, 18, 18, 9, 18, 19, 12],
[8, 8, 8, 9, 11, 12, 11], [8, 18, 19, 9, 18, 19, 11],
[8, 8, 8, 9, 10, 10, 10], [8, 18, 18, 9, 18, 18, 10],
[8, 8, 8, 9, 9, 9, 9], [8, 8, 8, 9, 9, 15, 9],
[8, 8, 8, 0, 8, 8, 8]] [8, 8, 8, 0, 8, 8, 8]]
self.eagle_score = [[11, 15, 50, 100000, 50, 15, 11], self.eagle_score = [[11, 15, 50, 100000, 50, 15, 11],
@ -684,8 +784,8 @@ class Information:
[12, 0, 0, 12, 0, 0, 12], [12, 0, 0, 12, 0, 0, 12],
[11, 0, 0, 11, 0, 0, 11], [11, 0, 0, 11, 0, 0, 11],
[10, 10, 10, 10, 10, 10, 10], [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], self.fox_score = [[11, 15, 50, 100000, 50, 15, 11],
[12, 12, 20, 50, 20, 15, 12], [12, 12, 20, 50, 20, 15, 12],
@ -694,8 +794,8 @@ class Information:
[12, 0, 0, 12, 0, 0, 12], [12, 0, 0, 12, 0, 0, 12],
[11, 0, 0, 11, 0, 0, 11], [11, 0, 0, 11, 0, 0, 11],
[10, 10, 10, 11, 10, 10, 10], [10, 10, 10, 11, 10, 10, 10],
[8, 8, 9, 10, 9, 8, 8], [8, 8, 9, 100, 9, 8, 8],
[8, 8, 10, 0, 10, 8, 8]] [8, 8, 100, 0, 100, 8, 8]]
self.wolf_score = [[11, 15, 50, 100000, 50, 15, 11], self.wolf_score = [[11, 15, 50, 100000, 50, 15, 11],
[12, 12, 20, 50, 20, 15, 12], [12, 12, 20, 50, 20, 15, 12],
@ -708,8 +808,8 @@ class Information:
[8, 8, 10, 0, 10, 8, 8]] [8, 8, 10, 0, 10, 8, 8]]
self.leopard_score = [[11, 15, 50, 100000, 50, 15, 11], self.leopard_score = [[11, 15, 50, 100000, 50, 15, 11],
[12, 12, 20, 50, 20, 15, 12], [12, 12, 20, 50, 200, 15, 12],
[14, 15, 20, 20, 20, 14, 14], [14, 15, 20, 20, 200, 14, 14],
[13, 0, 0, 13, 0, 0, 13], [13, 0, 0, 13, 0, 0, 13],
[12, 0, 0, 12, 0, 0, 12], [12, 0, 0, 12, 0, 0, 12],
[11, 0, 0, 11, 0, 0, 11], [11, 0, 0, 11, 0, 0, 11],
@ -719,21 +819,21 @@ class Information:
self.lion_score = [[20, 40, 50, 100000, 50, 40, 20], self.lion_score = [[20, 40, 50, 100000, 50, 40, 20],
[20, 25, 40, 50, 40, 25, 20], [20, 25, 40, 50, 40, 25, 20],
[18, 30, 30, 20, 30, 30, 18], [48, 30, 30, 47, 30, 30, 48],
[15, 0, 0, 15, 0, 0, 15], [35, 0, 0, 37, 0, 0, 37],
[12, 0, 0, 15, 0, 0, 12], [22, 0, 0, 27, 0, 0, 27],
[11, 0, 0, 15, 0, 0, 11], [17, 0, 0, 17, 0, 0, 17],
[14, 16, 16, 9, 16, 16, 14], [14, 16, 16, 9, 16, 16, 14],
[12, 12, 12, 12, 12, 12, 12], [12, 12, 12, 12, 12, 12, 12],
[5, 12, 12, 0, 12, 12, 5]] [5, 12, 12, 0, 12, 12, 5]]
self.elephant_score = [[20, 40, 50, 100000, 50, 40, 20], self.elephant_score = [[20, 40, 50, 100000, 50, 40, 20],
[20, 25, 40, 50, 40, 25, 20], [20, 25, 40, 50, 400, 25, 20],
[18, 30, 30, 20, 30, 30, 18], [18, 30, 30, 20, 300, 30, 18],
[15, 0, 0, 15, 0, 0, 15], [18, 0, 0, 70, 0, 0, 19],
[12, 0, 0, 15, 0, 0, 12], [17, 0, 0, 60, 0, 0, 20],
[11, 0, 0, 15, 0, 0, 11], [15, 0, 0, 55, 0, 0, 22],
[14, 16, 16, 9, 16, 16, 14], [14, 30, 40, 50, 40, 30, 20],
[12, 12, 12, 12, 12, 12, 12], [12, 12, 12, 12, 12, 12, 12],
[5, 12, 12, 0, 12, 12, 5]] [5, 12, 12, 0, 12, 12, 5]]
@ -755,6 +855,7 @@ class Information:
def Heuristic(Animals, pTurn): def Heuristic(Animals, pTurn):
global last_step
score = 0 score = 0
information = Information() information = Information()
piece_score = information.piece_score piece_score = information.piece_score
@ -773,19 +874,44 @@ def Heuristic(Animals, pTurn):
score -= (animalIdValue + piece_score[animalId]) score -= (animalIdValue + piece_score[animalId])
else: else:
score += (animalIdValue + piece_score[animalId]) score += (animalIdValue + piece_score[animalId])
return score return score
def depthLimitedSearch2(curAnimals, turn): # depth = 2 def depthLimitedSearch2(curAnimals, turn, ID): # depth = 2
Successors = getSuccessors(curAnimals, turn) Successors = getSuccessors(curAnimals, turn, ID)
tempNextMove = [(Successor, inf) for Successor in Successors] 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 = [] nextMove = []
if turn: if turn == 1:
turn2 = 0 turn2 = 0
else: elif turn == 0:
turn2 = 1 turn2 = 1
for Move in tempNextMove: 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] nextMove2 = [(Successor2, Heuristic(Successor2[0], turn2)) for Successor2 in Successors2]
max2 = -inf max2 = -inf
for action2 in nextMove2: for action2 in nextMove2:
@ -798,13 +924,233 @@ def depthLimitedSearch2(curAnimals, turn): # depth = 2
if nextMove[i][1] < min1: if nextMove[i][1] < min1:
min1 = nextMove[i][1] min1 = nextMove[i][1]
index = i 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(): 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)] (6, 3), (6, 6)]
Axis = s.Chessmen_axis(axis) Axis = s.Chessmen_axis(axis)
Animals = 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__': if __name__ == '__main__':
main() main()

File diff suppressed because it is too large Load Diff

@ -2300,8 +2300,8 @@ def main():
turn = (1 - turn) turn = (1 - turn)
player.invalid = 0 player.invalid = 0
elif demo == 2 and turn == player.side: elif demo == 2 and turn == player.side:
id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side) # TODO:AI algorithm id, x, y = DLS.depthLimitedSearch2(Axis.axis, player.side, ID) # TODO:AI algorithm
#print((id,x,y)) print((id,x,y))
if id == 1: if id == 1:
if 8 <= MAP[x][y] <= 14: if 8 <= MAP[x][y] <= 14:
ID[MAP[x][y]] = 0 ID[MAP[x][y]] = 0

Loading…
Cancel
Save