// skeleton.cpp
// Nanobots
// 1999 High School Programming Contest Take Home Problem
//
// Here's a basic skeleton that you can use to write your bot.  Routines for
// all input and output are provided as well as a basic main() for you to
// expand.
//
// You may modify any part of this file as you see fit.
//
// To write a nanobot:
//  1. Read description.html
//  2. Read readme.txt
//  3. Become famaliar with this file (look at the Global Variables and
//     functions provided.
//  4. Fill out the skeleton with your own code (see !!! comments)

#include <iostream.h>
#include <stdlib.h>

// Maximum map size
#define MAXMAP 252

// Global Variables
// mapWidth - the width of the input map
// mapHeight - the hieght of the input map
// fuel - the amount of fuel the nanobot has
// map - a two dimensional array holding the map.  The first index is row,
//       the second column (map[y][x]), the upper left corner is (0,0).
// baseX - the X coordinate of the base
// baseY - the Y coordinate of the base
int  mapWidth, mapHeight, fuel;
char map[MAXMAP][MAXMAP];
int  baseX, baseY;

// Misc. Functions
// bomb(char*)          - Display an error message and exit.
// acquireMap()         - Read the map from cin
void bomb( char *message );
void acquireMap();

// Movement Functions
// Call these function to send the appropriate output for moving in
// each direction.
void MoveNorth();
void MoveSouth();
void MoveEast();
void MoveWest();

// Action Functions
// These are the other two actions your rover can do.
void TakeMolecule();
void EndRun();

//////////////////////////////////////////////////////////////////////

// !!! - Put your datatypes here!

// !!! - Put your globals here!

// !!! - Put your function declarations here!
#include <stdio.h>
// main
void main() 
{
  // Read in the map.
  acquireMap();
  
  // !!! - Your Code Goes Here!
}

// !!! - Your functions go here!

//////////////////////////////////////////////////////////////////////
// Provided Code
// Edit the code below at your own risk.
//////////////////////////////////////////////////////////////////////

// bomb(char*)
void bomb( char *message ) 
{
  cerr << "fatal error: " << message << endl << endl;
  exit(1);
}

// acquireMap()
// These reads the input from cin and sets up the global variables.
void acquireMap()
{
  char l[MAXMAP+2];

  // reads in the map from standard input.
  cin >> mapWidth >> mapHeight >> fuel;
  
  if ((mapWidth  < 3) || (mapWidth  > MAXMAP)  ||
      (mapHeight < 3) || (mapHeight > MAXMAP) ||
      (fuel <= 0)) {
    bomb( "Invalid map (bad width, height and/or fuel specs.)" );
  }

  // clear the map file memory
  for (int i = 0; i < mapHeight; i++) {
    for (int j = 0; j < mapWidth; j++) {
      map[i][j] = 'X';
    }
  }
	
  // input map into array
  baseX = -1;
  baseY = -1;
  for (int i = 0; i < mapHeight; i++) {
    cin.getline(l,MAXMAP);
    if (l[0] == '\n' || l[0]=='\r' || l[0] == '\0') {
      i--;
      continue;
    }
    for (int j=0;j<mapWidth+2;j++) {
      map[i][j]=l[j];
      if (map[i][j] == 'B') {
	baseX=j;
	baseY=i;
      }
    }
  }

  // check for no base
  if (baseX == -1) {
    bomb( "no base found in map." );
  }
	
}

// output functions
void MoveNorth() {
  cout << "NORTH" << endl;
}

void MoveSouth() {
  cout << "SOUTH" << endl;
}

void MoveEast() {
  cout << "EAST" << endl;
}

void MoveWest() {
  cout << "WEST" << endl;
}

void TakeMolecule() {
  cout << "TAKE" << endl;
}

void EndRun() {
  cout << "END" << endl;
}

