// Eliminates a player by removing from active player list, adding to // eliminated player list, and returning all tiles to the draw pile public void eliminatePlayer(SPlayer p) { if ((p.playerState != SPlayer.State.Placed) && (p.playerState != SPlayer.State.Playing)) { throw new Exception("Player is being eliminated before having placed a start pawn."); } else if (!onBoard.Contains(p)) { throw new Exception("Trying to eliminate a non-active player."); } // Add eliminated player's tiles to draw pile, and remove from his/her hand if (p.getHandSize() != 0) { List <Tile> hand = p.returnHand(); int handSize = hand.Count; for (int i = 0; i < hand.Count; i++) { Tile tempTile = hand[i]; p.removeTileFromHand(tempTile); addTileToDrawPile(tempTile); i--; } } int onBoardIndex = onBoard.FindIndex(x => p.returnColor() == x.returnColor()); if (dragonTileHolder != null && dragonTileHolder.returnColor() == p.returnColor()) { // Pass dragon tile to next player with less than 3 tiles in hand int currIndex = onBoardIndex; SPlayer nextPlayer; do { currIndex += 1; nextPlayer = onBoard[(currIndex) % onBoard.Count]; } while (nextPlayer.getHandSize() >= 3); if (nextPlayer.returnColor() == p.returnColor()) { dragonTileHolder = null; } else { dragonTileHolder = nextPlayer; } } eliminated.Add(p); onBoard.Remove(p); p.eliminate(); }
public static XElement splayerToXML(SPlayer player, Board board) { XElement splayerXML; if (board.existsDragonTileHolder() && board.isDragonTileHolder(player.returnColor())) { splayerXML = new XElement("splayer-dragon"); } else { splayerXML = new XElement("splayer-nodragon"); } XElement handTileXML = playerHandToXML(player.returnHand()); splayerXML.Add(new XElement("color", player.returnColor()), handTileXML); return(splayerXML); }
public override Tile playTurn(Board b, List <Tile> playerHand, int numTilesInDrawPile) { List <Tile> validMoves = new List <Tile>(); List <Tile> allMoves = new List <Tile>(); Tile toPlayTile; if (playerHand.Count == 0) { throw new Exception("player hand is empty"); } else { foreach (Tile t in playerHand) { int timesRotated = 0; Tile checkTile = t.rotate(); while (timesRotated < 4) { SPlayer currPlayer = b.getActiveSPlayer(color); if (currPlayer.returnColor() == null) { throw new Exception("Player not found on board!"); } if (b.isNotEliminationMove(currPlayer, checkTile)) { validMoves.Add(checkTile); break; } else { checkTile = checkTile.rotate(); timesRotated = timesRotated + 1; } allMoves.Add(checkTile); } } if (validMoves.Count == 0) { Random rAll = new Random(); int rIntAll = rAll.Next(0, allMoves.Count); toPlayTile = playerHand.Find(x => x.isEqual(allMoves[rIntAll])); return(allMoves[rIntAll]); } Random r = new Random(); int rInt = r.Next(0, validMoves.Count); toPlayTile = playerHand.Find(x => x.isEqual(validMoves[rInt])); return(validMoves[rInt]); } }
public TurnResult playATurn(Board b, Tile t) { // Place tile on board SPlayer currentPlayer = b.getFirstActivePlayer(); b.placeTile(currentPlayer, t); // Move active players if newly placed tile affects them b.movePlayers(); bool isCurrentPlayerEliminated = b.isEliminated(currentPlayer.returnColor()); // Check if game is over if (b.isGameOver()) { return(b.GetTurnResult()); } // Players draw if (b.existsDragonTileHolder()) { b.drawTilesWithDragonHolder(); } else { if (!isCurrentPlayerEliminated) { if (b.isDrawPileEmpty()) { b.setDragonTileHolder(currentPlayer); } else { currentPlayer.addTileToHand(b.drawATile()); } } } // Update game play order if (!isCurrentPlayerEliminated) { b.moveCurrentPlayerToEndOfPlayOrder(); } // Compute turn result return(b.GetTurnResult()); }
public override Tile playTurn(Board b, List <Tile> playerHand, int numTilesInDrawPile) { //ordered from least to most symmetric List <Tile> validMoves = new List <Tile>(); if (playerHand.Count == 0) { throw new Exception("player hand is empty"); } else { //order tiles from most to least symmetric List <Tile> orderedTiles = new List <Tile>(); //list of all moves from most to least symmetric List <Tile> allMovesOrdered = new List <Tile>(); SortedDictionary <int, List <Tile> > sortedTiles = new SortedDictionary <int, List <Tile> >(); foreach (Tile t in playerHand) { int symmetry = t.howSymmetric(); if (sortedTiles.ContainsKey(symmetry)) { sortedTiles[symmetry].Add(t); } else { sortedTiles.Add(symmetry, new List <Tile> { t }); } } foreach (KeyValuePair <int, List <Tile> > pair in sortedTiles.Reverse()) { foreach (Tile t in pair.Value) { Tile checkTile = t; int timesRotated = 0; checkTile = checkTile.rotate(); while (timesRotated < 4) { SPlayer currPlayer = b.getActiveSPlayer(color); if (currPlayer.returnColor() == null) { throw new Exception("Player not found on board!"); } if (b.isNotEliminationMove(currPlayer, checkTile)) { validMoves.Add(checkTile); break; } else { checkTile = checkTile.rotate(); timesRotated = timesRotated + 1; } allMovesOrdered.Add(checkTile); } } } //no valid moves, return the first tile if (validMoves.Count == 0) { return(allMovesOrdered[0]); } return(validMoves[0]); } }