develop
huangjielun 3 years ago
parent c9cfd6321d
commit b237cffa60

@ -0,0 +1,18 @@
使用demo来标识是否为网络版通过开始函数返回
增加Player类成员有status_2,game_id, side,MAP(记录各个棋子的坐标-以id为索引要保持双方的坐标一致)counterpart_name,think_time,total_time用以记录双方的信息
定义了一个函数server_thread用来监听服务器发送的数据
在移动的时候使用side与turn区分是哪一方移动用demo区分单机与网络单机版只以turn为条件demo = 0而网络版比较side与turn是否相同demo = 1
question如何知道客户端接受到了一个报文maybe不断比较Player类中的坐标与本地MAP中坐标是否相同不同则修改对面的棋子并翻转turn 或 在Player中加入一个变量去记录在客户端发送了报文己方已经下好棋后置0然后不断询问是否为1为1后停止并修改对方的棋子坐标
该移动规则还需要修改path函数以致可以得到正确的路径显示

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1 @@
main.py

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
</modules>
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

@ -0,0 +1,251 @@
import copy
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 getMAP(Animals):
copyMAP = [[0 for i in range(7)] for j in range(9)]
for animalId in range(1, len(Animals)):
x, y = Animals[animalId]['old_x'], Animals[animalId]['old_y']
copyMAP[x][y] = animalId
return copyMAP
class PriorityQueue:
def __init__(self):
self.heap = []
self.count = 0
def push(self, item, priority):
entry = (priority, self.count, item)
heapq.heappush(self.heap, entry)
self.count += 1
def pop(self):
(_, _, item) = heapq.heappop(self.heap)
return item
def isEmpty(self):
return len(self.heap) == 0
def update(self, item, priority):
for index, (p, c, i) in enumerate(self.heap):
if i == item:
if p <= priority:
break
del self.heap[index]
self.heap.append((priority, c, item))
heapq.heapify(self.heap)
break
else:
self.push(item, priority)
def getMovement(Id, Animals):
MAP = getMAP(Animals)
Movements = []
o_x, o_y = Animals[Id]['old_x'], Animals[Id]['old_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)
Movements.append(move)
else:
if left_move(o_x, o_y, x, y, Id, MAP, MAP1):
move = (Id, x - o_x, y - o_y)
Movements.append(move)
return Movements
def getSuccessors(Animals, turn: int):
Successors = []
Actions = []
if turn == 0:
# 1 ~ 7
for Id in range(1, 8):
Move = getMovement(Id, Animals)
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)
# update the map
for action in Actions:
Id, dx, dy = action[0], action[1], action[2]
t_Animals = copy.deepcopy(Animals)
x = Animals[Id]['old_x'] + dx
y = Animals[Id]['old_y'] + dy
t_Animals[Id]['x'] = x
t_Animals[Id]['y'] = y
target = (Id, x, y)
#print(t_Animals)
Successors.append((t_Animals, target))
# updateMAP()
return Successors
class Information:
def __init__(self):
self.piece_score = {1: 100, 8: 100,
2: 70, 9: 70,
3: 60, 10: 60,
4: 80, 11: 80,
5: 90, 12: 90,
6: 120, 13: 120,
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, 8, 8, 0, 8, 8, 8]]
self.eagle_score = [[11, 15, 50, 100000, 50, 15, 11],
[12, 12, 20, 50, 20, 15, 12],
[14, 15, 20, 20, 20, 14, 14],
[13, 0, 0, 13, 0, 0, 13],
[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]]
self.fox_score = [[11, 15, 50, 100000, 50, 15, 11],
[12, 12, 20, 50, 20, 15, 12],
[14, 15, 20, 20, 20, 14, 14],
[13, 0, 0, 13, 0, 0, 13],
[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]]
self.wolf_score = [[11, 15, 50, 100000, 50, 15, 11],
[12, 12, 20, 50, 20, 15, 12],
[14, 15, 20, 20, 20, 14, 14],
[13, 0, 0, 13, 0, 0, 13],
[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]]
self.leopard_score = [[11, 15, 50, 100000, 50, 15, 11],
[12, 12, 20, 50, 20, 15, 12],
[14, 15, 20, 20, 20, 14, 14],
[13, 0, 0, 13, 0, 0, 13],
[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]]
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],
[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],
[12, 12, 12, 12, 12, 12, 12],
[5, 12, 12, 0, 12, 12, 5]]
self.position_score = {1: self.mouse_score,
8: self.mouse_score[::-1],
2: self.eagle_score,
9: self.eagle_score[::-1],
3: self.fox_score,
10: self.fox_score[::-1],
4: self.wolf_score,
11: self.wolf_score[::-1],
5: self.leopard_score,
12: self.leopard_score[::-1],
6: self.lion_score,
13: self.lion_score[::-1],
7: self.elephant_score,
14: self.elephant_score[::-1]
}
def Heuristic(Animals, pTurn):
score = 0
information = Information()
piece_score = information.piece_score
for animalId in range(1, len(Animals)):
x,y = Animals[animalId]['x'], Animals[animalId]['y']
if 1 <= animalId <= 14:
animalIdValue = information.position_score[animalId][x][y]
if pTurn == 0:
if 1 <= animalId <= 7:
score += (animalIdValue + piece_score[animalId])
else:
score -= (animalIdValue + piece_score[animalId])
else:
if 1 <= animalId <= 7:
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]
nextMove = []
if turn:
turn2 = 0
else:
turn2 = 1
for Move in tempNextMove:
Successors2 = getSuccessors(Move[0][0], turn2)
nextMove2 = [(Successor2, Heuristic(Successor2[0], turn2)) for Successor2 in Successors2]
max2 = -inf
for action2 in nextMove2:
if action2[1] > max2:
max2 = action2[1]
nextMove.append((Move, max2))
min1 = inf
index = 0
for i in range(len(nextMove)):
if nextMove[i][1] < min1:
min1 = nextMove[i][1]
index = i
return nextMove[index][0][0][1]
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),
(6, 3), (6, 6)]
Axis = s.Chessmen_axis(axis)
Animals = Axis.axis
print(depthLimitedSearch2(Animals, 0))
if __name__ == '__main__':
main()

@ -11,7 +11,7 @@ import uuid
import time import time
from threading import Thread, Lock from threading import Thread, Lock
import socket_client as s import socket_client as s
import pygame_menu import DLS
if(sys.version[:1] == "3"): if(sys.version[:1] == "3"):
import queue as Queue import queue as Queue
@ -1721,31 +1721,31 @@ def main():
font = pygame.font.SysFont('kaiti',40) font = pygame.font.SysFont('kaiti',40)
status = id = old_x = old_y = x = y = 0 status = id = old_x = old_y = x = y = 0
turn = 1 turn = 1
if demo == 1: if (demo == 1 or demo == 2):
name = input("Please tell us your name:") name = input("Please tell us your name:")
player.name = name player.name = name
Left_win = player.Left_win Left_win = player.Left_win
Right_win = player.Right_win Right_win = player.Right_win
Address = (Config.SOCKET_HOST, Config.SOCKET_PORT) Address = (Config.SOCKET_HOST, Config.SOCKET_PORT)
if demo == 1: if (demo == 1 or demo == 2):
C.load_config() C.load_config()
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((Config.SOCKET_HOST, Config.SOCKET_PORT)) client.connect((Config.SOCKET_HOST, Config.SOCKET_PORT))
C.conn_to_server(client, name) C.conn_to_server(client, name)
while run: while run:
clock.tick(FPS) clock.tick(FPS)
if demo == 1 and exit == 1: if (demo == 1 or demo == 2) and exit == 1:
request = "quit" 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: if player.side == 0:
player.Right_win = Right_win = 1 player.Right_win = Right_win = 1
elif player.side == 1: elif player.side == 1:
player.Left_win = Left_win = 1 player.Left_win = Left_win = 1
if left_win(x, y, MAP, MAP1) or (demo == 1 and Left_win == 1): if left_win(x, y, MAP, MAP1) or ((demo == 1 or demo == 2) and Left_win == 1):
run = False run = False
if right_win(x, y, MAP, MAP1) or (demo == 1 and Right_win == 1): if right_win(x, y, MAP, MAP1) or ((demo == 1 or demo == 2) and Right_win == 1):
run = False run = False
if demo == 1: 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 Right_win = player.Right_win
Left_win = player.Left_win Left_win = player.Left_win
@ -2003,7 +2003,7 @@ def main():
turn = 0 turn = 0
else : else :
status = 0 status = 0
elif demo == 1 and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1: elif (demo == 1 or demo == 2) and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1:
counterpart_id = player.id 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'] counterpart_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y']
@ -2011,6 +2011,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
l_mouse.x , l_mouse.y = init.tran(counterpart_x,counterpart_y) l_mouse.x , l_mouse.y = init.tran(counterpart_x,counterpart_y)
@ -2020,6 +2021,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
l_eagle.x , l_eagle.y = init.tran(counterpart_x,counterpart_y) l_eagle.x , l_eagle.y = init.tran(counterpart_x,counterpart_y)
@ -2028,6 +2030,7 @@ def main():
elif counterpart_id == 3 and turn == 0: elif counterpart_id == 3 and turn == 0:
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
r_animals -= 1
ID[MAP[counterpart_x][counterpart_y]] = 0 ID[MAP[counterpart_x][counterpart_y]] = 0
MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y] MAP[counterpart_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
@ -2038,6 +2041,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
l_wolf.x , l_wolf.y = init.tran(counterpart_x,counterpart_y) l_wolf.x , l_wolf.y = init.tran(counterpart_x,counterpart_y)
@ -2047,6 +2051,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
l_leopard.x , l_leopard.y = init.tran(counterpart_x,counterpart_y) l_leopard.x , l_leopard.y = init.tran(counterpart_x,counterpart_y)
@ -2056,6 +2061,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
l_lion.x , l_lion.y = init.tran(counterpart_x,counterpart_y) l_lion.x , l_lion.y = init.tran(counterpart_x,counterpart_y)
@ -2065,6 +2071,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
l_elephant.x , l_elephant.y = init.tran(counterpart_x,counterpart_y) l_elephant.x , l_elephant.y = init.tran(counterpart_x,counterpart_y)
@ -2074,6 +2081,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
r_mouse.x , r_mouse.y = init.tran(counterpart_x,counterpart_y) r_mouse.x , r_mouse.y = init.tran(counterpart_x,counterpart_y)
@ -2083,6 +2091,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
r_eagle.x , r_eagle.y = init.tran(counterpart_x,counterpart_y) r_eagle.x , r_eagle.y = init.tran(counterpart_x,counterpart_y)
@ -2092,6 +2101,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
r_fox.x , r_fox.y = init.tran(counterpart_x,counterpart_y) r_fox.x , r_fox.y = init.tran(counterpart_x,counterpart_y)
@ -2101,6 +2111,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
r_wolf.x , r_wolf.y = init.tran(counterpart_x,counterpart_y) r_wolf.x , r_wolf.y = init.tran(counterpart_x,counterpart_y)
@ -2110,6 +2121,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
r_leopard.x , r_leopard.y = init.tran(counterpart_x,counterpart_y) r_leopard.x , r_leopard.y = init.tran(counterpart_x,counterpart_y)
@ -2119,6 +2131,7 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
r_lion.x , r_lion.y = init.tran(counterpart_x,counterpart_y) r_lion.x , r_lion.y = init.tran(counterpart_x,counterpart_y)
@ -2128,13 +2141,210 @@ def main():
if MAP[counterpart_x][counterpart_y] != counterpart_id: if MAP[counterpart_x][counterpart_y] != counterpart_id:
if 1 <= MAP[counterpart_x][counterpart_y] <= 14: if 1 <= MAP[counterpart_x][counterpart_y] <= 14:
ID[MAP[counterpart_x][counterpart_y]] = 0 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_old_x][counterpart_old_y] = MAP1[counterpart_old_x][counterpart_old_y]
MAP[counterpart_x][counterpart_y] = counterpart_id MAP[counterpart_x][counterpart_y] = counterpart_id
r_elephant.x , r_elephant.y = init.tran(counterpart_x,counterpart_y) r_elephant.x , r_elephant.y = init.tran(counterpart_x,counterpart_y)
turn = (1-turn) turn = (1-turn)
player.invalid = 0 player.invalid = 0
elif demo == 2: elif demo == 2 and player.id and turn == player.id:
pass id,x,y = DLS.depthLimitedSearch2(Axis.axis,player.id)#TODO:AI algorithm
if id == 1:
if 8 <= MAP[x][y] <= 14:
ID[MAP[x][y]] = 0
r_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
l_mouse.x, l_mouse.y = init.tran(x, y)
turn = (1 - turn)
elif id ==2:
if 8 <= MAP[x][y] <= 14:
ID[MAP[x][y]] = 0
r_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
l_eagle.x, l_eagle.y = init.tran(x, y)
turn = (1 - turn)
elif id ==3:
if 8 <= MAP[x][y] <= 14:
ID[MAP[x][y]] = 0
r_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
l_fox.x, l_fox.y = init.tran(x, y)
turn = (1 - turn)
elif id ==4:
if 8 <= MAP[x][y] <= 14:
ID[MAP[x][y]] = 0
r_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
l_wolf.x, l_wolf.y = init.tran(x, y)
turn = (1 - turn)
elif id ==5:
if 8 <= MAP[x][y] <= 14:
ID[MAP[x][y]] = 0
r_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
l_leopard.x, l_leopard.y = init.tran(x, y)
turn = (1 - turn)
elif id ==6:
if 8 <= MAP[x][y] <= 14:
ID[MAP[x][y]] = 0
r_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
l_lion.x, l_lion.y = init.tran(x, y)
turn = (1 - turn)
elif id ==7:
if 8 <= MAP[x][y] <= 14:
ID[MAP[x][y]] = 0
r_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
l_elephant.x, l_elephant.y = init.tran(x, y)
turn = (1 - turn)
elif id == 8:
if 1 <= MAP[x][y] <= 7:
ID[MAP[x][y]] = 0
l_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
r_mouse.x, r_mouse.y = init.tran(x, y)
turn = (1 - turn)
elif id == 9:
if 1 <= MAP[x][y] <= 7:
ID[MAP[x][y]] = 0
l_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
r_eagle.x, r_eagle.y = init.tran(x, y)
turn = (1 - turn)
elif id == 10:
if 1 <= MAP[x][y] <= 7:
ID[MAP[x][y]] = 0
l_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
r_fox.x, r_fox.y = init.tran(x, y)
turn = (1 - turn)
elif id == 11:
if 1 <= MAP[x][y] <= 7:
ID[MAP[x][y]] = 0
l_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
r_wolf.x, r_wolf.y = init.tran(x, y)
turn = (1 - turn)
elif id == 12:
if 1 <= MAP[x][y] <= 7:
ID[MAP[x][y]] = 0
l_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
r_leopard.x, r_leopard.y = init.tran(x, y)
turn = (1 - turn)
elif id == 13:
if 1 <= MAP[x][y] <= 7:
ID[MAP[x][y]] = 0
l_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
r_lion.x, r_lion.y = init.tran(x, y)
turn = (1 - turn)
elif id == 14:
if 1 <= MAP[x][y] <= 7:
ID[MAP[x][y]] = 0
l_animals -= 1
MAP[x][y] = id
old_x = Axis.axis[id]["x"]
old_y = Axis.axis[id]["y"]
MAP[old_x][old_y] = MAP1[old_x][old_y]
Axis.axis[id]["old_x"] = old_x
Axis.axis[id]["old_y"] = old_y
Axis.axis[id]["x"] = x
Axis.axis[id]["y"] = y
r_elephant.x, r_elephant.y = init.tran(x, y)
turn = (1 - turn)
draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion,

@ -22,6 +22,8 @@ class Chessmen_axis:
old_x, old_y = Axis[i] old_x, old_y = Axis[i]
self.axis[i]["old_x"] = old_x self.axis[i]["old_x"] = old_x
self.axis[i]["old_y"] = old_y self.axis[i]["old_y"] = old_y
self.axis[i]["x"] = old_x
self.axis[i]["y"] = old_y
def set_axix(self, id, old_x, old_y, x, y): def set_axix(self, id, old_x, old_y, x, y):
self.axis[id]["old_x"] = old_x self.axis[id]["old_x"] = old_x

Loading…
Cancel
Save