-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.html
311 lines (253 loc) · 10.5 KB
/
doc.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<html>
<head>
<title>PHAIS: April 2015</title>
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700'
rel='stylesheet' type='text/css'>
<style>
@font-face {
font-family: 'Droid Sans';
font-weight: normal;
font-style: normal;
}
body {
background: #000033; padding: 10px 100px 100px 100px;
font-family: 'Droid Sans';
font-size: 18px;
color: #ffffff}
p {margin-left: 20; }
pre {margin: -8px 40px 8px 40px; padding: 4px 8px; background:
#333333; }
h1 {font-size: 400%; font-weight: bold; margin-bottom: 10px; text-align: center;}
h2 {font-size: 250%; margin-bottom: -10px; margin-top: 20px;}
h3 {font-size: 150%; margin-bottom: -10px; margin-top: -5px;}
td {text-align: center; padding: 0px 8px;}
</style>
</head>
<body>
<br>
<pre style="text-align: center; background: #333355">
______|\
_.--| SAIL |:
<____|.-----||
.---''---,
;..__..' _...
,'/ ;|/..--'' \
,'_/.-/': :
_..-'''/ / | \ \ _|/|
\ /-./_ \; \ \,;' \
,\ / \: `:\ \ // `:`.
,' \ /-._; | : : :: ,. .
,' :: /`-._| | | || ' : `.`.)
_,' |;._:: | | | | `| : `'
,' `. / |`-:_ ; | | | : \
`--. ) /|-._: : | \ \
/ / :_| ;`-._; __..--'; : :
/ ( ;|;-./_ _/.-:'o | / ' |
/ , \._/_/_./--''/_|:|___|_,' |
: / `'-'--'----'---------' |
| : O ._O O_. O ._O O_. ; ;
: `. // // // // ,' /
~~~`.______//____//____//____//_______,'~
// //~ // //
~~ _// _// _// ~ _// ~
~ / / / / / / / / ~ ~~
~~~ ~~~ ~~~ ~~~
mm mmmmmm mmm mmm mm mmmmm mm
#### ##""""## ### ### #### ##"""## ####
#### ## ## ######## #### ## ## ####
## ## ####### ## ## ## ## ## ## ## ## ##
###### ## "##m ## "" ## ###### ## ## ######
m## ##m ## ## ## ## m## ##m ##mmm## m## ##m
"" "" "" """ "" "" "" "" """"" "" ""
</pre>
<p>
The game of armada is played on a square grid, with a naval fleet
of ships <b>trailing behind each other</b>, with each ship occupying
one square on the grid. To begin with, your fleet contains five ships.
</p>
<p>
You control your armada by commanding the head ship of the fleet to
move up, down, left or right on the board. (Note that the head
of the fleet cannot move into the rest of the fleet. That would
surely cause a mutiny.) If the head of your fleet crashes into the
sides of the board or into another used ship, be that in your own
fleet or someone else's, your head ship will sink, and since the
rest of the fleet are following the head... I'll leave the rest to
your imagination. At this point, your fleet is eliminated from the
game.
</p>
<p>
It will likely serve as a strategic advantage to <b>extend your
fleet</b>. This is achieved by guiding the head of your fleet into an
<b>abandoned ship</b> (affectionately known as <b>food</b>). If you
command the head of the fleet into an abandoned ship, it will become
the new head ship of your fleet, and for that move, all other ships
in your armada will remain stationary.
</p>
<h3>Victory</h3>
<p>
A armada is victorious once all the other armadas have been eliminated.
<br>
<center>
<img src="armada.png" alt="screenshot"/>
</center>
<h2>Interface</h2>
<p>Do <b>not</b> write a <i>main()</i> function, this is provided by the
<tt>armada_library.c</tt> object file. The library will connect to the
server, and communicate with the server on your AI's behalf. You must
implement the functions described below in your source file.</p>
<h3>Headers</h3>
<p>You'll need the following line to start with:</p>
<pre>#include "armada.h"</pre>
<h3>clientRegister</h3>
<p>
<i>clientRegister()</i> is called when the client first logs on to the
server. You should call <i>setName(const char* name)</i> to define
the name of your AI and <i>setColour(int r, int g, int b)</i> to
elect a preferred colour. Names can be up to 16 characters long and
colour components are between 0 and 255 inclusive.
</p>
<pre>void clientRegister(void) {
setName("BlackPerl");
setColour(41, 35, 52);
}</pre>
<h3>clientInit</h3>
<p>
<i>clientInit(int numPlayers, int boardSize, int playerID)</i> is
called at the start of a game. The argument <i>numPlayers</i>
specifies the number of players in this game. The
argument <i>boardSize</i> specifies the height/width of the game
board, which is always square. The argument <i>playerID</i>
specifies your player ID throughout the game. Any persistent data
structures that you use throughout the course of a game are best
initialised here.
</p>
<pre>void clientInit(int numPlayers, int boardSize, int playerID) {
numP = numPlayers;
size = boardSize;
myID = playerID;
// Initialise state...
int i, j;
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
board[i][j] = -1;
}
}
}</pre>
<p><i>clientInit()</i> must return with one second.</p>
<h3>clientStartPositions</h3>
<p>
<i>clientStartPositions(int playerID, int length, struct point* positions)</i>
is called at the start of a game, after clientInit is called. It will be called
once for each player in the game, informing the client of the
positions of each of the ships in the player's armada. The argument
<i>playerID</i> specifies the player whose fleet the function call refers to.
The argument <i>positions</i> will be an array of points with <i>length</i>
elements (<i>length</i> will always be 5). <i>struct point</i> is a
type which contains two variables <i>r</i> and <i>c</i> indicating
the row and column of the ship, respectively.
</p>
<pre>void clientStartPositions(int playerID, int length, struct point* positions) {
int i;
for (i = 0; i < length; i++) {
board[positions[i].r][positions[i].c] = playerID;
}
if (playerID == myID) {
myHead = positions[0];
}
}</pre>
<p><i>clientStartPositions</i> must return with one second.</p>
<h3>clientAddHead</h3>
<p>
<i>clientAddHead(int playerID, struct point position)</i> is called
before the client's turn. It will be called once for each player in
the game, informing the client of the new position of the head of
each player's fleet. The player is indicated by <i>playerID</i> and
the new head is indicated by <i>position</i>
</p>
<pre>void clientAddHead(int playerID, struct point position) {
board[position.r][position.c] = playerID;
if (playerID == id) {
myHead = position;
}
}</pre>
<p><i>clientAddHead()</i> must return with one second.</p>
<p>
<i>clientRemoveTail(int playerID, struct point position)</i> is called
before the client's turn. It will be called at most once for each
player in the game, informing the client of the movement of the tail
of each player's fleet. The player is indicated by <i>playerID</i> and
the previous position of tail is indicated by <i>position</i>
</p>
<pre>void clientRemoveTail(int playerID, struct point position) {
board[position.r][position.c] = -1;
}</pre>
<p><i>clientRemoveTail()</i> must return with one second.</p>
<h3>clientPlayerDied</h3>
<p>
<i>void clientPlayerDied(int playerID)</i> is called before the
client's turn. It is called for each player who was eliminated in
the previous turn. The argument <i>playerID</i> indicates the player
id of the eliminated fleet.
<pre>void clientPlayerDied(int playerID) {
int i, j;
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
if (board[i][j] == playerID) {
board[i][j] = -1;
}
}
}
}</pre>
<p><i>clientPlayerDied()</i> must return with one second.</p>
<h3>clientFoodAdded</h3>
<p>
<i>clientFoodAdded(struct point position)</i> is called when a new
abandoned ship appears on a square. The argument <i>position</i>
describes where the new abandoned ship has been sighted.
</p>
<h3>clientDoTurn</h3>
<p>
<i>clientDoTurn()</i> is called when it's your turn to make a move. Do so by
calling <i>makeMove(int direction)</i>. Argument <i>direction</i>
should be used to specify the direction that you wish your fleet's
head to move in. (Note that directions are defined in armada.h as
UP, RIGHT, DOWN and LEFT) If you call attempt to
call <i>makeMove()</i> multiple times during your turn, only the
last value will be used. If you do not call <i>makeMove()</i>
in <i>clientDoTurn()</i>, your client will be dropped from the game
and will be recognised as having lost the game.
</p>
<p><i>clientDoTurn()</i> must return with one second.</p>
<pre>void clientDoTurn() {
makeMove(DOWN); // Quick! Run away! As far down as we can go!
// Note that this will either cause the head of the fleet to run
// into itself if the head begins upwards relative to the next
// ship in line, or it will eventually hit the bottom of the map if
// it doesn't hit another ship first.
}</pre>
<h2>Example code / compiling your code</h2>
<p>Download <tt>armada_library.c</tt> and <tt>armada.h</tt>, along with an example AI and support libraries,
from <a href='armada_client_v1.zip'>here</a>.
<p>It is recommended that you use, from the command line, <tt>gcc</tt> to compile the library and <tt>g++</tt> to compile your code.</p>
<p>Use the following line to compile the library:</p>
<pre>$ gcc armada_library.c -c -o armada_library.o</pre>
<p>Use the following line to compile your code:</p>
<pre>$ g++ <i>your_file</i>.cpp armada_library.o -o <i>your_program</i></pre>
<p>Run the program from the command line like so:</p>
<pre>$ <i>your_program</i> <i>ip</i></pre>
<h2>Testing your code</h2>
<p>You can test your code by connecting to the main server — look at the title bar on the projector screen.</p>
<p>If you wish to run your own server, <a href="armada-student.jar">download
the server</a> and run it using "java -jar armada-student.jar".</p>
<p>
To test your code, do the following:</p>
<ul>
<li>Run the server.
<li>Start each player.
</ul>
<p>
Type "<tt>help</tt>" to the server to find out more about the server.
</p>
<body>
</html>