-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_requirements.py
More file actions
164 lines (140 loc) · 4.85 KB
/
test_requirements.py
File metadata and controls
164 lines (140 loc) · 4.85 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python3
"""
Test script for AI Chess Scanner
Verifies all components work without requiring GUI display
"""
import sys
import os
# Test 1: Check Python version
print("=" * 60)
print("TEST 1: Python Version")
print("=" * 60)
print(f"Python: {sys.version}")
required_version = (3, 8)
if sys.version_info < required_version:
print(f"❌ FAILED: Python 3.8+ required")
sys.exit(1)
print("✅ PASSED\n")
# Test 2: Check dependencies
print("=" * 60)
print("TEST 2: Required Dependencies")
print("=" * 60)
dependencies = {
'PIL': 'Pillow',
'cv2': 'opencv-python',
'chess': 'python-chess',
'chess.engine': 'python-chess'
}
missing = []
for module, package in dependencies.items():
try:
__import__(module)
print(f"✅ {package:20} - OK")
except ImportError:
print(f"❌ {package:20} - MISSING")
missing.append(package)
if missing:
print(f"\n❌ FAILED: Missing packages: {', '.join(missing)}")
sys.exit(1)
print("✅ PASSED\n")
# Test 3: Check Stockfish
print("=" * 60)
print("TEST 3: Stockfish Engine")
print("=" * 60)
import chess
import chess.engine
stockfish_paths = [
"/opt/homebrew/bin/stockfish", # macOS Apple Silicon
"/usr/local/bin/stockfish", # macOS Intel
"/usr/games/stockfish", # Linux
"/usr/bin/stockfish", # Linux
]
found_stockfish = None
for path in stockfish_paths:
if os.path.exists(path):
found_stockfish = path
print(f"✅ Found Stockfish at: {path}")
break
if not found_stockfish:
print(f"❌ FAILED: Stockfish not found")
print("Install with: brew install stockfish (macOS) or sudo apt install stockfish (Linux)")
sys.exit(1)
# Test engine initialization
try:
with chess.engine.SimpleEngine.popen_uci(found_stockfish) as engine:
print(f"✅ Stockfish engine initialized successfully")
print(f"✅ PASSED\n")
except Exception as e:
print(f"❌ FAILED: {str(e)}\n")
sys.exit(1)
# Test 4: FEN Validation
print("=" * 60)
print("TEST 4: Chess FEN Validation")
print("=" * 60)
test_fens = [
("Starting Position", "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", True),
("After 1.e4", "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1", True),
("Invalid FEN", "invalid/fen/string", False),
]
for name, fen, should_pass in test_fens:
try:
chess.Board(fen)
result = "✅" if should_pass else "❌"
print(f"{result} {name}: {fen}")
except ValueError as e:
result = "✅" if not should_pass else "❌"
print(f"{result} {name}: Invalid")
print("✅ PASSED\n")
# Test 5: Basic Position Analysis
print("=" * 60)
print("TEST 5: Basic Position Analysis")
print("=" * 60)
board = chess.Board("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1")
print(f"FEN: {board.fen()}")
print(f"Turn: {'White' if board.turn else 'Black'}")
print(f"Legal Moves Available: {board.legal_moves.count()}")
print(f"In Check: {board.is_check()}")
try:
with chess.engine.SimpleEngine.popen_uci(found_stockfish) as engine:
info = engine.analyse(board, chess.engine.Limit(time=1.0))
if "pv" in info and info["pv"]:
best_move = info["pv"][0]
move_san = board.san(best_move)
print(f"\n🎯 Best Move: {move_san}")
if "score" in info:
score = info["score"]
if score.is_mate():
mate_in = score.mate()
print(f"⚠️ Checkmate in {abs(mate_in)} moves")
else:
# Extract the centipawn score
try:
# Try using relative() method first
cp_val = score.relative.cp
except (AttributeError, TypeError):
try:
# For white's perspective
cp_val = score.white().cp
except (AttributeError, TypeError):
# Fallback: convert to string and parse
cp_str = str(score)
try:
cp_val = int(float(cp_str) * 100)
except:
cp_val = 0
eval_score = cp_val / 100.0
print(f"📊 Evaluation: {eval_score:+.2f} pawns")
print("✅ PASSED\n")
else:
print("❌ FAILED: No best move found\n")
except Exception as e:
print(f"❌ FAILED: {str(e)}\n")
sys.exit(1)
# Final Summary
print("=" * 60)
print("ALL TESTS PASSED! ✅")
print("=" * 60)
print("\n✨ Your Chess Scanner is ready to run!")
print(" Launch with: python script.py")
print("\nNote: The GUI requires a display environment.")
print("If running on a server, use ssh -X for X11 forwarding.")