Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
elo-rating
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huangzhihao
elo-rating
Commits
e3cc7fb5
Commit
e3cc7fb5
authored
Aug 13, 2020
by
huangzhihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复了一些bug
parent
33f9d1ce
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
20 deletions
+24
-20
ELO_client.py
+1
-1
ELo_server.py
+17
-13
elorating.py
+4
-4
readme.md
+2
-2
No files found.
ELO_client.py
View file @
e3cc7fb5
...
...
@@ -4,7 +4,7 @@ import time
import
random
import
re
commdir
=
'
.
'
#共享目录
commdir
=
'
share
'
#共享目录
def
cd
(
path
):
return
os
.
path
.
join
(
commdir
,
path
)
...
...
ELo_server.py
View file @
e3cc7fb5
...
...
@@ -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
))
if
idx
==
5
:
print
(
'{}/{}'
.
format
(
complete_game
,
total_game
))
time
.
sleep
(
5
)
idx
=
0
idx
+=
1
time
.
sleep
(
1
)
...
...
elorating.py
View file @
e3cc7fb5
...
...
@@ -190,17 +190,17 @@ class EloRatingSystem:
players
.
sort
(
key
=
sortKey
,
reverse
=
True
)
print
(
'{:<
1
0s}{:<10s}{:<10s}{:<10s}{:<10s}'
.
format
(
'model'
,
'rating'
,
'games'
,
'wins'
,
'losses'
))
print
(
'{:<
2
0s}{:<10s}{:<10s}{:<10s}{:<10s}'
.
format
(
'model'
,
'rating'
,
'games'
,
'wins'
,
'losses'
))
for
p
in
players
:
print
(
'{:<
1
0s}{:<10.2f}{:<10d}{:<10d}{:<10d}'
.
format
(
str
(
p
.
name
),
p
.
rating
,
p
.
num_game
,
p
.
wins
,
p
.
losses
))
print
(
'{:<
2
0s}{:<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
(
'{:<
1
0s}{:<10s}{:<10s}{:<10s}{:<10s}
\n
'
.
format
(
'model'
,
'rating'
,
'games'
,
'wins'
,
'losses'
))
f
.
write
(
'{:<
2
0s}{:<10s}{:<10s}{:<10s}{:<10s}
\n
'
.
format
(
'model'
,
'rating'
,
'games'
,
'wins'
,
'losses'
))
for
p
in
players
:
f
.
write
(
'{:<
1
0s}{:<10.2f}{:<10d}{:<10d}{:<10d}
\n
'
.
format
(
str
(
p
.
name
),
p
.
rating
,
p
.
num_game
,
p
.
wins
,
p
.
losses
))
f
.
write
(
'{:<
2
0s}{:<10.2f}{:<10d}{:<10d}{:<10d}
\n
'
.
format
(
str
(
p
.
name
),
p
.
rating
,
p
.
num_game
,
p
.
wins
,
p
.
losses
))
def
getPlayers
(
self
,
sortByRank
=
False
):
...
...
readme.md
View file @
e3cc7fb5
...
...
@@ -6,9 +6,9 @@
**2、**
共享目录请到ELo_server.py和ELO_client.py中修改
,默认是'.'
共享目录请到ELo_server.py和ELO_client.py中修改
所有的文件都会存到这
个目录
临时文件都会存到这个目录,比赛的记录gameRecord.txt和output.txt会存放在server的代码文件那
个目录
**3、**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment