-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_direct_python.py
More file actions
132 lines (108 loc) · 4.05 KB
/
Copy pathtest_direct_python.py
File metadata and controls
132 lines (108 loc) · 4.05 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
#!/usr/bin/env python3
"""
Test V7P3R engines by calling the Python UCI script directly
"""
import subprocess
import time
from pathlib import Path
def test_engine_direct_python(engine_dir, version_name):
"""Test engine by calling Python directly on the UCI script"""
print(f"\n{'='*70}")
print(f"Testing {version_name} via direct Python call")
print(f"{'='*70}")
uci_script = Path(engine_dir) / "src" / "v7p3r_uci.py"
if not uci_script.exists():
print(f"❌ UCI script not found: {uci_script}")
return False
print(f"UCI Script: {uci_script}")
print(f"Working dir: {engine_dir}")
try:
# Call Python directly on the UCI script
proc = subprocess.Popen(
["python", str(uci_script)],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=1,
cwd=str(engine_dir)
)
print(f"✓ Process started with PID: {proc.pid}")
# Send UCI command
print("\nSending: uci")
proc.stdin.write("uci\n")
proc.stdin.flush()
# Read response
print("Engine response:")
start = time.time()
timeout = 5.0
found_uciok = False
engine_name = None
while time.time() - start < timeout:
line = proc.stdout.readline()
if line:
line = line.strip()
print(f" < {line}")
if "uciok" in line:
found_uciok = True
break
if "id name" in line:
engine_name = line.replace("id name", "").strip()
else:
time.sleep(0.1)
if found_uciok:
print(f"\n✅ SUCCESS!")
if engine_name:
print(f" Engine: {engine_name}")
# Test a move from starting position
print("\n🎯 Testing move generation from starting position...")
proc.stdin.write("position startpos\n")
proc.stdin.flush()
proc.stdin.write("go movetime 1000\n")
proc.stdin.flush()
best_move = None
start = time.time()
while time.time() - start < 5.0:
line = proc.stdout.readline()
if line:
line = line.strip()
if line.startswith("info"):
print(f" {line[:80]}...")
elif "bestmove" in line:
best_move = line.split()[1] if len(line.split()) > 1 else None
print(f"\n✅ Best move: {best_move}")
break
proc.stdin.write("quit\n")
proc.stdin.flush()
proc.wait(timeout=2)
return True
else:
print(f"\n❌ FAILED: No uciok received")
proc.terminate()
return False
except Exception as e:
print(f"❌ ERROR: {e}")
import traceback
traceback.print_exc()
return False
def main():
print("="*70)
print("V7P3R ENGINE DIRECT PYTHON TEST")
print("="*70)
engines = {
"v18.3": r"E:\Programming Stuff\Chess Engines\V7P3R Chess Engine\v7p3r-chess-engine\lichess\engines\V7P3R_v18.3_20251229",
"v18.4": r"E:\Programming Stuff\Chess Engines\V7P3R Chess Engine\v7p3r-chess-engine\development\V7P3R_v18.4_20260415"
}
results = {}
for version, engine_dir in engines.items():
results[version] = test_engine_direct_python(engine_dir, version)
print(f"\n{'='*70}")
print("SUMMARY")
print(f"{'='*70}")
for version, success in results.items():
status = "✅ WORKS" if success else "❌ FAILED"
print(f" {version:10s} {status}")
if all(results.values()):
print(f"\n💡 Solution: Use 'python <path>/src/v7p3r_uci.py' instead of .bat files")
if __name__ == "__main__":
main()