/*
* Example of a Lucky Words player program for the CodeCup.
*
* This only demonstrates how to do the input and output. You will
* have to write the algorithms for the game all by yourself.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
/*
* This function reads the list of words.
*/
void read_word_list(void)
{
FILE *f;
char word[8];
f = fopen("words.dat", "r");
assert(f != NULL);
while (! feof(f)) {
fscanf(f, "%s\n", word);
/* TODO : store the word in some sort of list */
}
fclose(f);
}
/*
* This function makes the game board empty.
*/
void init_game_board(void)
{
/* TODO */
}
/*
* This function selects the best possible letter and the position
* where we want to put it.
*/
void pick_letter_and_position(char *letter, int *position)
{
/* TODO */
}
/*
* This function returns the best possible position for an opponent letter.
*/
int pick_position(char letter)
{
/* TODO */
}
/*
* This function stores a letter at a position on the game board.
*/
void put_letter_at_position(char letter, int position)
{
/* TODO */
}
/*
* This function returns the total number of wordpoints on the game board.
*/
int count_total_wordpoints(void)
{
/* TODO */
}
int main(void)
{
char buf[40];
char letter;
int position;
int my_move, m;
/* Read the list of words */
read_word_list();
/* Make the game board empty */
init_game_board();
/* Read the starting letter */
scanf("%s", buf);
letter = buf[0];
put_letter_at_position(letter, 24);
/* Read the first move */
scanf("%s", buf);
/* Find out who will move first */
if (strcmp(buf, "start") == 0) {
my_move = 1;
} else {
my_move = 0;
letter = buf[0];
}
/* Do all moves */
for (m = 0; m < 48; m++) {
if (my_move) {
/* It's my turn to pick a letter */
pick_letter_and_position(&letter, &position);
put_letter_at_position(letter, position);
/* Write output */
printf("%c\n", letter);
printf("%d\n", position);
fflush(stdout);
/* Next turn */
my_move = 0;
} else {
/* My opponent has picked a letter */
if (m > 0) {
scanf("%s", buf);
letter = buf[0];
}
/* Pick a position for the letter */
position = pick_position(letter);
put_letter_at_position(letter, position);
/* Write output */
printf("%d\n", position);
fflush(stdout);
/* Next turn */
my_move = 1;
}
}
/* NIO contestants : Output total nr of wordpoints */
printf("%d\n", count_total_wordpoints());
fflush(stdout);
return 0;
}
/* End */
syntax highlighted by Code2HTML, v. 0.9.1