import java.awt.*;

// The Agent World.
//


import java.awt.*;
import java.io.*;
import AgentWorld.*;

public class RunAgentWorld 
{
  public static void main(String args[])
  { boolean barrenWorld = false; // Set this to 'true' to train a single player 
                                 // to learn to avoid the walls. 

    try 
    { // Need an AgentWindow instance with which to communicate.
      // This argument indicates whether the game is being displayed.
      // (you might wish to turn this off to conservce cpu cycles for training).
      AgentWindow aw = new AgentWindow(true);

      // Create some players that simply do random walks.
      // Notice you can specify the colors for players,
      // which will otherwise default depending on the player type.
      if (!barrenWorld) aw.addRandomWalker("Alice", Color.pink);
      //if (!barrenWorld) aw.addRandomWalker("Bob",   Color.cyan);

      // Create a malicious player that chases other players.
      //if (!barrenWorld) aw.addAssassin("The Jackal");

      // Start with the sensors being displayed for the next player,
      // which has a hand-coded 'brain' of reasonable cleverness.
      if (!barrenWorld) aw.addSmartPlayer("a Smart Player",  Color.yellow);
 
      // This player will follow the mouse whenever the mouse button is down.
      // (You may wish to only display what this player sees, and then see
      // how high you can score do guiding it from its perspective.
      // The ability to maneuver a player is also useful for debugging.)
      //aw.addFollowMousePlayer("The Pied Piper"); 

      if (!barrenWorld) aw.addPlayer(new SamplePlayer(aw), "Geisler Player", Color.blue);
	  if (!barrenWorld) aw.addPlayer(new GeislerPlayer(aw), "Geisler Player 2", Color.cyan);
		  if (!barrenWorld) aw.addPlayer(new GeislerPlayerMem(aw), "Geisler Player w/mem", Color.green);

      // Add some players whose scores aren't reported on the score board.
      //if (!barrenWorld) aw.addAnonymousAssassins(1);
      //if (!barrenWorld) aw.addAnonymousSmartPlayers(1);
      if (!barrenWorld) aw.addAnonymousRandomWalkers(1);

      if (!barrenWorld) aw.addMinerals(   50); // Can't have more than 100 of either of these,
      if (!barrenWorld) aw.addVegetables(100); // nor more than 25 players.

      // At some point we may try to have a competition among the 
      // players trained (via RL) by various students.  Since the
      // training and 'testing' environments, should be approximately
      // equivalent, we'll define the basic initial configuration to have:
      //
      //          7 Players (with exactly 3 Assassin's & 0 FollowMouse's)
      //         50 Minerals
      //        100 Vegetables
      //
      // Of course the intelligence of the players will vary.

      // The "game manager" sleeps at most this long (in msec) for all the 
      // players to choose their moves.  Players that aren't ready continue
      // in the same direction as their last choice. You may wish to adjust
      // this depending on the speed of your code/machine and the number of
      // players.  (If all players are ready, the simulator proceeds without
      // waiting for the duration to expire, so it isn't too harmful to set
      // this high.  However, the player threads seem to die/hang for no
      // [obvious] reason; if a player times-out too many times in a row,
      // its thread will automatically be recreated, and a low time-out
      // causes this detection and restarting to be accomplished faster.)
      aw.setClockPeriod(150);

      // You can request that the 'manager' wait for you to 
      // press GO before each move.
      aw.setSingleStepMode(false); // The default setting is also false.

      // The following will play the specified number of games,
      // where each game last for the stated number of steps.
      // Each game starts in a new randomized initial configuration.
      // The mean score is reported for each player at the end.
      // We'll say that games always end after 5000 units of time,
      // since the optimal behavior to learn depends on game length.
      // (This command also automatically pushes the Start button.)
      if (!barrenWorld) aw.playThisManyGamesEachOfThisManyTimeSteps(100, 5000);

      // If the above line is commented out, then you can choose
      // the initial configuration before pushing the Start button.
    }
    
    catch(Exception e)
    {
      Utils.println("Exception encountered in main method: " + e);
      Utils.println("The following indicates the location of the problem:");
      e.printStackTrace(System.err);
      Utils.exit(-1);
    }
     
  }

}
