a geicko-2 based round robin ranking system designed to test c++ battleship submissions battleship.dunkirk.sh
1#include "battleship.h" 2#include "kasbs.h" 3#include "memory.h" 4#include <string> 5 6using namespace std; 7 8// Random AI - just picks random valid moves 9void initMemoryRandom(ComputerMemory &memory) { 10 memory.mode = RANDOM; 11 memory.hitRow = -1; 12 memory.hitCol = -1; 13 memory.hitShip = NONE; 14 memory.fireDir = NONE; 15 memory.fireDist = 1; 16 memory.lastResult = NONE; 17 18 for (int i = 0; i < BOARDSIZE; i++) { 19 for (int j = 0; j < BOARDSIZE; j++) { 20 memory.grid[i][j] = EMPTY_MARKER; 21 } 22 } 23} 24 25string smartMoveRandom(const ComputerMemory &memory) { 26 // Find all empty cells 27 for (int attempts = 0; attempts < 100; attempts++) { 28 int row = rand() % BOARDSIZE; 29 int col = rand() % BOARDSIZE; 30 31 if (memory.grid[row][col] == EMPTY_MARKER) { 32 char letter = static_cast<char>('A' + row); 33 return string(1, letter) + to_string(col + 1); 34 } 35 } 36 37 // Fallback: find first empty cell 38 for (int i = 0; i < BOARDSIZE; i++) { 39 for (int j = 0; j < BOARDSIZE; j++) { 40 if (memory.grid[i][j] == EMPTY_MARKER) { 41 char letter = static_cast<char>('A' + i); 42 return string(1, letter) + to_string(j + 1); 43 } 44 } 45 } 46 47 return "A1"; // Should never reach here 48} 49 50void updateMemoryRandom(int row, int col, int result, ComputerMemory &memory) { 51 memory.lastResult = result; 52 char marker; 53 if (isAMiss(result)) { 54 marker = MISS_MARKER; 55 } else { 56 marker = HIT_MARKER; 57 } 58 memory.grid[row][col] = marker; 59}