-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_test.py
More file actions
132 lines (113 loc) · 3.59 KB
/
run_test.py
File metadata and controls
132 lines (113 loc) · 3.59 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 runner for Chess Analyzer using the embedded PGN from article.txt.
Usage:
1. Set your Gemini API key:
export GEMINI_API_KEY='your-api-key-here'
2. Run this script:
python run_test.py
Or provide API key directly:
python run_test.py --api-key your-api-key
With custom Stockfish settings:
python run_test.py --depth 20 --threads 2 --hash 512
"""
import sys
import os
# Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from chess_analyzer import analyze_game, TEST_PGN, GEMINI_MODEL, STOCKFISH_DEPTH, STOCKFISH_TIME_PER_MOVE, STOCKFISH_THREADS, STOCKFISH_HASH
def main():
import argparse
parser = argparse.ArgumentParser(description="Run chess analysis on embedded test game")
parser.add_argument(
"--api-key",
default=os.environ.get("GEMINI_API_KEY", ""),
help="Gemini API key (or set GEMINI_API_KEY environment variable)"
)
parser.add_argument(
"--model",
default=GEMINI_MODEL,
help=f"Gemini model to use (default: {GEMINI_MODEL})"
)
parser.add_argument(
"--output",
"-o",
default="GameAnalysis_Output.txt",
help="Output file path (default: GameAnalysis_Output.txt)"
)
parser.add_argument(
"--perspective",
choices=["White", "Black"],
default="White",
help="Analyze from player's perspective (default: White)"
)
# Stockfish settings
parser.add_argument(
"--depth",
type=int,
default=STOCKFISH_DEPTH,
help=f"Stockfish search depth (default: {STOCKFISH_DEPTH})"
)
parser.add_argument(
"--time",
type=int,
default=STOCKFISH_TIME_PER_MOVE,
help=f"Time per move in ms (default: {STOCKFISH_TIME_PER_MOVE})"
)
parser.add_argument(
"--threads",
type=int,
default=STOCKFISH_THREADS,
help=f"CPU threads (default: {STOCKFISH_THREADS})"
)
parser.add_argument(
"--hash",
type=int,
dest="hash_mb",
default=STOCKFISH_HASH,
help=f"Hash table size in MB (default: {STOCKFISH_HASH})"
)
args = parser.parse_args()
if not args.api_key:
print("Error: Please provide API key")
print("\nOptions:")
print(" 1. Set environment variable: export GEMINI_API_KEY='your-key'")
print(" 2. Use command line: python run_test.py --api-key your-key")
sys.exit(1)
print("=" * 70)
print("Chess Game Analyzer - Test Run")
print("=" * 70)
print(f"\nModel: {args.model}")
print(f"Output: {args.output}")
print(f"Perspective: {args.perspective}")
print(f"\nStockfish Settings:")
print(f" Depth: {args.depth}")
print(f" Time per move: {args.time}ms")
print(f" Threads: {args.threads}")
print(f" Hash: {args.hash_mb}MB")
print("\nAnalyzing game from article.txt:")
print(" White: MattPlaysChess")
print(" Black: T., A.")
print(" Result: 1-0")
print(" Opening: Dutch Defense")
print(" Moves: 52")
print("\n" + "-" * 70)
# Run analysis
analysis = analyze_game(
TEST_PGN,
args.api_key,
args.model,
args.perspective,
args.depth,
args.time,
args.threads,
args.hash_mb
)
# Save output
with open(args.output, 'w') as f:
f.write(analysis)
print("-" * 70)
print(f"\n✓ Analysis complete! Output saved to: {args.output}")
print("\n" + "=" * 70)
if __name__ == "__main__":
main()