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// Diagonal AI - shoots in diagonal patterns
9void initMemoryDiagonal(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 smartMoveDiagonal(const ComputerMemory &memory) {
26 if (memory.mode == RANDOM) {
27 // Shoot in diagonal pattern first
28 for (int i = 0; i < BOARDSIZE; i++) {
29 for (int j = 0; j < BOARDSIZE; j++) {
30 if ((i + j) % 3 == 0 && memory.grid[i][j] == EMPTY_MARKER) {
31 char letter = static_cast<char>('A' + i);
32 return string(1, letter) + to_string(j + 1);
33 }
34 }
35 }
36
37 // Fallback to any 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
48 // Target mode - shoot adjacent cells
49 int directions[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
50 for (int d = 0; d < 4; d++) {
51 int newRow = memory.hitRow + directions[d][0];
52 int newCol = memory.hitCol + directions[d][1];
53
54 if (newRow >= 0 && newRow < BOARDSIZE && newCol >= 0 && newCol < BOARDSIZE &&
55 memory.grid[newRow][newCol] == EMPTY_MARKER) {
56 char letter = static_cast<char>('A' + newRow);
57 return string(1, letter) + to_string(newCol + 1);
58 }
59 }
60
61 return "A1";
62}
63
64void updateMemoryDiagonal(int row, int col, int result, ComputerMemory &memory) {
65 memory.lastResult = result;
66 char marker;
67 if (isAMiss(result)) {
68 marker = MISS_MARKER;
69 } else {
70 marker = HIT_MARKER;
71 }
72 memory.grid[row][col] = marker;
73
74 if (memory.mode == RANDOM && !isAMiss(result)) {
75 memory.mode = SEARCH;
76 memory.hitRow = row;
77 memory.hitCol = col;
78 } else if (isASunk(result)) {
79 memory.mode = RANDOM;
80 memory.hitRow = -1;
81 memory.hitCol = -1;
82 }
83}