// Used by the function that builds the pieces lists according to the positions on the board private bool isPieceBelongsToPlayer(eCellMode i_Cell, Checkers.ePlayerTag i_Player) { bool pieceBelongToPlayer; switch (i_Player) { case Checkers.ePlayerTag.First: pieceBelongToPlayer = i_Cell == eCellMode.Player1Piece || i_Cell == eCellMode.Player1King; break; case Checkers.ePlayerTag.Second: pieceBelongToPlayer = i_Cell == eCellMode.Player2Piece || i_Cell == eCellMode.Player2King; break; default: throw new InvalidEnumArgumentException(); } return pieceBelongToPlayer; }
// Fills the pieces lists of each player by checking the pieces positions on the board, only used in the beginning of a match public List<Checkers.Piece> BuildPlayerPiecesList(Checkers.ePlayerTag i_CurrentPlayer) { List<Checkers.Piece> listOfPieces = new List<Checkers.Piece>(getNumberOfInitialPieces()); int cellIndex = 0; for (int row = 0; row < (int)r_BoardSize; ++row) { for (int col = 0; col < (int)r_BoardSize; ++col) { if (isPieceBelongsToPlayer(r_BoardMatrix[row, col], i_CurrentPlayer)) { listOfPieces.Add(new Checkers.Piece(i_CurrentPlayer)); listOfPieces[cellIndex++].CurrPosition = new Position(row, col); } } } return listOfPieces; }