a geicko-2 based round robin ranking system designed to test c++ battleship submissions battleship.dunkirk.sh
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: add directory for battleship engine

+58 -3
battleship-arena

This is a binary file and will not be displayed.

+6
flake.nix
··· 45 45 "-w" 46 46 ]; 47 47 48 + postInstall = '' 49 + mkdir -p $out/share/battleship-arena/battleship-engine 50 + cp -r ${self}/battleship-engine/src $out/share/battleship-arena/battleship-engine/ 51 + mkdir -p $out/share/battleship-arena/battleship-engine/build 52 + ''; 53 + 48 54 meta = with pkgs.lib; { 49 55 description = "SSH-based battleship tournament service"; 50 56 homepage = "https://github.com/taciturnaxolotl/battleship-arena";
+51 -2
internal/runner/runner.go
··· 14 14 "battleship-arena/internal/storage" 15 15 ) 16 16 17 - const enginePath = "./battleship-engine" 17 + var enginePath = getEnginePath() 18 + 19 + func getEnginePath() string { 20 + if path := os.Getenv("BATTLESHIP_ENGINE_PATH"); path != "" { 21 + return path 22 + } 23 + return "./battleship-engine" 24 + } 18 25 19 26 func CompileSubmission(sub storage.Submission, uploadDir string) error { 20 27 storage.UpdateSubmissionStatus(sub.ID, "testing") ··· 85 92 cpp1Path := filepath.Join(enginePath, "src", player1.Filename) 86 93 cpp2Path := filepath.Join(enginePath, "src", player2.Filename) 87 94 95 + // Ensure both files exist in engine/src (copy from uploads if missing) 96 + if _, err := os.Stat(cpp1Path); os.IsNotExist(err) { 97 + log.Printf("Player1 file missing in engine/src, skipping: %s", cpp1Path) 98 + return 0, 0, 0 99 + } 100 + 101 + if _, err := os.Stat(cpp2Path); os.IsNotExist(err) { 102 + log.Printf("Player2 file missing in engine/src, skipping: %s", cpp2Path) 103 + return 0, 0, 0 104 + } 105 + 88 106 cpp1Content, err := os.ReadFile(cpp1Path) 89 107 if err != nil { 90 108 log.Printf("Failed to read %s: %v", cpp1Path, err) ··· 151 169 return parseMatchOutput(string(output)) 152 170 } 153 171 154 - func RunRoundRobinMatches(newSub storage.Submission, broadcastFunc func(string, int, int, time.Time, []string)) { 172 + func RunRoundRobinMatches(newSub storage.Submission, uploadDir string, broadcastFunc func(string, int, int, time.Time, []string)) { 155 173 activeSubmissions, err := storage.GetActiveSubmissions() 156 174 if err != nil { 157 175 log.Printf("Failed to get active submissions: %v", err) ··· 171 189 } 172 190 173 191 if !hasMatch { 192 + // Ensure opponent file exists in engine/src 193 + opponentSrcPath := filepath.Join(uploadDir, opponent.Username, opponent.Filename) 194 + opponentDstPath := filepath.Join(enginePath, "src", opponent.Filename) 195 + 196 + if _, err := os.Stat(opponentDstPath); os.IsNotExist(err) { 197 + // Copy opponent file to engine/src 198 + opponentContent, err := os.ReadFile(opponentSrcPath) 199 + if err != nil { 200 + log.Printf("Failed to read opponent file %s: %v", opponentSrcPath, err) 201 + continue 202 + } 203 + if err := os.WriteFile(opponentDstPath, opponentContent, 0644); err != nil { 204 + log.Printf("Failed to copy opponent file to engine: %v", err) 205 + continue 206 + } 207 + 208 + // Generate opponent header if missing 209 + re := regexp.MustCompile(`memory_functions_(\w+)\.cpp`) 210 + matches := re.FindStringSubmatch(opponent.Filename) 211 + if len(matches) >= 2 { 212 + prefix := matches[1] 213 + functionSuffix, err := parseFunctionNames(string(opponentContent)) 214 + if err == nil { 215 + headerFilename := fmt.Sprintf("memory_functions_%s.h", prefix) 216 + headerPath := filepath.Join(enginePath, "src", headerFilename) 217 + headerContent := generateHeader(headerFilename, functionSuffix) 218 + os.WriteFile(headerPath, []byte(headerContent), 0644) 219 + } 220 + } 221 + } 222 + 174 223 unplayedOpponents = append(unplayedOpponents, opponent) 175 224 } 176 225 }
+1 -1
internal/runner/worker.go
··· 68 68 log.Printf("✓ Compiled %s", sub.Username) 69 69 storage.UpdateSubmissionStatus(sub.ID, "completed") 70 70 71 - RunRoundRobinMatches(sub, broadcastFunc) 71 + RunRoundRobinMatches(sub, uploadDir, broadcastFunc) 72 72 notifyFunc() 73 73 } 74 74