a geicko-2 based round robin ranking system designed to test c++ battleship submissions
battleship.dunkirk.sh
1# Development Notes
2
3**⚠️ AI Instructions: Do NOT create summary documents. User prefers to see actual code changes without additional documentation files.**
4
5## Architecture
6
7- **main.go** - SSH/HTTP server initialization with Wish and Bubble Tea
8- **model.go** - Terminal UI (TUI) for SSH sessions
9- **database.go** - SQLite storage for submissions and results
10- **web.go** - HTTP leaderboard with HTML template
11- **runner.go** - Compiles and tests C++ submissions against battleship library
12- **scp.go** - SCP upload middleware for file submissions
13- **worker.go** - Background processor (runs every 30s)
14
15## Glicko-2 Rating System
16
17**Important**: The system uses Glicko-2 ratings with **proper rating periods** to avoid last-submitter bias:
18
19- All matches in a round-robin are stored first
20- Ratings update **once at the end** using all match results together (proper rating period)
21- This eliminates path-dependency where identical algorithms get different ratings based on submission order
22- Each player's rating considers ALL their opponents' ratings at the start of the rating period
23- Glicko-2 expects 10-15+ games per rating period - our round-robin satisfies this
24
25**Manual recalculation**: Run `./battleship-arena recalculate-ratings` or `make recalculate-ratings` to recompute all ratings from scratch.
26
27## File Upload
28
29Students upload via SCP:
30```bash
31scp -P 2222 memory_functions_name.cpp username@host:~/
32```
33
34Files must match pattern `memory_functions_*.cpp`
35
36## Required Function Signatures
37
38**IMPORTANT**: Your submission must implement exactly these three functions with these exact signatures:
39
40```cpp
41void initMemoryYOURNAME(ComputerMemory &memory);
42string smartMoveYOURNAME(const ComputerMemory &memory);
43void updateMemoryYOURNAME(int row, int col, int result, ComputerMemory &memory);
44```
45
46Replace `YOURNAME` with your chosen suffix (must match your filename `memory_functions_YOURNAME.cpp`).
47
48**Example** for `memory_functions_alice.cpp`:
49```cpp
50#include "memory_functions_alice.h"
51#include "battleship.h"
52#include "kasbs.h"
53#include "memory.h"
54#include <string>
55
56using namespace std;
57
58inline string formatMove(int row, int col) {
59 char letter = static_cast<char>('A' + row);
60 return string(1, letter) + to_string(col + 1);
61}
62
63void initMemoryAlice(ComputerMemory &memory) {
64 // Initialize your memory structure
65 for (int i = 0; i < BOARDSIZE; i++) {
66 for (int j = 0; j < BOARDSIZE; j++) {
67 memory.grid[i][j] = '?';
68 }
69 }
70}
71
72void updateMemoryAlice(int row, int col, int result, ComputerMemory &memory) {
73 // Update memory based on shot result
74 // result constants: HIT, MISS, SUNK (from kasbs.h)
75 if (result == HIT || result == SUNK) {
76 memory.grid[row][col] = 'h';
77 } else {
78 memory.grid[row][col] = 'm';
79 }
80}
81
82string smartMoveAlice(const ComputerMemory &memory) {
83 // Return your next move as a string (e.g., "A1", "B5", "J10")
84 int row = 0; // your logic here
85 int col = 0; // your logic here
86 return formatMove(row, col);
87}
88```
89
90**Key Points**:
91- Function names must match your filename suffix exactly (case-sensitive)
92- Must return `string` from `smartMove`, not integer array
93- Must use `ComputerMemory &` parameter, not custom structs
94- Use `formatMove(row, col)` helper to convert coordinates to string format
95- Result constants available: `HIT`, `MISS`, `SUNK` from `kasbs.h`
96- Grid size constant: `BOARDSIZE` from `kasbs.h`
97
98## Testing Flow
99
1001. Student uploads file via SCP → saved to `./submissions/username/`
1012. Student SSH in and selects "Test Submission"
1023. Worker picks up pending submission
1034. Compiles with battleship library: `g++ battle_light.cpp battleship_light.cpp memory_functions_*.cpp`
1045. Runs benchmark: `./battle --benchmark 100`
1056. Parses results and updates database
1067. Leaderboard shows updated rankings
107
108## Configuration
109
110Edit `runner.go` line 11:
111```go
112const battleshipRepoPath = "/path/to/cs1210-battleship"
113```
114
115## Building
116
117```bash
118make build # Build binary
119make run # Build and run
120make gen-key # Generate SSH host key
121```
122
123## Deployment
124
125See `Dockerfile`, `docker-compose.yml`, or `battleship-arena.service` for systemd.
126
127Web runs on port 8080, SSH on port 2222.
128
129## Performance Stages
130
131Submissions are categorized into stages based on average moves per game:
132
133- **Expert** (<85 moves): Significantly better than random shooting
134- **Advanced** (85-95 moves): Better than random shooting
135- **Intermediate** (95-99 moves): Around random shooting performance
136- **Beginner** (≥99 moves): Worse than random shooting
137
138*Benchmark: Pure random shooting averages 95.5 moves over 1000 games (range: 64-100)*