Skip to content

Commit 36103d5

Browse files
committed
Can't continue further due to MacOS bug
1 parent 4070517 commit 36103d5

4 files changed

Lines changed: 109 additions & 38 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ stockfish/
66
stockfish.zip
77
__MAC*
88
*cpython*
9+
data/
10+
dest/

contribute/auto.py

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
22
import sys
3+
import stat
34
import zipfile
45
from pathlib import Path
56
from subprocess import call
67
from typing import *
78

89
import evalfen
9-
from getFile import downloadName, getAvailableNames
10+
from getFile import downloadName, getAvailableNames, createDir
1011
from send import sendFile, sendNotification
1112

1213
STOCKFISH_DOWNLOAD = {
@@ -16,8 +17,15 @@
1617
"darwin": "https://stockfishchess.org/files/stockfish-11-mac.zip"
1718
}
1819

20+
STOCKFISH_LOCATION = {
21+
"win32": r"stockfish\stockfish-11-win\Windows\stockfish_20011801_x64_bmi2.exe",
22+
"linux": "stockfish/stockfish-11-linux/Linux/stockfish_20011801_x64_bmi2",
23+
"linux32": "stockfish/stockfish-11-linux/Linux/stockfish_20011801_x64_bmi2",
24+
"darwin": "stockfish/stockfish-11-mac/Mac/stockfish-11-bmi2"
25+
}
26+
1927

20-
def unzip(filepath, resultpath):
28+
def unzip(filepath: str, resultpath: str) -> None:
2129
with zipfile.ZipFile(filepath, 'r') as zip_ref:
2230
zip_ref.extractall(resultpath)
2331

@@ -38,25 +46,72 @@ def downloadStockfish() -> None:
3846
link = STOCKFISH_DOWNLOAD[sys.platform]
3947
call(["curl", "-o", "stockfish.zip", link])
4048
unzip("stockfish.zip", "stockfish/")
41-
49+
stockfishexecutable = str(findStockfish())
50+
if sys.platform != "win32":
51+
os.chmod(stockfishexecutable, stat.S_IEXEC)
52+
os.remove("stockfish.zip")
53+
54+
def promptNameChoice() -> Tuple[str]:
55+
available = os.listdir("data")
56+
for i, name in enumerate(available):
57+
print(i, name, sep='\t')
58+
uin = input("Which would you like to start on? ")
59+
try:
60+
uin = available[int(uin)]
61+
except ValueError:
62+
pass
63+
return str(Path(os.getcwd()) / "data" / uin), uin
4264

4365
def findStockfish() -> Path:
44-
pass
66+
return Path(os.getcwd()) / STOCKFISH_LOCATION[sys.platform]
4567

4668

4769
def promptStockfish() -> Path:
48-
uin = input("Do you have stockfish in your current directory?(y)es/(n)o ")
49-
needsfish = 'y' in uin
70+
needsfish = "stockfish" not in os.listdir()
5071
if needsfish:
72+
print("Downloading stockfish")
5173
downloadStockfish()
52-
74+
return findStockfish()
75+
76+
def getNumberThreads() -> int:
77+
return os.cpu_count()
78+
79+
def progressBar(percentage: float) -> str:
80+
numpound = round(percentage*78)
81+
numdash = 78-numpound
82+
return '[' + numpound*'#' + numdash*'-' + ']'
83+
84+
def countOutput(count: int, length: int) -> None:
85+
print(progressBar(count/length), end='\r', flush=True)
86+
87+
def promptThreads() -> int:
88+
numthreads = getNumberThreads()
89+
userthreads = 0
90+
print(f"You have {numthreads} threads available.")
91+
while not 1 <= userthreads <= numthreads:
92+
try:
93+
userthreads = int(input("How many threads would you like to use? "))
94+
except ValueError:
95+
pass
96+
return userthreads
5397

5498
def main() -> None:
99+
createDir("dest")
100+
createDir("data")
55101
if promptDownload():
56102
names = list(getAvailableNames())
57103
names.sort()
58104
name = promptNames(names)
59105
downloadName(name)
106+
pathToStockfish = str(promptStockfish())
107+
threads = promptThreads()
108+
source, name = promptNameChoice()
109+
dest = str(Path(os.getcwd()) / "dest" / name)
110+
111+
amountlines = evalfen.lineCount(dest)
112+
countOut = lambda c: countOutput(c, amountlines)
113+
114+
evalfen.main(source, dest, 22, threads, amountlines, pathToStockfish, countOut)
60115
print("Done for now")
61116

62117

contribute/evalfen.py

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import sys
33
from threading import Thread
4+
import subprocess
45

56
import chess
67
import chess.engine
@@ -35,7 +36,8 @@ def evalFENThread(output, i, fen, engine, d):
3536
info = engine.analyse(board, chess.engine.Limit(depth=d))
3637
output[i] = str(info["score"].white()) + '\n'
3738

38-
def main(filein, fileout, d, threads, linetostart, enginepath):
39+
def main(filein, fileout, d, threads, linetostart, enginepath, counterOutput = lambda x: print(x, end='\r', flush=True)):
40+
print(enginepath)
3941
engines = [chess.engine.SimpleEngine.popen_uci(enginepath) for i in range(threads)]
4042

4143
with open(filein, 'r') as fin:
@@ -46,35 +48,38 @@ def main(filein, fileout, d, threads, linetostart, enginepath):
4648

4749
counter = linetostart
4850
with open(fileout, 'a+') as fout:
49-
while counter < l:
50-
ts = []
51-
threadcontents = [0 for i in range(threads)]
52-
for i in range(threads):
53-
try:
54-
f = contents.pop(0)
55-
fen = f[:-1]
56-
t = Thread(
57-
target = evalFENThread,
58-
args = (threadcontents, i, fen, engines[i], d),
59-
daemon = True
60-
)
61-
ts.append(t)
62-
except IndexError:
63-
print("Almost done")
64-
for t in ts:
65-
t.start()
66-
for t in ts:
67-
t.join()
68-
for c in threadcontents:
69-
try:
70-
fout.write(c)
71-
fout.flush()
72-
except:
73-
if c != 0:
74-
print("Add this:", c)
75-
counter += threads
76-
print(counter)
77-
del ts, threadcontents
51+
try:
52+
while counter < l:
53+
ts = []
54+
threadcontents = [0 for i in range(threads)]
55+
for i in range(threads):
56+
try:
57+
f = contents.pop(0)
58+
fen = f[:-1]
59+
t = Thread(
60+
target = evalFENThread,
61+
args = (threadcontents, i, fen, engines[i], d),
62+
daemon = True
63+
)
64+
ts.append(t)
65+
except IndexError:
66+
print("Almost done")
67+
for t in ts:
68+
t.start()
69+
for t in ts:
70+
t.join()
71+
for c in threadcontents:
72+
try:
73+
fout.write(c)
74+
fout.flush()
75+
except:
76+
if c != 0:
77+
print("Add this:", c)
78+
counter += threads
79+
counterOutput(counter)
80+
del ts, threadcontents
81+
except KeyboardInterrupt:
82+
pass
7883

7984
print("Done")
8085
for engine in engines: engine.quit()

contribute/getFile.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from typing import *
2+
from pathlib import Path
3+
import os
24

35
import requests
46

@@ -27,10 +29,17 @@ def getAvailableNames() -> Set[str]:
2729
taken = getTakenNames()
2830
return {name for name in allnames if name not in taken}
2931

32+
def createDir(name: str) -> None:
33+
try:
34+
os.mkdir(name)
35+
except FileExistsError:
36+
pass
37+
3038
def downloadName(name: str) -> None:
39+
createDir("data")
3140
fenurl = "https://raw.githubusercontent.com/r2dev2bb8/ChessData/master/fens/"
3241
r = requests.get(fenurl + name, HEADERS)
33-
with open("../" + name, 'w+') as fout:
42+
with open(str(Path(os.getcwd()) / "data" / name), 'w+') as fout:
3443
fout.write(r.content.decode())
3544

3645
def main():

0 commit comments

Comments
 (0)