
import java.util.*;


public class Monopoly
{
	public Random rand = new Random();
	public int[] board;
	public long[] rolls;
	public long loops = 0;

	public ChanceDeck chance;
	public ChestDeck chest;

	public Monopoly(String[] args)
	{

		board = new int[40];
		rolls = new long[20];
		chance = new ChanceDeck();
		chest = new ChestDeck();

		int num = Integer.parseInt(args[0]);

		board = game(num,board);

		printBoard();
	}


	public int roll()
	{
		int rval = Math.abs(rand.nextInt()%6)+Math.abs(rand.nextInt()%6)+2;
		rolls[rval]++;
		return(rval);
	}

	public int[] game(int count, int[] board)
	{
		int spot = 0;
		for(int x=0;x<count;x++) {
			int roll = roll();
			spot = spot+roll;
			if(spot>=40) {
				spot = spot-40;
				loops++;
			}
			board[spot]++;
			if(spot==30) {
				spot=10;
			}
			else if(spot==7 || spot==22 || spot==36) {
				int newspot = chance.getChance(spot);
				if(newspot!=spot) {
					board[newspot]++;
					spot = newspot;
				}
			}
			else if(spot==2 || spot==17 || spot==33) {
				int newspot = chest.getChest(spot);
				if(newspot!=spot) {
					board[newspot]++;
					spot = newspot;
				}
			}
		}

		return(board);
	}
	
	public void printBoard()
	{
		System.out.println("GO collect $200              = "+board[0]);
		System.out.println("Mediterreanian Ave [purple]  = "+board[1]);
		System.out.println("Community Chest 1            = "+board[2]);
		System.out.println("Baltic Ave         [purple]  = "+board[3]);
		System.out.println("INCOME TAX                   = "+board[4]);
		System.out.println("Reading Railroad    < RR >   = "+board[5]);
		System.out.println("Oriental Ave       [cyan]    = "+board[6]);
		System.out.println("Chance 1                     = "+board[7]);
		System.out.println("Vermont Ave        [cyan]    = "+board[8]);
		System.out.println("Connecticut Ave    [cyan]    = "+board[9]);
		System.out.println("Jail                         = "+board[10]);
		System.out.println("St. Charles Place  [magenta] = "+board[11]);
		System.out.println("Electic Company    (Utility) = "+board[12]);
		System.out.println("States Ave         [magenta] = "+board[13]);
		System.out.println("Virginia Ave       [magenta] = "+board[14]);
		System.out.println("Pennsylvania RR     < RR >   = "+board[15]);
		System.out.println("St James Place     [orange]  = "+board[16]);
		System.out.println("Community Chest 2            = "+board[17]);
		System.out.println("Tennessee Ave      [orange]  = "+board[18]);
		System.out.println("New York Ave       [orange]  = "+board[19]);
		System.out.println("Free Parking                 = "+board[20]);
		System.out.println("Kentucky Ave       [red]     = "+board[21]);
		System.out.println("Chance 2                     = "+board[22]);
		System.out.println("Indiana Ave        [red]     = "+board[23]);
		System.out.println("Illinois Ave       [red]     = "+board[24]);
		System.out.println("B&O Railroad        < RR >   = "+board[25]);
		System.out.println("Atlantic Ave       [yellow]  = "+board[26]);
		System.out.println("Ventnor Ave        [yellow]  = "+board[27]);
		System.out.println("Water Works        (Utility) = "+board[28]);
		System.out.println("Marvin Gardens     [yellow]  = "+board[29]);
		System.out.println("GO TO JAIL                   = "+board[30]);
		System.out.println("Pacific Ave        [green]   = "+board[31]);
		System.out.println("North Carolina Ave [green]   = "+board[32]);
		System.out.println("Community Chest 3            = "+board[33]);
		System.out.println("Pennsylvania Ave   [green]   = "+board[34]);
		System.out.println("Short Line RR       < RR >   = "+board[35]);
		System.out.println("Chance 3                     = "+board[36]);
		System.out.println("Park Place         [blue]    = "+board[37]);
		System.out.println("LUXURY TAX                   = "+board[38]);
		System.out.println("Boardwalk          [blue]    = "+board[39]);

		System.out.println("\nProperties:");
		System.out.println("purple  = "+(board[1]+board[3]));
		System.out.println("cyan    = "+(board[6]+board[8]+board[9]));
		System.out.println("magenta = "+(board[11]+board[13]+board[14]));
		System.out.println("orange  = "+(board[16]+board[18]+board[19]));
		System.out.println("red     = "+(board[21]+board[23]+board[24]));
		System.out.println("yellow  = "+(board[26]+board[27]+board[29]));
		System.out.println("green   = "+(board[31]+board[32]+board[34]));
		System.out.println("blue    = "+(board[37]+board[39]));
		System.out.println("RR      = "+(board[5]+board[15]+board[25]+board[35]));
		System.out.println("Utility = "+(board[12]+board[28]));
		System.out.println("chance  = "+(board[7]+board[22]+board[36]));
		System.out.println("chest   = "+(board[2]+board[17]+board[33]));
		System.out.println("fucked  = "+(board[4]+board[30]+board[38]));
		
		System.out.println("\nThe board was traversed a total of "+loops+" times");

		System.out.print("\nRolls: ");
		for(int x=2;x<13;x++) {
			System.out.print("("+x+")="+rolls[x]+" ");
		}
		System.out.println("\n\n");
	}

	public static void main(String[] args)
	{
		Monopoly game = new Monopoly(args);
	}








	class ChanceDeck
	{
		Vector cards;
		Vector discards;

		public ChanceDeck()
		{
			cards = new Vector();
			discards = new Vector();

			discards.addElement(new ChanceCard(0,"get out of jail free"));
			discards.addElement(new ChanceCard(0,"pay poor tax"));
			discards.addElement(new ChanceCard(0,"elected chairman of the board"));
			discards.addElement(new ChanceCard(0,"bank pays"));
			discards.addElement(new ChanceCard(0,"collect 150"));
			discards.addElement(new ChanceCard(0,"make repairs"));
			discards.addElement(new ChanceCard(1,"GO TO JAIL"));
			discards.addElement(new ChanceCard(2,"advance to go"));
			discards.addElement(new ChanceCard(3,"advance to charles"));
			discards.addElement(new ChanceCard(4,"advance to boardwalk"));
			discards.addElement(new ChanceCard(5,"advance to nearest utility"));
			discards.addElement(new ChanceCard(6,"advance to illinois"));
			discards.addElement(new ChanceCard(7,"advance to reading"));
			discards.addElement(new ChanceCard(8,"go back 3 spaces"));
			discards.addElement(new ChanceCard(9,"advance to nearest RR"));
			discards.addElement(new ChanceCard(9,"advance to nearest RR"));

			shuffle();
		}

		public void shuffle()
		{
			//			System.out.println("shuffling chance");

			Random random = new Random();
			while(discards.size()>0) {
				int index = Math.abs(random.nextInt())%discards.size();
				cards.addElement(discards.elementAt(index));
				discards.removeElementAt(index);
			}
		}

		public int getChance(int location)
		{
			int rval = location;

			if(cards.size()==0) {
				shuffle();
			}
			ChanceCard card = (ChanceCard)cards.elementAt(0);
			cards.removeElementAt(0);
			discards.addElement(card);
			if(card.type==1) {
				rval = 10;
			}
			else if(card.type==2) {
				loops++;
				rval = 0;
			}
			else if(card.type==3) {
				if(location>11) {
					loops++;
				}
				rval = 11;
			}
			else if(card.type==4) {
				rval = 39;
			}
			else if(card.type==5) {
				if(location==7) {
					rval = 12;
				}
				else if(location==22) {
					rval = 28;
				}
				else if(location==36) {
					loops++;
					rval = 12;
				}
				else {
					System.out.println("I fucked up");
				}
			}
			else if(card.type==6) {
				if(location>24) {
					loops++;
				}
				rval = 24;
			}
			else if(card.type==7) {
				loops++;
				rval = 5;
			}
			else if(card.type==8) {
				rval = location-3;
			}
			else if(card.type==9) {
				if(location==7) {
					rval = 15;
				}
				else if(location==22) {
					rval = 25;
				}
				else if(location==36) {
					loops++;
					rval = 5;
				}
			}

			//			System.out.println("GOT Chance: "+card.label);


			return(rval);
		}

	}

	class ChanceCard
	{
		public int type;
		public String label;

		public ChanceCard(int cardtype, String cardname)
		{
			type = cardtype;
			label = cardname;
		}
	}


	class ChestDeck
	{
		Vector cards;
		Vector discards;

		public ChestDeck()
		{
			cards = new Vector();
			discards = new Vector();

			discards.addElement(new ChestCard(0,"second prize"));
			discards.addElement(new ChestCard(0,"bank error"));
			discards.addElement(new ChestCard(0,"life insurance"));
			discards.addElement(new ChestCard(0,"income tax refund"));
			discards.addElement(new ChestCard(0,"grand opera opening"));
			discards.addElement(new ChestCard(0,"recieve for services"));
			discards.addElement(new ChestCard(0,"you inherit"));
			discards.addElement(new ChestCard(0,"get out of jail free"));
			discards.addElement(new ChestCard(0,"street repairs"));
			discards.addElement(new ChestCard(0,"doctor's fee"));
			discards.addElement(new ChestCard(0,"pay school tax"));
			discards.addElement(new ChestCard(0,"pay hospital"));
			discards.addElement(new ChestCard(0,"xmas fund"));
			discards.addElement(new ChestCard(0,"from sale of stock"));
			discards.addElement(new ChestCard(1,"advance to go"));
			discards.addElement(new ChestCard(2,"go to jail"));

			shuffle();
		}

		public void shuffle()
		{
			//			System.out.println("shuffling chest");

			Random random = new Random();
			while(discards.size()>0) {
				int index = Math.abs(random.nextInt())%discards.size();
				cards.addElement(discards.elementAt(index));
				discards.removeElementAt(index);
			}
		}

		public int getChest(int location)
		{
			int rval = location;

			if(cards.size()==0) {
				shuffle();
			}
			ChestCard card = (ChestCard)cards.elementAt(0);
			cards.removeElementAt(0);
			discards.addElement(card);
			if(card.type==1) {
				loops++;
				location = 0;
			}
			else if(card.type==2) {
				location = 10;
			}

			//			System.out.println("GOT CommunityChest: "+card.label);

			return(rval);
		}
	}
	
	class ChestCard
	{
		public int type;
		public String label;

		public ChestCard(int cardtype, String cardname)
		{
			type = cardtype;
			label = cardname;
		}
	}
}
