/**
* This example demonstrates how an Alquerque player can be made
* Alquerque is the CodeCup game 2008 (www.codecup.nl)
* The use of this file and/or ideas is not compulsory
* Left to do: eight TODOs
* This example is written by Marcel Vlastuin
* Use Caia to play Alquerque games (and more...) at your own house
* Success and a lot of joy in the contest!
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0;
#define true 1
typedef int t_player; // Use an int to store a player
typedef int t_move; // Use an int to store a move, assuming that an int is enough to store one move!
typedef int t_bool; // Use an int to store a boolean
t_player board[49]; // This solution to store the board is used in this example!
t_move translate_move_to_own_notation(char inputline[]) {
t_move move;
// TODO: TRANSLATE inputline[] INTO move
return move;
}
char *translate_move_to_text(t_move move) {
static char text[100]; // USING A static char[] HERE TO AVOID USING malloc OR SIMILAR
// TODO: TRANSLATE move INTO text[]
return text;
}
t_bool is_white_dead(void) {
t_bool yes_or_no;
// TODO: CALCULATE yes_or_no
return yes_or_no;
}
t_bool is_black_dead(void) {
t_bool yes_or_no;
// TODO: CALCULATE yes_or_no
return yes_or_no;
}
void process_whitemove(t_move move) {
// TODO: PROCESS THE move IN board[49]
}
void process_blackmove(t_move move) {
// TODO: PROCESS THE move IN board[49]
}
t_move calculate_best_whitemove(void) {
t_move move;
// TODO: CALCULATE move USING board[49]
return move;
}
t_move calculate_best_blackmove(void) {
t_move move;
// TODO: CALCULATE move USING board[49]
return move;
}
int main(void) {
t_move move;
int number_of_moves = 0;
char inputline[100];
scanf("%s", inputline);
if (!strcmp(inputline, "Start")) { // PLAY AS WHITE
do {
move = calculate_best_whitemove();
process_whitemove(move);
printf("%s\n", translate_move_to_text(move));
fflush(stdout);
if (is_black_dead()) break;
scanf("%s", inputline);
if (!strcmp(inputline, "Quit")) break;
move = translate_move_to_own_notation(inputline);
process_blackmove(move);
} while (++number_of_moves < 100);
} else { // PLAY AS BLACK
while (true) {
move = translate_move_to_own_notation(inputline);
process_whitemove(move);
move = calculate_best_blackmove();
process_blackmove(move);
printf("%s\n", translate_move_to_text(move));
fflush(stdout);
if (++number_of_moves == 100) break;
if (is_white_dead()) break;
scanf("%s", inputline);
if (!strcmp(inputline, "Quit")) break;
}
}
return 0;
}
syntax highlighted by Code2HTML, v. 0.9.1