forked from DpEpsilon/DpJuice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
overrun_example.cpp
103 lines (82 loc) · 2.27 KB
/
overrun_example.cpp
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
/*
* This example creates whatever it can make and moves around randomly.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "overrun.h"
struct unit {
int ownerID;
int unitID;
int x;
int y;
int level;
};
struct unitOnSquare {
int ownerID;
int unitID;
int level; // A level 0 unit means one does not exist on that square.
};
int amountOfPlayers;
int size;
int playersMinerals[MAX_PLAYERS];
int terrain[MAX_SIZE][MAX_SIZE];
struct unitOnSquare whatOnSquare[MAX_SIZE][MAX_SIZE];
int myID;
// Number of units in the game. We reset this after every turn
int numUnits;
struct unit allUnits[MAX_SIZE * MAX_SIZE];
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
// AI logic will mostly go here.
void clientDoTurn() {
int i, j;
for (i = 0; i < numUnits; i++) {
// It is my unit
if (allUnits[i].ownerID == myID) {
// Move randomly
move (allUnits[i].unitID, rand () % 5);
}
}
// Finally, toss a coin to decide to build a dude.
if (rand () % 2 == 0) {
// Build with some minerals we have
build (rand () % playersMinerals[myID]);
}
// We now reset the data we have stored to get the new data next round.
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
whatOnSquare[i][j].level = 0; // We erase eveything set on squares
}
}
numUnits = 0; // This will erase all the units we stored in allUnits.
}
void clientRegister() {
// We need to call setName ()
setName ("Randombot");
// We also want to seed the random generator
srand (time (NULL));
}
// All of these function simply get data into our AI
void clientInit(int playerCount, int boardSize, int playerID) {
amountOfPlayers = playerCount;
size = boardSize;
myID = playerID;
numUnits = 0;
}
void clientJuiceInfo(int pid, int juiceCount) {
playersMinerals[pid] = juiceCount;
}
void clientTerrainInfo(int x, int y, int type) {
terrain[y][x] = type;
}
void clientStudentLocation(int pid, int id, int x, int y, int level) {
whatOnSquare[y][x].ownerID = pid;
whatOnSquare[y][x].unitID = id;
whatOnSquare[y][x].level = level;
allUnits[numUnits].ownerID = pid;
allUnits[numUnits].unitID = id;
allUnits[numUnits].x = x;
allUnits[numUnits].y = y;
numUnits++;
}