Compare commits

..

No commits in common. 'develop' and 'master' have entirely different histories.

3
.idea/.gitignore vendored

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

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

@ -1,8 +0,0 @@
<?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>

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

@ -1,7 +0,0 @@
<?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" />
<component name="PyPackaging">
<option name="earlyReleasesAsUpgrades" value="true" />
</component>
</project>

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

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

@ -1,3 +1,2 @@
# Jungle
主要功能在main.py函数中

Binary file not shown.

@ -1,18 +0,0 @@
使用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函数以致可以得到正确的路径显示

@ -1,5 +0,0 @@
SOCKET_HOST=127.0.0.1
SOCKET_PORT=50005
MAX_WAITING_TIME=600
MAX_THNIKING_TIME=30
MAX_TOTAL_TIME=1000

@ -1,268 +0,0 @@
# coding:utf-8
import socket
import sys
import json
import uuid
import time
from threading import Thread, Lock
if (sys.version[:1] == "3"):
import queue as Queue
from _thread import *
else:
import Queue
from thread import *
class Config:
SOCKET_HOST = '127.0.0.1' # Symbolic name meaning all available interfaces
SOCKET_PORT = 50005 # Arbitrary non-privileged port
MAX_WAITING_TIME = 180
MAX_THNIKING_TIME = 60
MAX_TOTAL_TIME = 600
class Client:
def __init__(self, conn, addr, name, side, time, total):
self.conn = conn
self.addr = addr
self.name = name
self.side = side
self.time = time
self.total = total
mutex = Lock()
mutex_playing = Lock()
playing_ones = {}
waiting_players = Queue.Queue()
# init queues
# for games in range(1, 10):
# waiting_players[games] = Queue.Queue()
def load_config():
with open('config.txt', 'r') as f:
for line in f.readlines():
line = line.strip()
if line.find('SOCKET_HOST=') >= 0:
Config.SOCKET_HOST = line[line.index('=') + 1:]
elif line.find('SOCKET_PORT=') >= 0:
Config.SOCKET_PORT = int(line[line.index('=') + 1:])
elif line.find('MAX_WAITING_TIME=') >= 0:
Config.MAX_WAITING_TIME = int(line[line.index('=') + 1:])
elif line.find('MAX_THNIKING_TIME=') >= 0:
Config.MAX_THNIKING_TIME = int(line[line.index('=') + 1:])
elif line.find('MAX_TOTAL_TIME=') >= 0:
Config.MAX_TOTAL_TIME = int(line[line.index('=') + 1:])
else:
pass
def get_counterpart_from(waiting_ones):
counterpart = None
mutex.acquire()
if not waiting_ones.empty():
counterpart = waiting_ones.get()
mutex.release()
return counterpart
def to_wait_in_queue(client, the_queue):
mutex.acquire()
the_queue.put(client)
mutex.release()
def remove_one_from_queue(the_queue):
mutex.acquire()
if (the_queue.qsize() == 1):
the_queue.get()
mutex.release()
def send_msg_to(client, msg):
packet = json.dumps(msg)
if (sys.version[:1] == "3"):
packet = packet.encode('utf-8')
# print(client.addr[0] + ":" + str(client.addr[1]) + "\t" + str(msg))
client.conn.send(packet)
def __start_match_between(client0, client1):
match_uuid = str(uuid.uuid4())
mutex_playing.acquire()
playing_ones[match_uuid] = (client0, client1)
mutex_playing.release()
client0.side = 0
client0.time = Config.MAX_THNIKING_TIME
client0.total = Config.MAX_TOTAL_TIME
client1.side = 1
client1.time = -1
client1.total = Config.MAX_TOTAL_TIME
msg0 = {
"status": 1,
"counterpart_name": client1.name,
"game_id": match_uuid,
"side": client0.side,
"think_time": Config.MAX_THNIKING_TIME,
"total_time": Config.MAX_TOTAL_TIME,
}
send_msg_to(client0, msg0)
msg1 = {
"status": 1,
"counterpart_name": client0.name,
"game_id": match_uuid,
"side": client1.side,
"think_time": Config.MAX_THNIKING_TIME,
"total_time": Config.MAX_TOTAL_TIME,
}
send_msg_to(client1, msg1)
def join_game_handler(msg, addr, conn):
new_client = Client(conn, addr, msg['name'], -1, -1, -1)
# game_type = msg["id"]
# the_queue = waiting_players[game_type]
counterpart = get_counterpart_from(waiting_players)
if not counterpart: # wait
to_wait_in_queue(new_client, waiting_players)
return
else:
# counterpart=get_counterpart_from(waiting_players[game_type])
__start_match_between(new_client, counterpart)
def quit_game_handler(msg):
match_uuid = msg['game_id']
if match_uuid is None:
remove_one_from_queue(waiting_players)
return
pairs = None
mutex_playing.acquire()
if (match_uuid in playing_ones):
pairs = playing_ones[match_uuid]
del playing_ones[match_uuid]
mutex_playing.release()
if pairs is not None:
if (pairs[0].side == msg['side']):
to_notify = pairs[1]
else:
to_notify = pairs[0]
msg = {
"status": 2, # exit
"game_id": match_uuid,
"side": msg['side'],
"request": msg['request'],
}
send_msg_to(to_notify, msg)
def timer_thread():
while True:
time.sleep(1)
mutex_playing.acquire()
for game_id in list(playing_ones.keys()):
(client0, client1) = playing_ones[game_id]
# print("%d - %d" % (client0.time, client1.time))
if (client0.time < 0):
client = client1
else:
client = client0
if (client.time == 0 or client.total == 0):
msg = {
"status": 3, # timeout exit
"game_id": game_id,
"side": client.side,
}
send_msg_to(client0, msg)
send_msg_to(client1, msg)
del playing_ones[game_id]
else:
client.time -= 1
client.total -= 1
mutex_playing.release()
def transfer_message(msg):
match_uuid = msg['game_id']
pairs = playing_ones[match_uuid]
if (pairs[0].side == msg['side']):
to_notify = pairs[1]
pairs[0].time = -1
else:
to_notify = pairs[0]
pairs[1].time = -1
to_notify.time = Config.MAX_THNIKING_TIME
send_msg_to(to_notify, msg)
def client_thread(conn, addr):
while True:
try:
data = conn.recv(1024)
if not data:
break
print(data)
data = json.loads(data)
if not 'type' in data:
transfer_message(data['msg'])
continue
if data['type'] == 0:
join_game_handler(data['msg'], addr, conn)
continue
elif data['type'] == 1:
transfer_message(data['msg'])
continue
elif data['type'] == 2:
quit_game_handler(data['msg'])
break
elif data['type'] == 3:
break
else:
# delivering message between the two clients
transfer_message(data['msg'])
continue
except:
break
# came out of loop
conn.close()
# print("conneection exit!")
def main():
load_config()
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print('Socket server created')
# try:
server.bind((Config.SOCKET_HOST, Config.SOCKET_PORT))
# except (socket.error, msg):
# print ('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
# sys.exit()
print('Socket bind complete')
server.listen(10)
print('Socket now listening')
# now keep talking with the client
start_new_thread(timer_thread, ())
while True:
# wait to accept a connection - blocking call
conn, addr = server.accept()
print('Connected with ' + addr[0] + ':' + str(addr[1]))
# start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function.
start_new_thread(client_thread, (conn, addr))
server.close()
if __name__ == '__main__':
main()

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

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

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

@ -1,4 +0,0 @@
<?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>

@ -1,8 +0,0 @@
<?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>

@ -1,8 +0,0 @@
<?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>

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

@ -1,176 +0,0 @@
# coding:utf-8
import socket
import sys
import json
import uuid
import time
from threading import Thread, Lock
if(sys.version[:1] == "3"):
import queue as Queue
from _thread import *
else:
import Queue
from _thread import *
class Config:
SOCKET_HOST = '127.0.0.1'#Symbolic name meaning all available interfaces
SOCKET_PORT = 50005#Arbitrary non-privileged port
MAX_WAITING_TIME = 180
MAX_THNIKING_TIME = 60
MAX_TOTAL_TIME = 600
def load_config():
with open('../server/config.txt', 'r') as f:
for line in f.readlines():
line = line.strip()
if line.find('SOCKET_HOST=') >= 0:
Config.SOCKET_HOST = line[line.index('=') + 1 : ]
elif line.find('SOCKET_PORT=') >= 0:
Config.SOCKET_PORT = int(line[line.index('=') + 1 : ])
elif line.find('MAX_WAITING_TIME=') >= 0:
Config.MAX_WAITING_TIME = int(line[line.index('=') + 1 : ])
elif line.find('MAX_THNIKING_TIME=') >= 0:
Config.MAX_THNIKING_TIME = int(line[line.index('=') + 1 : ])
elif line.find('MAX_TOTAL_TIME=') >= 0:
Config.MAX_TOTAL_TIME = int(line[line.index('=') + 1 : ])
else:
pass
def send_msg_to(conn, msg):
packet = json.dumps(msg)
if (sys.version[:1] == "3"):
packet = packet.encode('utf-8')
#print(client.addr[0] + ":" + str(client.addr[1]) + "\t" + str(msg))
conn.send(packet)
return
def conn_to_server(conn,name):
data = {
"type" : 0,
"msg" :
{
"name":name
}
}
send_msg_to(conn,data)
return
#TODO无法发送src与dst的坐标
def move(conn,game_id,side,id,old_x,old_y,x,y):
if id == 0:
id = 14
if side == 1:
id = id - 7
#print("side,id:",side,id)
data = {
"type" : 1,
"msg" :
{
"game_id" : game_id,
"side":side,
"chessman": (id - 1),
"src":
{
"x":old_x,
"y":old_y
},
"dst":
{
"x":x,
"y":y
}
}
}
send_msg_to(conn,data)
return
def exit_game(conn,request,game_id,side):
data ={
"type":2,
"msg":{
"request":request,
"game_id":game_id,
"side":side
}
}
send_msg_to(conn,data)
return
def ack_exit_game(conn,side):#退出游戏或超时
data = {
"type" : 3,
"side":side
}
send_msg_to(conn,data)
return
def handle_move(msg):
num = msg["chessman"]
game_id = msg["game_id"]
side = msg["side"]
src= msg["src"]
old_x,old_y = src["x"],src["y"]
dst = msg["dst"]
x,y = dst["x"],dst["y"]
status_2 = -1
return status_2,game_id,side,old_x,old_y,x,y,num
def handle_new_player(msg):
status_2 = msg["status"]
counterpart_name = msg["counterpart_name"]
game_id = msg["game_id"]
side = msg["side"]
think_time = msg["think_time"]
total_time = msg["total_time"]
return status_2,counterpart_name,game_id,side,think_time,total_time
def handle_exit_game(msg):
status_2 = msg["status"]
request = msg["request"]
game_id = msg["game_id"]
side = msg["side"]
return status_2,request,game_id,side
def handle_time_over(msg):
status_2 = msg["status"]
game_id = msg["game_id"]
side = msg["side"]
return status_2,game_id, side
def server_thread(conn,addr):
conn_to_server(conn,"an")
while True:
msg = conn.recv(1024)
if not msg:
break
print(msg)
msg = json.loads(msg)
if not 'status' in msg:
handle_move(msg)
continue
if msg["status"] == 1:
handle_new_player(msg)
continue
elif msg["status"] == 2:
handle_exit_game(msg)
break
elif msg["status"] == 3:
handle_time_over(msg)
break
conn.close()
Address = (Config.SOCKET_HOST,Config.SOCKET_PORT)
def main():
load_config()
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((Config.SOCKET_HOST, Config.SOCKET_PORT))
while True:
start_new_thread(server_thread,(client,Address))
#print("can pass")
client.close()
if __name__ == '__main__':
main()

File diff suppressed because it is too large Load Diff

@ -1,41 +0,0 @@
import main
import math
'''
// 负极大值算法
int negamax(GameState S, int depth, int alpha, int beta) {
// 游戏是否结束 || 探索的递归深度是否到边界
if ( gameover(S) || depth == 0 ) {
return evaluation(S);
}
// 依据预估(历史, 经验)对可行步, 进行排序
sort (candidate list);
// 遍历每一个候选步
foreach ( move in candidate list ) {
S' = makemove(S);
value = -negamax(S', depth - 1, -beta, -alpha);
unmakemove(S')
if ( value > alpha ) {
// alpha + beta剪枝点
if ( value >= beta ) {
return beta;
}
alpha = value;
}
}
return alpha;
}
'''
def h(State):
return 0
def negaMax(State,depth,alpha,beta,moveList):
if depth == 0:
return h(State)
moveList=sorted(moveList)
for move in moveList:
newState = State#update state
value = -negaMax(newState,depth - 1,-beta,-alpha)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

@ -1,212 +0,0 @@
import pygame
import os
pygame.init()
pygame.font.init()
pygame.mixer.init()
WIDTH , HEIGHT = 1200 , 800
CHESSSIZE_X=120
CHESSSIZE_Y=100 #棋子大小
#animals rect
l_elephant = pygame.Rect(281,10,CHESSSIZE_Y,CHESSSIZE_Y)
l_eagle = pygame.Rect(157,120,CHESSSIZE_Y,CHESSSIZE_Y)
l_wolf = pygame.Rect(284,229,CHESSSIZE_Y,CHESSSIZE_Y)
l_lion = pygame.Rect(282,343,CHESSSIZE_Y,CHESSSIZE_Y)
l_leopard = pygame.Rect(285,450,CHESSSIZE_Y,CHESSSIZE_Y)
l_mouse = pygame.Rect(285,665,CHESSSIZE_Y,CHESSSIZE_Y)
l_fox = pygame.Rect(157,557,CHESSSIZE_Y,CHESSSIZE_Y)
r_elephant = pygame.Rect(795,673,CHESSSIZE_Y,CHESSSIZE_Y)
r_eagle = pygame.Rect(925,570,CHESSSIZE_Y,CHESSSIZE_Y)
r_wolf = pygame.Rect(803,458,CHESSSIZE_Y,CHESSSIZE_Y)
r_lion = pygame.Rect(802,347,CHESSSIZE_Y,CHESSSIZE_Y)
r_leopard = pygame.Rect(796,232,CHESSSIZE_Y,CHESSSIZE_Y)
r_fox = pygame.Rect(920,123,CHESSSIZE_Y,CHESSSIZE_Y)
r_mouse = pygame.Rect(793,16,CHESSSIZE_Y,CHESSSIZE_Y)
#############################################
def calc(x,y):#将像素转化为抽象坐标
new_x = int((x + 10) / WIDTH * 9)
new_y = int((y + 10) / HEIGHT * 7)
return (new_x,new_y)
def tran(x,y):#将抽象坐标转化为像素
new_x = int(x / 9 * WIDTH)
new_y = int(y / 7 * HEIGHT)
return (new_x,new_y)
def calc_map():
MAP = [[0 for i in range(7)] for i in range(9)]
x,y=calc(87,278)
MAP[x][y] = 15
x,y = calc(211,378)
MAP[x][y] = 15
x,y = calc(85,496)
MAP[x][y] = 15
x,y = calc(81,388)
MAP[x][y] = 16
x,y = calc(1105,282)
MAP[x][y] = 17
x,y = calc(976,381)
MAP[x][y] = 17
x,y = calc(1114,497)
MAP[x][y] = 17
x,y = calc(1102,379)
MAP[x][y] = 18
x,y = calc(468,185)
MAP[x][y] = 20
x,y = calc(597,180)
MAP[x][y] = 20
x,y = calc(714,184)
MAP[x][y] = 20
x,y = calc(472,273)
MAP[x][y] = 20
x,y = calc(595,275)
MAP[x][y] = 20
x,y = calc(705,275)
MAP[x][y] = 20
x,y = calc(479,505)
MAP[x][y] = 20
x,y = calc(591,504)
MAP[x][y] = 20
x,y = calc(718,514)
MAP[x][y] = 20
x,y = calc(467,598)
MAP[x][y] = 20
x,y = calc(593,604)
MAP[x][y] = 20
x,y = calc(719,604)
MAP[x][y] = 20
# 将动物的像素坐标转化为格子x-y轴坐标
r_elephant_x = int((r_elephant.x + 20) / WIDTH * 9)
r_elephant_y = int((r_elephant.y + 20) / HEIGHT * 7)
MAP[r_elephant_x][r_elephant_y] = 14
r_eagle_x = int((r_eagle.x + 20) / WIDTH * 9)
r_eagle_y = int((r_eagle.y + 20) / HEIGHT * 7)
MAP[r_eagle_x][r_eagle_y] = 9
r_wolf_x = int((r_wolf.x) / WIDTH * 9)
r_wolf_y = int(r_wolf.y / HEIGHT * 7)
MAP[r_wolf_x][r_wolf_y] = 11
r_lion_x = int((r_lion.x) / WIDTH * 9)
r_lion_y = int(r_lion.y / HEIGHT * 7)
MAP[r_lion_x][r_lion_y] = 13
r_leopard_x = int((r_leopard.x + 20) / WIDTH * 9)
r_leopard_y = int(r_leopard.y / HEIGHT * 7)
MAP[r_leopard_x][r_leopard_y] = 12
r_mouse_x = int((r_mouse.x + 20) / WIDTH * 9)
r_mouse_y = int(r_mouse.y / HEIGHT * 7)
MAP[r_mouse_x][r_mouse_y] = 8
r_fox_x = int((r_fox.x + 20) / WIDTH * 9)
r_fox_y = int((r_fox.y) / HEIGHT * 7)
MAP[r_fox_x][r_fox_y] = 10
l_elephant_x = int(l_elephant.x / WIDTH * 9)
l_elephant_y = int(l_elephant.y / HEIGHT * 7)
MAP[l_elephant_x][l_elephant_y] = 7
l_eagle_x = int(l_eagle.x / WIDTH * 9)
l_eagle_y = int(l_eagle.y / HEIGHT * 7)
MAP[l_eagle_x][l_eagle_y] = 2
l_wolf_x = int(l_wolf.x / WIDTH * 9)
l_wolf_y = int(l_wolf.y / HEIGHT * 7)
MAP[l_wolf_x][l_wolf_y] = 4
l_lion_x = int(l_lion.x / WIDTH * 9)
l_lion_y = int(l_lion.y / HEIGHT * 7)
MAP[l_lion_x][l_lion_y] = 6
l_leopard_x = int(l_leopard.x / WIDTH * 9)
l_leopard_y = int((l_leopard.y + 20) / HEIGHT * 7)
MAP[l_leopard_x][l_leopard_y] = 5
l_mouse_x = int(l_mouse.x / WIDTH * 9)
l_mouse_y = int((l_mouse.y + 30) / HEIGHT * 7)
MAP[l_mouse_x][l_mouse_y] = 1
l_fox_x = int(l_fox.x / WIDTH * 9)
l_fox_y = int((l_fox.y + 20) / HEIGHT * 7)
MAP[l_fox_x][l_fox_y] = 3
#############################
##print(MAP1)
return MAP
def clac_MAP1():
MAP = [[0 for i in range(7)] for i in range(9)]
x, y = calc(87, 278)
MAP[x][y] = 15
x, y = calc(211, 378)
MAP[x][y] = 15
x, y = calc(85, 496)
MAP[x][y] = 15
x, y = calc(81, 388)
MAP[x][y] = 16
x, y = calc(1105, 282)
MAP[x][y] = 17
x, y = calc(976, 381)
MAP[x][y] = 17
x, y = calc(1114, 497)
MAP[x][y] = 17
x, y = calc(1102, 379)
MAP[x][y] = 18
x, y = calc(468, 185)
MAP[x][y] = 20
x, y = calc(597, 180)
MAP[x][y] = 20
x, y = calc(714, 184)
MAP[x][y] = 20
x, y = calc(472, 273)
MAP[x][y] = 20
x, y = calc(595, 275)
MAP[x][y] = 20
x, y = calc(705, 275)
MAP[x][y] = 20
x, y = calc(479, 505)
MAP[x][y] = 20
x, y = calc(591, 504)
MAP[x][y] = 20
x, y = calc(718, 514)
MAP[x][y] = 20
x, y = calc(467, 598)
MAP[x][y] = 20
x, y = calc(593, 604)
MAP[x][y] = 20
x, y = calc(719, 604)
MAP[x][y] = 20
return MAP
def refresh():
l_elephant = pygame.Rect(281, 10, CHESSSIZE_Y, CHESSSIZE_Y)
l_eagle = pygame.Rect(157, 120, CHESSSIZE_Y, CHESSSIZE_Y)
l_wolf = pygame.Rect(284, 229, CHESSSIZE_Y, CHESSSIZE_Y)
l_lion = pygame.Rect(282, 343, CHESSSIZE_Y, CHESSSIZE_Y)
l_leopard = pygame.Rect(285, 450, CHESSSIZE_Y, CHESSSIZE_Y)
l_mouse = pygame.Rect(285, 665, CHESSSIZE_Y, CHESSSIZE_Y)
l_fox = pygame.Rect(157, 557, CHESSSIZE_Y, CHESSSIZE_Y)
r_elephant = pygame.Rect(795, 673, CHESSSIZE_Y, CHESSSIZE_Y)
r_eagle = pygame.Rect(925, 570, CHESSSIZE_Y, CHESSSIZE_Y)
r_wolf = pygame.Rect(803, 458, CHESSSIZE_Y, CHESSSIZE_Y)
r_lion = pygame.Rect(802, 347, CHESSSIZE_Y, CHESSSIZE_Y)
r_leopard = pygame.Rect(796, 232, CHESSSIZE_Y, CHESSSIZE_Y)
r_fox = pygame.Rect(920, 123, CHESSSIZE_Y, CHESSSIZE_Y)
r_mouse = pygame.Rect(793, 16, CHESSSIZE_Y, CHESSSIZE_Y)
return l_elephant,l_eagle,l_wolf, l_lion,l_leopard, l_mouse,l_fox,r_elephant,r_eagle,r_wolf,r_lion,r_leopard,r_fox,r_mouse
def getAnimalsname():
animalsName=[0,l_mouse,l_eagle,l_fox,l_wolf,l_leopard,l_lion,l_elephant,r_mouse,r_eagle,r_fox,r_wolf,r_leopard,r_lion,r_elephant]
return animalsName
def update(animalsName):
l_mouse = animalsName[1]
l_eagle = animalsName[2]
l_fox = animalsName[3]
l_wolf = animalsName[4]
l_leopard = animalsName[5]
l_lion = animalsName[6]
l_elephant = animalsName[7]
r_mouse = animalsName[8]
r_eagle = animalsName[9]
r_fox = animalsName[10]
r_wolf = animalsName[11]
r_leopard = animalsName[12]
r_lion = animalsName[13]
r_elephant = animalsName[14]
return l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, r_leopard, r_fox, r_mouse

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,30 +0,0 @@
import pygame
import pygame_menu
def pause():
pass
def report():
pass
def surrender():
pass
def start_menu():
pygame.init()
surface = pygame.display.set_mode((600, 400))
menu = pygame_menu.Menu('DO YOUR ACTIONS', 400, 300, theme = pygame_menu.themes.THEME_BLUE)
menu.add.button('Pause', pause)
menu.add.button('Surrender', surrender)
menu.add.button('Report', report)
menu.add.button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)
if __name__ == '__main__':
start_menu()

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 516 B

@ -1,32 +0,0 @@
import pygame
rules = {}
for i in range(1, 8):
eaten = [i]
for j in range(1, i):
eaten.append(j)
rules[i] = eaten
rules[1].append(7)
hint = pygame.image.load("hint.png")
capture_hint = pygame.image.load("capture_hint.png")
def tran(x,y):
pass
def ismove(old_x, old_y, x, y, id, MAP):
pass
def path(id, x, y, status):
if status:
movement = []
for i in range(9):
for j in range(7):
if ismove(x, y, i, j, id, MAP):
movement.append([i, j])
for i, j in movement:
WIN.blit(hint, tran(i,j))
WIN.blit(capture_hint,tran(x,y))
else:
pass#重新绘制

@ -1,2 +0,0 @@
def f(x):
x = 1

@ -1,38 +0,0 @@
class Player:
def __init__(self, counterpart_name=None,name=None, game_id=None, side=None,think_time=30,total_time=600,id = None,status_2 = None,request = None,invalid = 1,Left_win = 0,Right_win = 0,over_time_side = None):
self.name = name
self.game_id = game_id
self.side = side
self.think_time = think_time
self.total_time = total_time
self.id = id
self.status_2 = status_2
self.counterpart_name = counterpart_name
self.request = request
self.invalid = invalid
self.Left_win = Left_win
self.Right_win = Right_win
self.over_time_side = over_time_side
class Chessmen_axis:
def __init__(self, Axis):
self.axis = [{} for i in range(15)]
for i in range(1,15):
old_x, old_y = Axis[i]
self.axis[i]["old_x"] = old_x
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):
self.axis[id]["old_x"] = old_x
self.axis[id]["old_y"] = old_y
self.axis[id]["x"] = x
self.axis[id]["y"] = y

@ -1,174 +0,0 @@
import pygame
import init
font_addr = pygame.font.get_default_font()
font = pygame.font.Font(font_addr, 36)
BLACK = (0,0,0)
LIGHTBLUE = (40,191,255)
LIGHTBLUE2 = (0,0,255)
BGCOLOR = (230,230,250)
MAGENTA = (255,0,255)
LIGHTYELLOW = (255,225,0)
MYCOLOR = (255,165,0)
WHITE = (255,255,255)
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
Crimson = (220,20,60)
LightPink = (255,182,193)
DeepSkyBlue = (0,191,255)
WIDTH,HEIGHT = 1200 , 800
WIN = pygame.display.set_mode((WIDTH,HEIGHT))
SPACE = pygame.transform.scale(pygame.image.load('images/map.png'),(WIDTH,HEIGHT))
class Button(object):
def __init__(self, text, color, x=None, y=None, **kwargs):
self.surface = font.render(text, True, color)
self.WIDTH = self.surface.get_width()
self.HEIGHT = self.surface.get_height()
if 'centered_x' in kwargs and kwargs['centered_x']:
self.x = WIDTH // 2 - self.WIDTH // 2
else:
self.x = x
if 'centered_y' in kwargs and kwargs['centered_y']:
self.y = HEIGHT //2 - self.HEIGHT // 2
else:
self.y = y
def display(self):
WIN.blit(self.surface, (self.x, self.y))
def check_click(self, position):
x_match = (position[0] > self.x) and (position[0] < self.x + self.WIDTH)
y_match = (position[1] > self.y) and (position[1] < self.y + self.HEIGHT)
if x_match and y_match:
return True
else:
return False
def starting_screen():
WIN.blit(SPACE, (0, 0))
game_title = font.render('Starting Screen', True, WHITE)
WIN.blit(game_title, (WIDTH//2 - game_title.get_width()//2, 150))
play_button = Button('Single Play!', WHITE, None, 350, centered_x=True)
Oplay_button = Button('Online Play!', WHITE, None, 400, 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()
while True:
if play_button.check_click(pygame.mouse.get_pos()):
play_button = Button('Single Play!', RED, None, 350, centered_x=True)
else:
play_button = Button('Single Play!', WHITE, None, 350, centered_x=True)
if Oplay_button.check_click(pygame.mouse.get_pos()):
Oplay_button = Button('Online Play!', RED, None, 400, centered_x=True)
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, 500, centered_x=True)
else:
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()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
if pygame.mouse.get_pressed()[0]:
if play_button.check_click(pygame.mouse.get_pos()):
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
def starting_menu():
WIN.blit(SPACE, (0, 0))
game_title = font.render('Menu', True, WHITE)
WIN.blit(game_title, (WIDTH//2 - game_title.get_width()//2, 150))
play_button = Button('Pause', WHITE, None, 350, centered_x=True)
Oplay_button = Button('Report', WHITE, None, 400, centered_x=True)
exit_button = Button('Quit', WHITE, None, 500, centered_x=True)
surrender_button = Button('Surrender', WHITE, None, 450, centered_x=True)
play_button.display()
Oplay_button.display()
exit_button.display()
surrender_button.display()
pygame.display.update()
while True:
if play_button.check_click(pygame.mouse.get_pos()):
play_button = Button('Pause', RED, None, 350, centered_x=True)
else:
play_button = Button('Pause', WHITE, None, 350, centered_x=True)
if Oplay_button.check_click(pygame.mouse.get_pos()):
Oplay_button = Button('Report', RED, None, 400, centered_x=True)
else:
Oplay_button = Button('Report', WHITE, None, 400, centered_x=True)
if surrender_button.check_click(pygame.mouse.get_pos()):
surrender_button = Button('Surrender', RED, None, 450, centered_x=True)
else:
surrender_button = Button('Surrender', WHITE, None, 450, centered_x=True)
if exit_button.check_click(pygame.mouse.get_pos()):
exit_button = Button('Quit', RED, None, 500, centered_x=True)
else:
exit_button = Button('Quit', WHITE, None, 500, centered_x=True)
play_button.display()
Oplay_button.display()
exit_button.display()
surrender_button.display()
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
if pygame.mouse.get_pressed()[0]:
if play_button.check_click(pygame.mouse.get_pos()):
return 1
if Oplay_button.check_click(pygame.mouse.get_pos()):
return 2
if surrender_button.check_click(pygame.mouse.get_pos()):
return 3
if exit_button.check_click(pygame.mouse.get_pos()):
return 0

@ -1,27 +0,0 @@
import pygame
import pygame_menu
import math
def draw_update_function(widget, menu):
t = widget.get_attribute('t', 0)
t += menu.get_clock().get_time()
widget.set_padding(10*(1 + math.sin(t))) # Oscillating padding
pygame.init()
surface = pygame.display.set_mode((600, 400))
def set_difficulty(value, difficulty):
# Do the job here !
pass
def start_the_game():
# Do the job here !
pass
menu = pygame_menu.Menu('Welcome', 400, 300,
theme=pygame_menu.themes.THEME_BLUE)
menu.add.text_input('Name :', default='John Doe')
menu.add.selector('Difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add.button('Play', start_the_game)
menu.add.button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)

@ -1,32 +0,0 @@
import pygame
import time
pygame.init()
black = (0, 0, 0)
white = (255, 255, 255)
display_width = 800
display_height = 600
gameDisplay = pygame.display.set_mode((display_width, display_height))
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def time_ShowAndCheck(client_time):
time.sleep(1)
gameDisplay.fill(white)
count = client_time
clock = str(count)
largeText = pygame.font.SysFont('comicsansms', 25)
TextSurf, TextRect = text_objects(clock, largeText)
TextRect.center = (750, (display_height / 10))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
flag = 300
while flag:
time_ShowAndCheck(flag)
flag -= 1
Loading…
Cancel
Save