/*
* 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.
*/
import java.io.*;
class CodeCup
{
// Input stream tokenizer
StreamTokenizer inp;
// Constructor
CodeCup()
throws IOException
{
inp = new StreamTokenizer(new InputStreamReader(System.in));
inp.resetSyntax();
inp.whitespaceChars(0, 32);
inp.wordChars(33, 127);
}
// This functions reads the list of words
void readWordList()
throws IOException
{
InputStreamReader ir = new FileReader("words.dat");
StreamTokenizer is = new StreamTokenizer(ir);
while (is.nextToken() != StreamTokenizer.TT_EOF) {
String word = is.sval;
// TODO : store the word in some sort of list
}
ir.close();
}
// This function makes the game board empty
void initGameBoard()
{
// TODO
}
// This function selects the best possible letter
char pickLetter()
{
// TODO
return 'A';
}
// This function selects the best position for the given letter
int pickPosition(char letter)
{
// TODO
return 0;
}
// This function stores a letter at a position on the game board
void putLetterAtPosition(char letter, int position)
{
// TODO
}
// This function returns the total number of wordpoints on the board
int countTotalWordpoints()
{
// TODO
return 0;
}
// Game loop
void run()
throws IOException
{
char letter;
int position;
boolean myMove;
// Read the list of words
readWordList();
// Set the game board to its initial position
initGameBoard();
// Read the starting letter
inp.nextToken();
letter = inp.sval.charAt(0);
putLetterAtPosition(letter, 24);
// Find out who will move first
inp.nextToken();
if ( inp.sval.equals("start") ) {
myMove = true;
} else {
myMove = false;
letter = inp.sval.charAt(0);
}
// Do all moves
for (int m = 0; m < 48; m++) {
if (myMove) {
// It's my turn to pick a letter
letter = pickLetter();
position = pickPosition(letter);
putLetterAtPosition(letter, position);
// Write output
System.out.println(letter);
System.out.println(position);
System.out.flush();
// Next turn
myMove = false;
} else {
// My opponent has picked a letter
if (m > 0) {
inp.nextToken();
letter = inp.sval.charAt(0);
}
// Pick a position for the letter
position = pickPosition(letter);
putLetterAtPosition(letter, position);
// Write output
System.out.println(position);
System.out.flush();
// Next turn
myMove = true;
}
}
// NIO contestants : Output total nr of wordpoints
int wordpoints = countTotalWordpoints();
System.out.println(wordpoints);
System.out.flush();
}
// Main program function called when program starts
public static void main(String[] args) {
try {
CodeCup cc = new CodeCup();
cc.run();
} catch (IOException e) {
System.err.println(e);
}
}
}
/* End */
syntax highlighted by Code2HTML, v. 0.9.1