static void Main(string[] args) { Player p1 = new Player("David", SpaceType.Player1, PlayerColor.Red); Player p2 = new Player("Paul", SpaceType.Player2, PlayerColor.Blue); Game plop = new Game(p1, p2); Position pos1 = new Position(); pos1.row = 3; pos1.col = 4; Position pos2 = new Position(); pos2.row = 6; pos2.col = 4; plop.setPieceOnGrid(plop.player2Pieces[2], pos1); plop.setPieceOnGrid(plop.player1Pieces[0], pos2); plop.start(); plop.initialGrid.displayGrid(); for (int i = 1; i < 8; i++) { Position nextPos = new Position(); nextPos.row = pos1.row + 1; nextPos.col = pos1.col; switch (plop.movePiece(pos1, nextPos)) { case 1: Console.WriteLine("Piece MOVED !"); break; case 10: Console.WriteLine("WIN !!!"); break; case 20: Console.WriteLine("TIE !"); break; case 30: Console.WriteLine("LOST !!!"); break; case 50: Console.WriteLine("You found the flag !"); break; default: Console.WriteLine("Move not allowed !"); break; } pos1.row++; plop.initialGrid.displayGrid(); } //Console.ReadLine(); }
static void Main(string[] args) { Player p1 = new Player("David", SpaceType.Player1, PlayerColor.Red); Player p2 = new Player("Paul", SpaceType.Player2, PlayerColor.Blue); Game plop = new Game(p1,p2); Position pos1 = new Position(); pos1.row = 3; pos1.col = 4; Position pos2 = new Position(); pos2.row = 6; pos2.col = 4; plop.setPieceOnGrid(plop.player2Pieces[2], pos1); plop.setPieceOnGrid(plop.player1Pieces[0], pos2); plop.start(); plop.initialGrid.displayGrid(); for (int i = 1; i <8;i++ ) { Position nextPos = new Position(); nextPos.row = pos1.row+1; nextPos.col = pos1.col; switch (plop.movePiece(pos1, nextPos)) { case 1: Console.WriteLine("Piece MOVED !"); break; case 10: Console.WriteLine("WIN !!!"); break; case 20: Console.WriteLine("TIE !"); break; case 30: Console.WriteLine("LOST !!!"); break; case 50: Console.WriteLine("You found the flag !"); break; default: Console.WriteLine("Move not allowed !"); break; } pos1.row++; plop.initialGrid.displayGrid(); } Console.ReadLine(); }
static void Main(string[] args) { Player p1 = new Player("David", SpaceType.Player1, PlayerColor.Red); Player p2 = new Player("Paul", SpaceType.Player2, PlayerColor.Blue); Game plop = new Game(p1, p2); Position pos1 = new Position(); pos1.row = 0; pos1.col = 0; Position pos2 = new Position(); pos2.row = 6; pos2.col = 4; //plop.setPieceOnGrid(plop.player2Pieces[0], pos1); //plop.setPieceOnGrid(plop.player1Pieces[0], pos2); //plop.initPlayerPieces(p1, p2); // set up a complete board //int numPieces = plop.player1Pieces.Count(); //plop.setPieceOnGrid(plop.player2Pieces[3], pos1); int pieceIndex = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 4; j++) { Position posB = new Position(); // player 2 posB.row = j; posB.col = i; plop.setPieceOnGrid(plop.player2Pieces[pieceIndex], posB); // Player 1 Position posA = new Position(); posA.row = 9 - j; posA.col = 9 - i; plop.setPieceOnGrid(plop.player1Pieces[pieceIndex], posA); pieceIndex++; // go to next piece } } plop.start(); //plop.initialGrid.displayGrid(); // check the player's piece lists foreach (var p in plop.player1Pieces) { p.displayPiece(); } Console.WriteLine("Player 2"); foreach (var p in plop.player2Pieces) { p.displayPiece(); } plop.initialGrid.displayGrid(); /* Test the getMoves() function */ Position flag2Pos = new Position(); flag2Pos.col = 0; flag2Pos.row = 3; int rc; // return code List <Position> flagMoves = plop.getMoves(flag2Pos, out rc); Console.WriteLine(rc); foreach (var p in flagMoves) { Console.WriteLine("row: {0}", p.row); Console.WriteLine("col: {0}", p.col); Console.WriteLine(); } Position marsh2Pos = new Position(); marsh2Pos.col = 1; marsh2Pos.row = 3; List <Position> marshMoves = plop.getMoves(marsh2Pos, out rc); Console.WriteLine("Marshall"); Console.WriteLine(rc); foreach (var p in marshMoves) { Console.WriteLine("row: {0}", p.row); Console.WriteLine("col: {0}", p.col); Console.WriteLine(); } //Console.Write(plop.initialGrid.mainGrid[0,6]._piece.displayPiece()); /* Test a WIN */ /* * int column = 0; * Position start1 = new Position(); * start1.col = column; * start1.row = 6; * //Position next1 = new Position(); * //next1.col = column; * //next1.row = start1 * for (int i = 0; i < 3; i++) { * // move player 1 * Position next = new Position(); * next.row = 5-i; * next.col = column; * switch (plop.movePiece(start1, next)) * { * case 1: Console.WriteLine("Piece MOVED !"); * break; * case 10: Console.WriteLine("WIN !!!"); * break; * case 20: Console.WriteLine("TIE !"); * break; * case 30: Console.WriteLine("LOST !!!"); * break; * case 50: Console.WriteLine("You found the flag !"); * break; * default: Console.WriteLine("Move not allowed !"); * break; * } * plop.initialGrid.displayGrid(); * start1.row = next.row; // update * } */ // test movement /* * Position firstPos = new Position(); * firstPos.row = 3; * firstPos.col = 1; * Position nextPos = new Position(); * nextPos.row = 4; * nextPos.col = 1; * switch (plop.movePiece(firstPos, nextPos)) * { * case 1: Console.WriteLine("Piece MOVED !"); * break; * case 10: Console.WriteLine("WIN !!!"); * break; * case 20: Console.WriteLine("TIE !"); * break; * case 30: Console.WriteLine("LOST !!!"); * break; * case 50: Console.WriteLine("You found the flag !"); * break; * default: Console.WriteLine("Move not allowed !"); * break; * } * plop.initialGrid.displayGrid(); * * // another move * firstPos.row = nextPos.row; * firstPos.col = nextPos.col; * nextPos.row = 5; * switch (plop.movePiece(firstPos, nextPos)) * { * case 1: Console.WriteLine("Piece MOVED !"); * break; * case 10: Console.WriteLine("WIN !!!"); * break; * case 20: Console.WriteLine("TIE !"); * break; * case 30: Console.WriteLine("LOST !!!"); * break; * case 50: Console.WriteLine("You found the flag !"); * break; * default: Console.WriteLine("Move not allowed !"); * break; * } * plop.initialGrid.displayGrid(); * * for (int i = 1; i <8;i++ ) * { * Position nextPos = new Position(); * nextPos.row = pos1.row+1; * nextPos.col = pos1.col; * switch (plop.movePiece(pos1, nextPos)) * { * case 1: Console.WriteLine("Piece MOVED !"); * break; * case 10: Console.WriteLine("WIN !!!"); * break; * case 20: Console.WriteLine("TIE !"); * break; * case 30: Console.WriteLine("LOST !!!"); * break; * case 50: Console.WriteLine("You found the flag !"); * break; * default: Console.WriteLine("Move not allowed !"); * break; * } * pos1.row++; * plop.initialGrid.displayGrid(); * } */ //Console.ReadLine(); }
/* * static int distance(Position pos1, Position pos2) * { * return Math.Abs(pos1.row - pos2.row) + Math.Abs(pos1.col - pos2.col); * } */ static void setUpBoard() { /* Initial Set up * 1. FLAG: goes in back two rows * 2. BOMBS: 2-3 go near FLAG, rest go in rows 2-3 * 3. SCOUTS: Go in front 2 rows * 4. MINERS: Go anywhere but front row * 5. Everything else is RANDOM */ // First determine flag position 0 <= flagPos <= 19 // in back two rows Random rnd = new Random(); // random number generator // Make lists of all available positions for each player, updated during process List <Position> availableP1 = new List <Position>(); List <Position> availableP2 = new List <Position>(); // lists of all used positions for (int i = 0; i < 4; i++) { for (int j = 0; j < 10; j++) { // availableP2.Add(new Position(i, j)); availableP1.Add(new Position(9 - i, 9 - j)); } } //Console.WriteLine(availableP2.Count); /* Flags First playerXPieces[3] ------------------------------------------ */ //Position flag2Pos = new Position(); int flag2Index = rnd.Next(19); Position flag2Pos = availableP2[flag2Index]; p2.flagPos = flag2Pos; // SETTING FOR THE PLAYER //flag2Pos.row = flag2Index / 10; //flag2Pos.col = flag2Index % 10; plop.setPieceOnGrid(plop.player2Pieces[3], flag2Pos); availableP2.RemoveAt(flag2Index); //Position flag1Pos = new Position(); int flag1Index = rnd.Next(19); Position flag1Pos = availableP1[flag1Index]; p1.flagPos = flag1Pos; // SETTING FOR THE PLAYER!!!!! //flag1Pos.row = flag1Index / 10; //flag1Pos.col = flag1Index % 10; plop.setPieceOnGrid(plop.player1Pieces[3], flag1Pos); availableP1.RemoveAt(flag1Index); //Console.WriteLine("Done with flag..."); int numBombs = rnd.Next(2) + 2; // number of bombs for flag, 2 or 3 List <Position> bombs = new List <Position>(); List <Position> possibleBombs = new List <Position>(); if (flag2Pos.col == 0) { // edge or corner possibleBombs.Add(new Position(flag2Pos.row + 1, flag2Pos.col)); possibleBombs.Add(new Position(flag2Pos.row, flag2Pos.col + 1)); possibleBombs.Add(new Position(flag2Pos.row + 1, flag2Pos.col + 1)); } else if (flag2Pos.col == 9) { // Other edge or corner possibleBombs.Add(new Position(flag2Pos.row + 1, flag2Pos.col)); possibleBombs.Add(new Position(flag2Pos.row, flag2Pos.col - 1)); possibleBombs.Add(new Position(flag2Pos.row + 1, flag2Pos.col - 1)); } else { possibleBombs.Add(new Position(flag2Pos.row, flag2Pos.col - 1)); possibleBombs.Add(new Position(flag2Pos.row, flag2Pos.col + 1)); possibleBombs.Add(new Position(flag2Pos.row + 1, flag2Pos.col - 1)); possibleBombs.Add(new Position(flag2Pos.row + 1, flag2Pos.col)); possibleBombs.Add(new Position(flag2Pos.row + 1, flag2Pos.col + 1)); } // actually add the bombs to list int index; for (int i = 0; i < numBombs; i++) { index = rnd.Next(possibleBombs.Count); bombs.Add(possibleBombs[index]); // add the chosen pos availableP2.Remove(possibleBombs[index]); possibleBombs.RemoveAt(index); // then remove that pos from the list of possibles } //Console.WriteLine("Done with first bombs..."); int bombIndex = 34; // first bomb in list foreach (var p in bombs) { plop.setPieceOnGrid(plop.player2Pieces[bombIndex], p); bombIndex++; } //Console.WriteLine("Doing random bombs..."); // Place the rest of the bombs, go anywhere but row 1 for (int i = 0; i < (6 - numBombs); i++) { index = rnd.Next(28 - numBombs); plop.setPieceOnGrid(plop.player2Pieces[bombIndex], availableP2[index]); availableP2.RemoveAt(index); } //Console.WriteLine(availableP2.Count); // PLAYER 1 ----------------------------------------------------- numBombs = rnd.Next(2) + 2; // number of bombs for flag, 2 or 3 bombs = new List <Position>(); possibleBombs = new List <Position>(); if (flag1Pos.col == 0) { // edge or corner possibleBombs.Add(new Position(flag1Pos.row - 1, flag1Pos.col)); possibleBombs.Add(new Position(flag1Pos.row, flag1Pos.col + 1)); possibleBombs.Add(new Position(flag1Pos.row - 1, flag1Pos.col + 1)); } else if (flag1Pos.col == 9) { // Other edge or corner possibleBombs.Add(new Position(flag1Pos.row - 1, flag1Pos.col)); possibleBombs.Add(new Position(flag1Pos.row, flag1Pos.col - 1)); possibleBombs.Add(new Position(flag1Pos.row - 1, flag1Pos.col - 1)); } else { possibleBombs.Add(new Position(flag1Pos.row, flag1Pos.col - 1)); possibleBombs.Add(new Position(flag1Pos.row, flag1Pos.col + 1)); possibleBombs.Add(new Position(flag1Pos.row - 1, flag1Pos.col - 1)); possibleBombs.Add(new Position(flag1Pos.row - 1, flag1Pos.col)); possibleBombs.Add(new Position(flag1Pos.row - 1, flag1Pos.col + 1)); } // actually add the bombs to list for (int i = 0; i < numBombs; i++) { index = rnd.Next(possibleBombs.Count); bombs.Add(possibleBombs[index]); // add the chosen pos availableP1.Remove(possibleBombs[index]); possibleBombs.RemoveAt(index); // then remove that pos from the list of possibles } //Console.WriteLine("plop.player1Pieces: {0}", plop.player1Pieces.Count); bombIndex = 34; // first bomb in list foreach (var p in bombs) { plop.setPieceOnGrid(plop.player1Pieces[bombIndex], p); bombIndex++; } // Place the rest of the bombs, go anywhere but row 1 for (int i = 0; i < (6 - numBombs); i++) { index = rnd.Next(28 - numBombs); plop.setPieceOnGrid(plop.player1Pieces[bombIndex], availableP1[index]); availableP1.RemoveAt(index); } //Console.WriteLine(availableP1.Count); List <List <Piece> > playerPieceLists = new List <List <Piece> >(); playerPieceLists.Add(plop.player1Pieces); playerPieceLists.Add(plop.player2Pieces); foreach (var pieces in playerPieceLists) { List <Position> available = new List <Position>(); if (pieces == plop.player1Pieces) { available = availableP1; } else { available = availableP2; } /* Now for SCOUTS, playerXPieces[26 - 33]*/ int scoutIndex = 26; // first scout in list int count = 20; for (int i = 0; i < 8; i++) { index = available.Count - rnd.Next(count) - 1; plop.setPieceOnGrid(pieces[scoutIndex], available[index]); available.RemoveAt(index); scoutIndex++; count--; } /* Now for MINERS, playerXPieces[21-] * could be 10 spots left in first row */ int minerIndex = 21; count = 10; for (int i = 0; i < 5; i++) { index = rnd.Next(available.Count - count); plop.setPieceOnGrid(pieces[minerIndex], available[index]); available.RemoveAt(index); minerIndex++; //count--; } /* Now do the rest of the pieces, should be RANDOM! */ for (int i = 0; i < 21; i++) { if (i != 3) { index = rnd.Next(available.Count); // random remaining position plop.setPieceOnGrid(pieces[i], available[index]); available.RemoveAt(index); } } } }
static void Main(string[] args) { Player p1 = new Player("P1", SpaceType.Player1, PlayerColor.Red); Player p2 = new Player("P2", SpaceType.Player2, PlayerColor.Blue); Game plop = new Game(p1, p2); Position pos1 = new Position(); pos1.row = 0; pos1.col = 0; Position pos2 = new Position(); pos2.row = 6; pos2.col = 4; int pieceIndex = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 4; j++) { Position posB = new Position(); // player 2 posB.row = j; posB.col = i; plop.setPieceOnGrid(plop.player2Pieces[pieceIndex], posB); // Player 1 Position posA = new Position(); posA.row = 9 - j; posA.col = 9 - i; plop.setPieceOnGrid(plop.player1Pieces[pieceIndex], posA); pieceIndex++; // go to next piece } } plop.start(); // start the game // check the player's piece lists foreach (var p in plop.player1Pieces) { p.displayPiece(); } Console.WriteLine("Player 2"); foreach (var p in plop.player2Pieces) { p.displayPiece(); } // display the initial grid plop.initialGrid.displayGrid(); // Test random movement int rc; // return code, needed for getMoves() Random rnd = new Random(); // random number generator int numMoves = 5; // how many moves do you want to test??? Position pos = new Position(); // initial position // this position will be where player 2s leftmost miner is, next to their flag // note that all movement is based on position, whatever piece is at that position will be moved. pos.row = 3; pos.col = 1; Position nextPos = new Position(); int moveIndex; // this helps choose a random move from the list of possible moves at a given state for (int i = 0; i < numMoves; i++) { List <Position> moves = plop.getMoves(pos, out rc); Console.WriteLine("Possible moves at {0}", i); foreach (var p in moves) { Console.WriteLine("row: {0}", p.row); Console.WriteLine("col: {0}", p.col); Console.WriteLine(); } moveIndex = rnd.Next(moves.Count); // random number no bigger than size of list Position next = nextPos = moves[moveIndex]; // update position // movePiece() moves whatever piece is at pos to next. // it returns a numeric code that represents what happened at the move. switch (plop.movePiece(pos, next)) { case 1: Console.WriteLine("Piece MOVED !"); break; case 10: Console.WriteLine("WIN !!!"); break; case 20: Console.WriteLine("TIE !"); break; case 30: Console.WriteLine("LOST !!!"); break; case 50: Console.WriteLine("You found the flag !"); break; default: Console.WriteLine("Move not allowed !"); break; } plop.initialGrid.displayGrid(); // show the grid pos = next; // update the piece's current position } }