11import os
22import sys
3+ import stat
34import zipfile
45from pathlib import Path
56from subprocess import call
67from typing import *
78
89import evalfen
9- from getFile import downloadName , getAvailableNames
10+ from getFile import downloadName , getAvailableNames , createDir
1011from send import sendFile , sendNotification
1112
1213STOCKFISH_DOWNLOAD = {
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
4365def findStockfish () -> Path :
44- pass
66+ return Path ( os . getcwd ()) / STOCKFISH_LOCATION [ sys . platform ]
4567
4668
4769def 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
5498def 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
0 commit comments