Commit e3cc7fb5 by huangzhihao

修复了一些bug

parent 33f9d1ce
......@@ -4,7 +4,7 @@ import time
import random
import re
commdir='.' #共享目录
commdir='share' #共享目录
def cd(path):
return os.path.join(commdir,path)
......
......@@ -5,11 +5,11 @@ import os
import re
import time
commdir='.' #共享目录
commdir='share' #共享目录
def cd(path):
return os.path.join(commdir,path)
elo=EloRatingSystem(recordSaveFile=cd('gameRecord.txt')) #初始化
elo=EloRatingSystem(recordSaveFile='gameRecord.txt') #初始化
def askYes(str):
ans=''
......@@ -26,11 +26,11 @@ def askYes(str):
def main():
print('--------------ELO rating system---------------')
if os.path.exists(cd('models.txt')):
if os.path.exists('models.txt'):
print('read models from models.txt')
with open(cd('models.txt'),'r') as f:
with open('models.txt','r') as f:
lines=f.readlines()
models=lines
models=[l.strip() for l in lines]
else:
models=[str(i) for i in range(300)] #模型的名字
print('default models:range(0,300,1) or [0,299]')
......@@ -43,12 +43,12 @@ def main():
if os.path.exists(cd('stop.txt')):
os.remove(cd('stop.txt'))
if os.path.exists(cd('gameRecord.txt')):
if os.path.exists('gameRecord.txt'):
print('\n game records has found!')
if askYes('read it? if not,will delete it and create a new one <y/n> :'):
elo.readRecords(cd('gameRecord.txt'))
elo.readRecords('gameRecord.txt')
else:
os.remove(cd('gameRecord.txt'))
os.remove('gameRecord.txt')
commandList=[r'play (\d+)','summary','stop','save']
print('commandList:\n '+'\n '.join(commandList))
......@@ -60,7 +60,7 @@ def main():
elif ans=='summary':
elo.summary()
elif ans=='save':
elo.save(saveFile=cd('output.txt'),sortByRank=False)
elo.save(saveFile='output.txt',sortByRank=False)
else:
matchRes=re.match(r'play (\d+)',ans)
if matchRes:
......@@ -104,7 +104,7 @@ def play(total_game):
def read():
#读取完成的比赛记录
count=0
dir=os.listdir('comm')
dir=os.listdir(cd('comm'))
for d in dir:
res=re.match(r'(\d+)_(\d+)_(\d+)\.finish',d)
if res:
......@@ -118,7 +118,7 @@ def play(total_game):
def exist_game():
count=0
dir=os.listdir('comm')
dir=os.listdir(cd('comm'))
for d in dir:
res=re.match(r'(\d+)_(\d+)\.running',d)
if res:
......@@ -129,13 +129,17 @@ def play(total_game):
count+=1
continue
return count
idx=0
while complete_game<total_game:
complete_game+=read()
num=exist_game()
create_game(min(max_game-num,total_game-complete_game-num+10))
print('{}/{}'.format(complete_game,total_game))
time.sleep(5)
if idx==5:
print('{}/{}'.format(complete_game,total_game))
idx=0
idx+=1
time.sleep(1)
......@@ -145,4 +149,4 @@ def play(total_game):
if __name__ == '__main__':
main()
\ No newline at end of file
main()
......@@ -190,17 +190,17 @@ class EloRatingSystem:
players.sort(key=sortKey,reverse=True)
print('{:<10s}{:<10s}{:<10s}{:<10s}{:<10s}'.format('model','rating','games','wins','losses'))
print('{:<20s}{:<10s}{:<10s}{:<10s}{:<10s}'.format('model','rating','games','wins','losses'))
for p in players:
print('{:<10s}{:<10.2f}{:<10d}{:<10d}{:<10d}'.format(str(p.name),p.rating,p.num_game,p.wins,p.losses))
print('{:<20s}{:<10.2f}{:<10d}{:<10d}{:<10d}'.format(str(p.name),p.rating,p.num_game,p.wins,p.losses))
def save(self,saveFile='elo_rating_output.txt',sortByRank=False):
players=self.getPlayers(sortByRank)
with open(saveFile,'w') as f:
f.write('{:<10s}{:<10s}{:<10s}{:<10s}{:<10s}\n'.format('model','rating','games','wins','losses'))
f.write('{:<20s}{:<10s}{:<10s}{:<10s}{:<10s}\n'.format('model','rating','games','wins','losses'))
for p in players:
f.write('{:<10s}{:<10.2f}{:<10d}{:<10d}{:<10d}\n'.format(str(p.name),p.rating,p.num_game,p.wins,p.losses))
f.write('{:<20s}{:<10.2f}{:<10d}{:<10d}{:<10d}\n'.format(str(p.name),p.rating,p.num_game,p.wins,p.losses))
def getPlayers(self,sortByRank=False):
......
......@@ -6,9 +6,9 @@
**2、**
​ 共享目录请到ELo_server.py和ELO_client.py中修改,默认是'.'
​ 共享目录请到ELo_server.py和ELO_client.py中修改
所有的文件都会存到这个目录
临时文件都会存到这个目录,比赛的记录gameRecord.txt和output.txt会存放在server的代码文件那个目录
**3、**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment