public Posn placeTile(SPlayer p, Tile t) { int[] newGridLoc = new int[2]; Posn playerPosn = p.getPlayerPosn(); // if player is not on the edge, if it is not the players first turn anymore // set new grid location to be the next location that player can place tile in newGridLoc = nextTileCoord(playerPosn); // get the current player location on their current tile int currentTilePosn = playerPosn.returnLocationOnTile(); // get the new player location on the next tile int newTilePosn = getEndOfPathOnTile(t, currentTilePosn); int newRow = newGridLoc[0]; int newCol = newGridLoc[1]; // set the next grid location on the board to be the tile grid[newRow, newCol] = t; // Calculate end position of player on new tile Posn endPos = new Posn(newRow, newCol, newTilePosn); // Calculate end position of player if additional tiles to move across endPos = moveMockPlayer(endPos); return(endPos); }
// Adds player to appropriate list // Eliminated if player is on edge, onBoard otherwise public void addPlayerToBoard(SPlayer player) { if (onEdge(player.getPlayerPosn())) { eliminated.Add(player); } else { onBoard.Add(player); } }
public bool isNotEliminationMove(SPlayer p, Tile t) { // Get next tile position Posn playerPosn = p.getPlayerPosn(); int[] newGridLoc = nextTileCoord(playerPosn); // Put tile on mock board Board mockBoard = this.clone(); mockBoard.grid[newGridLoc[0], newGridLoc[1]] = t; // Move player on fake board Posn endPos = mockBoard.moveMockPlayer(playerPosn); // See if elimination move return(!onEdge(endPos)); }
// Moves all players to the end of their path // Returns list of players who end up on the edge public void movePlayers() { List <SPlayer> onEdgePlayers = new List <SPlayer>(); for (int i = 0; i < getNumActive(); i++) { SPlayer player = onBoard[i]; Posn endPos = moveMockPlayer(player.getPlayerPosn()); player.setPosn(endPos); if (onEdge(endPos)) { onEdgePlayers.Add(player); eliminatePlayer(player); i--; } } if (getNumActive() == 0) { eliminatedButWinners = onEdgePlayers; } }