/*
* BlindEyes 0.1
* Random moves
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int main()
{
// Variables used in the IO proces
char input[4][27]; // 4 Lines of viewing information unparsed
// We get a maximum of 25 characters from the competition
// enviroment, we need 2 for the newline and \0
int oppDist; // Square of the distance to the opponent (parsed)
char myMove[257]; // Buffer for the Move we do (we can do just 256 steps
// each turn + \0 = 257 characters)
int myMoveLength; // length of the Move we do
// Variables used in the algorithm
int direction; // What is the direction we are going to move
// 0 - straight ahead
// 1 - right
// 2 - backwards
// 3 - left
int steps; // number of steps we were capable of doing in the chosen direction
// Initialize rand using the time to get random results
srand((int)time(NULL));
// Read first line and check whether we are the starting player
scanf("%s", &input[0][0]);
if (strcmp(&input[0][0], "Start") == 0)
{
// We have read start so this is not the first line of viewing information
// read that line now
scanf("%s", &input[0][0]);
}
// if we didn't read start as first line it will be viewing information
while (1)
{
// Read the remaining lines of viewing information
scanf("%s", &input[1][0]);
scanf("%s", &input[2][0]);
scanf("%s", &input[3][0]);
// Read the distance to the Opponent
scanf("%d", &oppDist);
/* Code to decide move starts here */
/*
myMove[0] = 'T'; // Do a Turn move, this is guaranteed to be possible
myMoveLength = 1; // We have character in myMove
*/
direction = rand() % 4; // Select direction to walk in
// If there is no opening in the current side we pick the next
while (input[direction][0] == 'W')
{
direction++;
if (direction == 4)
direction = 0; // wrap round, limit to 0-3
}
// Take on step in the direction chosen
switch(direction)
{
case 0: // forward
myMove[0] = 'F';
break;
case 1: // right
myMove[0] = 'R';
break;
case 2: // backwards
myMove[0] = 'T';
break;
case 3: // left
myMove[0] = 'L';
break;
}
// make more steps till we can go left or right or meet an endwall
steps = 1;
while (input[direction][steps] == 'N') // if it isnt N it either has a gap
// or is an endwall
{
myMove[steps] = 'F';
steps++;
}
// We have exactly steps characters in myMove so its length is equal to steps
myMoveLength = steps;
/* Code to decide move ends here */
myMove[myMoveLength] = '\0'; // Finish our move string with a null character
// (for printf)
printf("%s\n", myMove); // Report our move back to the caiaio
fflush(stdout); // make sure the software gets our output
// Check for a quit message
scanf("%s", &input[0][0]);
if (strcmp(&input[0][0], "Quit") == 0)
{
return 0;
}
// Input[0][0] is not a quit message thus it is the first line of the viewing info
// so we are in the same state as at the begining of the loop
}
}
syntax highlighted by Code2HTML, v. 0.9.1