-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_chess.py
More file actions
63 lines (53 loc) · 2.23 KB
/
Copy pathsetup_chess.py
File metadata and controls
63 lines (53 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import urllib.request
import zipfile
import subprocess
import sys
def setup():
base_dir = os.path.dirname(os.path.abspath(__file__))
assets_dir = os.path.join(base_dir, "games", "chess_game", "assets")
pieces_dir = os.path.join(assets_dir, "pieces")
os.makedirs(pieces_dir, exist_ok=True)
# 1. Download Pieces from chess.com
pieces = ['wp', 'wn', 'wb', 'wr', 'wq', 'wk', 'bp', 'bn', 'bb', 'br', 'bq', 'bk']
print("Downloading chess pieces...")
for p in pieces:
url = f"https://images.chesscomfiles.com/chess-themes/pieces/neo/150/{p}.png"
file_path = os.path.join(pieces_dir, f"{p}.png")
if not os.path.exists(file_path):
try:
urllib.request.urlretrieve(url, file_path)
print(f"Downloaded {p}.png")
except Exception as e:
print(f"Failed to download {p}.png: {e}")
# 2. Download Stockfish
print("Downloading Stockfish...")
sf_zip = os.path.join(assets_dir, "stockfish.zip")
sf_dir = os.path.join(assets_dir, "stockfish")
sf_exe_dest = os.path.join(assets_dir, "stockfish.exe")
if not os.path.exists(sf_exe_dest):
url = "https://github.com/official-stockfish/Stockfish/releases/download/sf_16.1/stockfish-windows-x86-64.zip"
urllib.request.urlretrieve(url, sf_zip)
print("Stockfish downloaded, extracting...")
with zipfile.ZipFile(sf_zip, 'r') as zip_ref:
zip_ref.extractall(sf_dir)
# Find the exe inside the extracted folder
for root, dirs, files in os.walk(sf_dir):
for file in files:
if file.endswith(".exe"):
os.rename(os.path.join(root, file), sf_exe_dest)
break
# Cleanup
try:
os.remove(sf_zip)
except:
pass
print("Stockfish setup complete.")
else:
print("Stockfish already exists.")
# 3. Install stockfish python package
print("Installing python stockfish wrapper...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "stockfish", "chess"])
print("Setup completed successfully.")
if __name__ == "__main__":
setup()