|
|
|
@ -200,12 +200,16 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1):
|
|
|
|
|
if 1 <= MAP[x][y] <= 6:
|
|
|
|
|
if MAP[x][y] == 1:
|
|
|
|
|
if MAP1[x][y] != 20:
|
|
|
|
|
#print("laoshu")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
#print("other animals")
|
|
|
|
|
return 1
|
|
|
|
|
if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7:
|
|
|
|
|
#print("xianjing")
|
|
|
|
|
return 1
|
|
|
|
|
#print("grass")
|
|
|
|
|
return 1
|
|
|
|
|
elif old_x == x and abs(y - old_y) == 1 and (
|
|
|
|
|
MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (
|
|
|
|
@ -213,12 +217,16 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1):
|
|
|
|
|
if 1 <= MAP[x][y] <= 6:
|
|
|
|
|
if MAP[x][y] == 1:
|
|
|
|
|
if MAP1[x][y] != 20:
|
|
|
|
|
#print("laoshu2")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
#print("other aniamls 2")
|
|
|
|
|
return 1
|
|
|
|
|
if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7:
|
|
|
|
|
#print("xianjing2")
|
|
|
|
|
return 1
|
|
|
|
|
#print("grass2")
|
|
|
|
|
return 1
|
|
|
|
|
elif old_x == x and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (
|
|
|
|
|
MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6):
|
|
|
|
@ -229,26 +237,34 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1):
|
|
|
|
|
if 1 <= MAP[x][y] <= 6:
|
|
|
|
|
if MAP[x][y] == 1:
|
|
|
|
|
if MAP1[x][y] != 20:
|
|
|
|
|
#print("laoshu3")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
#print("other animals 3")
|
|
|
|
|
return 1
|
|
|
|
|
if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7:
|
|
|
|
|
#print("xianjing3")
|
|
|
|
|
return 1
|
|
|
|
|
#print("grass 3")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
for i in range(y + 1, old_y):
|
|
|
|
|
if MAP[x][i] != 20 and MAP[x][i] != 1:
|
|
|
|
|
if MAP[x][i] != 20 :
|
|
|
|
|
return 0
|
|
|
|
|
if 1 <= MAP[x][y] <= 6:
|
|
|
|
|
if MAP[x][y] == 1:
|
|
|
|
|
if MAP1[x][y] != 20:
|
|
|
|
|
#print("laoshu4")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
#print("other animals 4")
|
|
|
|
|
return 1
|
|
|
|
|
if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7:
|
|
|
|
|
#print("xianjing4")
|
|
|
|
|
return 1
|
|
|
|
|
#print("grass 4")
|
|
|
|
|
return 1
|
|
|
|
|
elif old_y == y and (MAP[x][y] == 0 or MAP[x][y] == 17 or MAP[x][y] == 15 or MAP[x][y] == 16 or (
|
|
|
|
|
MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7) or 1 <= MAP[x][y] <= 6):
|
|
|
|
@ -259,26 +275,36 @@ def left_move(old_x, old_y, x, y, id, MAP, MAP1):
|
|
|
|
|
if 1 <= MAP[x][y] <= 6:
|
|
|
|
|
if MAP[x][y] == 1:
|
|
|
|
|
if MAP1[x][y] != 20:
|
|
|
|
|
#print("laoshu5")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
#print("other animals 5")
|
|
|
|
|
return 1
|
|
|
|
|
if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7:
|
|
|
|
|
#print("xianjing5")
|
|
|
|
|
return 1
|
|
|
|
|
#print("grass 5")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
for i in range(x + 1, old_x):
|
|
|
|
|
if MAP[i][y] != 20 and MAP[i][y] != 1:
|
|
|
|
|
if MAP[i][y] != 20 :
|
|
|
|
|
#if x == 1 and y == 6:
|
|
|
|
|
#print("why?")
|
|
|
|
|
return 0
|
|
|
|
|
if 1 <= MAP[x][y] <= 6:
|
|
|
|
|
if MAP[x][y] == 1:
|
|
|
|
|
if MAP1[x][y] != 20:
|
|
|
|
|
#print("laoshu6")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
#print("other animals 6")
|
|
|
|
|
return 1
|
|
|
|
|
if MAP1[x][y] == 17 and 1 <= MAP[x][y] <= 7:
|
|
|
|
|
#print("xianjing6")
|
|
|
|
|
return 1
|
|
|
|
|
#print("grass 6")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
@ -716,9 +742,13 @@ def getMovement(Id, Animals, ID):
|
|
|
|
|
move = (Id, x, y)
|
|
|
|
|
Movements.append(move)
|
|
|
|
|
elif 8 <= Id <= 14:
|
|
|
|
|
if Id == 13 and o_x == 3 and o_y == 6:
|
|
|
|
|
print("---------------")
|
|
|
|
|
if left_move(o_x, o_y, x, y, Id, MAP, MAP1):
|
|
|
|
|
move = (Id, x, y)
|
|
|
|
|
Movements.append(move)
|
|
|
|
|
if Id == 13 and o_x == 3 and o_y == 6:
|
|
|
|
|
print("---------------")
|
|
|
|
|
return Movements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -936,7 +966,7 @@ def findWayToDes(Animals, id, Des, ID):
|
|
|
|
|
y = ways[index][2]
|
|
|
|
|
cal_dis = abs(x - d_x) + abs(y - d_y)
|
|
|
|
|
if cal_dis < distance:
|
|
|
|
|
print(cal_dis)
|
|
|
|
|
#print(cal_dis)
|
|
|
|
|
distance = cal_dis
|
|
|
|
|
target_i = index
|
|
|
|
|
return ways[target_i]
|
|
|
|
@ -986,21 +1016,28 @@ def defendHome(Animals, ID, turn):
|
|
|
|
|
AnimalsPos = getAnimalsPos(Animals, ID)
|
|
|
|
|
# set the position and eat the trapped
|
|
|
|
|
if turn == 0:
|
|
|
|
|
for id in range(1,8):
|
|
|
|
|
for i in range(0,9):
|
|
|
|
|
for j in range(0,7):
|
|
|
|
|
if ID[id] and right_move(AnimalsPos[id][0],AnimalsPos[id][1],i,j,id,MAP,MAP1) :
|
|
|
|
|
if 8<=MAP[i][j]<=14:
|
|
|
|
|
des = (id,i,j)
|
|
|
|
|
return findWayToDes(Animals, id, des, ID)
|
|
|
|
|
# eat the trap
|
|
|
|
|
enemyID = [8, 9, 10, 11, 12, 13, 14]
|
|
|
|
|
if MAP[0][2] in enemyID:
|
|
|
|
|
if AnimalsPos[5]:
|
|
|
|
|
if AnimalsPos[5] != (-1,-1):
|
|
|
|
|
des = (5, 0, 2)
|
|
|
|
|
return findWayToDes(Animals, 5, des, ID)
|
|
|
|
|
if MAP[1][3] in enemyID:
|
|
|
|
|
if AnimalsPos[4]:
|
|
|
|
|
if AnimalsPos[4] != (-1,-1):
|
|
|
|
|
des = (4, 1, 3)
|
|
|
|
|
return findWayToDes(Animals, 4, des, ID)
|
|
|
|
|
elif AnimalsPos[3]:
|
|
|
|
|
elif AnimalsPos[3] != (-1,-1):
|
|
|
|
|
des = (3, 1, 3)
|
|
|
|
|
return findWayToDes(Animals, 3, des, ID)
|
|
|
|
|
if MAP[0][4] in enemyID:
|
|
|
|
|
if AnimalsPos[5]:
|
|
|
|
|
if AnimalsPos[5] != (-1,-1):
|
|
|
|
|
des = (5, 0, 4)
|
|
|
|
|
return findWayToDes(Animals, 5, des, ID)
|
|
|
|
|
if MAP[0][5] in enemyID:
|
|
|
|
@ -1022,20 +1059,27 @@ def defendHome(Animals, ID, turn):
|
|
|
|
|
|
|
|
|
|
if turn == 1:
|
|
|
|
|
# eat the trapped
|
|
|
|
|
for id in range(8,15):
|
|
|
|
|
for i in range(0,9):
|
|
|
|
|
for j in range(0,7):
|
|
|
|
|
if ID[id] and left_move(AnimalsPos[id][0],AnimalsPos[id][1],i,j,id,MAP,MAP1):
|
|
|
|
|
if 1<=MAP[i][j]<=7:
|
|
|
|
|
des = (id,i,j)
|
|
|
|
|
return findWayToDes(Animals, id, des, ID)
|
|
|
|
|
enemyID = [1, 2, 3, 4, 5, 6, 7]
|
|
|
|
|
if MAP[8][4] in enemyID:
|
|
|
|
|
if AnimalsPos[12]:
|
|
|
|
|
if AnimalsPos[12] != (-1,-1):
|
|
|
|
|
des = (12, 8, 4)
|
|
|
|
|
return findWayToDes(Animals, 12, des, ID)
|
|
|
|
|
if MAP[7][3] in enemyID:
|
|
|
|
|
if AnimalsPos[11]:
|
|
|
|
|
if AnimalsPos[11] != (-1,-1):
|
|
|
|
|
des = (11, 7, 3)
|
|
|
|
|
return findWayToDes(Animals, 11, des, ID)
|
|
|
|
|
elif AnimalsPos[10]:
|
|
|
|
|
elif AnimalsPos[10] != (-1,-1):
|
|
|
|
|
des = (12, 7, 3)
|
|
|
|
|
return findWayToDes(Animals, 12, des, ID)
|
|
|
|
|
if MAP[8][2] in enemyID:
|
|
|
|
|
if AnimalsPos[12]:
|
|
|
|
|
if AnimalsPos[12] != (-1,-1):
|
|
|
|
|
des = (11, 8, 2)
|
|
|
|
|
return findWayToDes(Animals, 12, des, ID)
|
|
|
|
|
if MAP[8][1] in enemyID:
|
|
|
|
@ -1059,10 +1103,17 @@ def defendHome(Animals, ID, turn):
|
|
|
|
|
|
|
|
|
|
def lionAttack(Animals, ID, turn):
|
|
|
|
|
AnimalsPos = getAnimalsPos(Animals, ID)
|
|
|
|
|
MAP = getMAP(Animals, ID)
|
|
|
|
|
if turn == 0:
|
|
|
|
|
if ID[6]:
|
|
|
|
|
print('in')
|
|
|
|
|
#print('in')
|
|
|
|
|
print('AnimalsPos:', AnimalsPos[6])
|
|
|
|
|
for i in range(0,9):
|
|
|
|
|
for j in range(0,7):
|
|
|
|
|
if right_move(AnimalsPos[6][0],AnimalsPos[6][1],i,j,6,MAP,MAP1):
|
|
|
|
|
if 8<=MAP[i][j]<=14:
|
|
|
|
|
des = (6,i,j)
|
|
|
|
|
return findWayToDes(Animals, 6, des, ID)
|
|
|
|
|
if AnimalsPos[6][0] == 8:
|
|
|
|
|
des = (6, 8, 3)
|
|
|
|
|
return findWayToDes(Animals, 6, des, ID)
|
|
|
|
@ -1078,10 +1129,15 @@ def lionAttack(Animals, ID, turn):
|
|
|
|
|
des = (6, 3, 3)
|
|
|
|
|
return findWayToDes(Animals, 6, des, ID)
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
else:
|
|
|
|
|
if ID[13]:
|
|
|
|
|
for i in range(0,9):
|
|
|
|
|
for j in range(0,7):
|
|
|
|
|
if left_move(AnimalsPos[13][0],AnimalsPos[13][1],i,j,13,MAP,MAP1):
|
|
|
|
|
if 1<=MAP[i][j]<=7:
|
|
|
|
|
des = (6,i,j)
|
|
|
|
|
return findWayToDes(Animals, 13, des, ID)
|
|
|
|
|
if AnimalsPos[13][0] == 0:
|
|
|
|
|
des = (13, 0, 3)
|
|
|
|
|
return findWayToDes(Animals, 13, des, ID)
|
|
|
|
@ -1103,8 +1159,15 @@ def lionAttack(Animals, ID, turn):
|
|
|
|
|
|
|
|
|
|
def elephantAttack(Animals, ID, turn):
|
|
|
|
|
AnimalsPos = getAnimalsPos(Animals, ID)
|
|
|
|
|
MAP = getMAP(Animals, ID)
|
|
|
|
|
if turn == 0:
|
|
|
|
|
if ID[7]:
|
|
|
|
|
for i in range(0,9):
|
|
|
|
|
for j in range(0,7):
|
|
|
|
|
if right_move(AnimalsPos[7][0],AnimalsPos[7][1],i,j,7,MAP,MAP1):
|
|
|
|
|
if 8<=MAP[i][j]<=14:
|
|
|
|
|
des = (7,i,j)
|
|
|
|
|
return findWayToDes(Animals, 7, des, ID)
|
|
|
|
|
if AnimalsPos[7][1] == 3:
|
|
|
|
|
des = (7, 8, 3)
|
|
|
|
|
return findWayToDes(Animals, 7, des, ID)
|
|
|
|
@ -1116,6 +1179,12 @@ def elephantAttack(Animals, ID, turn):
|
|
|
|
|
return None
|
|
|
|
|
else:
|
|
|
|
|
if ID[14]:
|
|
|
|
|
for i in range(0,9):
|
|
|
|
|
for j in range(0,7):
|
|
|
|
|
if right_move(AnimalsPos[14][0],AnimalsPos[14][1],i,j,14,MAP,MAP1):
|
|
|
|
|
if 1<=MAP[i][j]<=7:
|
|
|
|
|
des = (14,i,j)
|
|
|
|
|
return findWayToDes(Animals, 14, des, ID)
|
|
|
|
|
if AnimalsPos[14][1] == 3:
|
|
|
|
|
des = (14, 0, 3)
|
|
|
|
|
return findWayToDes(Animals, 14, des, ID)
|
|
|
|
@ -1128,12 +1197,26 @@ def elephantAttack(Animals, ID, turn):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def eagleToHome(Animals, ID, turn):
|
|
|
|
|
AnimalsPos = getAnimalsPos(Animals, ID)
|
|
|
|
|
MAP = getMAP(Animals, ID)
|
|
|
|
|
if turn == 0:
|
|
|
|
|
if ID[2]:
|
|
|
|
|
for i in range(0,9):
|
|
|
|
|
for j in range(0,7):
|
|
|
|
|
if right_move(AnimalsPos[2][0],AnimalsPos[2][1],i,j,2,MAP,MAP1):
|
|
|
|
|
if 8<=MAP[i][j]<=14:
|
|
|
|
|
des = (2,i,j)
|
|
|
|
|
return findWayToDes(Animals, 2, des, ID)
|
|
|
|
|
des = [2, 8, 3]
|
|
|
|
|
return findWayToDes(Animals, 2, des, ID)
|
|
|
|
|
else:
|
|
|
|
|
if ID[9]:
|
|
|
|
|
for i in range(0,9):
|
|
|
|
|
for j in range(0,7):
|
|
|
|
|
if left_move(AnimalsPos[9][0],AnimalsPos[9][1],i,j,9,MAP,MAP1):
|
|
|
|
|
if 1<=MAP[i][j]<=7:
|
|
|
|
|
des = (9,i,j)
|
|
|
|
|
return findWayToDes(Animals, 9, des, ID)
|
|
|
|
|
des = [9, 0, 3]
|
|
|
|
|
return findWayToDes(Animals, 9, des, ID)
|
|
|
|
|
return None
|
|
|
|
@ -1163,7 +1246,7 @@ def main():
|
|
|
|
|
Axis = s.Chessmen_axis(axis)
|
|
|
|
|
Animals = Axis.axis
|
|
|
|
|
ID = [1 for i in range(20)]
|
|
|
|
|
print(depthLimitedSearch2(Animals, 0, ID))
|
|
|
|
|
#print(depthLimitedSearch2(Animals, 0, ID))
|
|
|
|
|
x, y, z = depthLimitedSearch2(Animals, 0, ID)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|