Compare commits

...

77 Commits

Author SHA1 Message Date
huangjielun 52e4823634 完成
3 years ago
huangjielun 0289aca1d8 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 9efeb3be10 报告
3 years ago
Mix 3542078481 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 7b609712e7 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix d63335731e Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 8a29593221 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 49969c8790 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 53237cb159 AI版修改规则
3 years ago
huangjielun 33aa13d222 AI版修改规则
3 years ago
huangjielun fbe4e48e06 AI版完成
3 years ago
huangjielun e9e8bf0402 AI版
3 years ago
huangjielun c9e2613130 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun a64402b06d 接受消息一方移动,但是不改变turn
3 years ago
Mix 0b556077df Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 077f6f4d34 AI_play
3 years ago
huangjielun 064da16cb3 AI
3 years ago
huangjielun b237cffa60 AI对战
3 years ago
huangjielun c9cfd6321d No more
3 years ago
huangjielun 2e4d5c1bab Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 4b997d71ee 换边
3 years ago
Mix 932d375d89 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 204a21506a Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix acd151d235 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 810180a173 还需要加入判断对方的移动是否合法
3 years ago
huangjielun cb032171d8 还需要加入判断对方的移动是否合法
3 years ago
huangjielun 8930400e6f 完成除举报外的协议
3 years ago
huangjielun 2fa04276b3 完成基本协议
3 years ago
Mix 54761a1c93 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun cc6b020ab1 网络版,还有退出游戏和超时判负规则未做
3 years ago
huangjielun 309ff905ae 网络版,还有退出游戏和超时判负规则未做
3 years ago
huangjielun 0c763d008d 网络版移动
3 years ago
Mix 07bfacc8bd Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 53f63cba27 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix dbda5c0e65 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 04180852db Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 3473a88bdf Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 1a933aa815 完成单机版
3 years ago
huangjielun 214ea8a70d 完成单机版
3 years ago
huangjielun 9c55916cbf 存在围住无法判输的bug
3 years ago
huangjielun f88e6df36a Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun c07e07deff 修改bug
3 years ago
huangjielun f4b4890161 修复可以吃自己陷阱里的同伴的bug
3 years ago
Mix 9cfc8e8724 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 481c4f1508 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 1d0aad14fd Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 82cc676dc1 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 23bcbedd18 修改老鹰bug
3 years ago
huangjielun 92cffab111 修复消失BUG
3 years ago
Mix cbdd10d0cc Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 28bc2f9f44 完成
3 years ago
Mix a20e4745a7 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun cfb99efff9 完成包围和重新开始
3 years ago
huangjielun 2e7acc35bd 完成包围和重新开始
3 years ago
huangjielun 607e82d035 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun a1d1873ddd 基本完成单机版(还差一个判负规则,一个悔棋,一个重置,一些结束后的处理)
3 years ago
Mix 814f558a2c Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun d7e2fdae45 修改
3 years ago
huangjielun a5ae8fb642 8月27
3 years ago
huangjielun 0d980d2aab 修改
3 years ago
huangjielun ce32842dff Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun 5fedd0a4d3 开始页面和背景坐标化
3 years ago
Mix 71bbe94a13 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix af6a319895 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 8477421769 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 6eb7471c33 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix 0b62c9d6f3 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun ecd2fa5118 完成棋子的摆放
3 years ago
huangjielun 68fb8fd3b2 完成棋子的摆放
3 years ago
huangjielun 9ac29b868d 完成棋子的格子化
3 years ago
huangjielun 9468e40ac6 完成移动
3 years ago
Mix 3f98b59793 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix a790f78355 Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
Mix d3a262492e Merge branch 'develop' of https://bdgit.educoder.net/pahiq8bnc/Jungle into develop
3 years ago
huangjielun d528bbd93a 完成了动物图片的处理与游戏背景的制作
3 years ago
huangjielun 2537c228d7 完成了动物图片的处理与游戏背景的制作
3 years ago
huangjielun 015888158e java斗兽棋
3 years ago

3
.idea/.gitignore vendored

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

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

@ -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 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

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

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

@ -0,0 +1,7 @@
<?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,2 +1,3 @@
# Jungle
主要功能在main.py函数中

Binary file not shown.

@ -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,5 @@
SOCKET_HOST=127.0.0.1
SOCKET_PORT=50005
MAX_WAITING_TIME=600
MAX_THNIKING_TIME=30
MAX_TOTAL_TIME=1000

@ -0,0 +1,268 @@
# 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()

@ -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,176 @@
# 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

@ -0,0 +1,41 @@
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.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

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

@ -0,0 +1,30 @@
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.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

@ -0,0 +1,32 @@
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#重新绘制

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

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

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

@ -0,0 +1,27 @@
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)

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