public void InitializeBoard() ////builds the first board by the given size { CoinInformation currentCoinInformation = new CoinInformation(); CellPosition currentCoinCellPosition = new CellPosition(); for (int i = 0; i < m_boardSize; i++) { currentCoinCellPosition.X = i; for (int j = 0; j < m_boardSize; j++) { currentCoinCellPosition.Y = j; if (i < (m_boardSize / 2) - 1) { if ((j + i) % 2 != 0) { m_gameBoard[i, j].SetCellOccupation(Cell.e_CellOccupation.topPlayerRegularCoin); currentCoinInformation.CellPosition = currentCoinCellPosition; currentCoinInformation.CoinType = Cell.e_CellOccupation.topPlayerRegularCoin; topPlayerListOfCoins.Add(currentCoinInformation); ////Ready list of a new board with each coin of the top player } } else if (i > m_boardSize / 2) { if ((j + i) % 2 != 0) { m_gameBoard[i, j].SetCellOccupation(Cell.e_CellOccupation.bottomPlayerRegularCoin); currentCoinInformation.CellPosition = currentCoinCellPosition; currentCoinInformation.CoinType = Cell.e_CellOccupation.bottomPlayerRegularCoin; bottomPlayerListOfCoins.Add(currentCoinInformation); ////Ready list of a new board with each coin of the bottom player } } } } }
public Cell(CellPosition position, string rawCell, Desk desk) { Checker checker; var rawChrcker = int.Parse(rawCell.Substring(1, 1)); switch (rawChrcker) { case 1: checker = new Checker(false, false); break; case 2: checker = new Checker(false, true); break; case 3: checker = new Checker(true, false); break; case 4: checker = new Checker(true, true); break; default: checker = null; break; } _position = position; _color = new CellColor(rawCell[0] == '1'); Checker = checker; ActiveButtonColor = Brushes.Gray; ActiveCheckerColor = Brushes.Gold; ActiveKingCheckerColor = Brushes.Cyan; AllowedPositionColor = Brushes.LawnGreen; _desk = desk; }
public Cell GetCell(CellPosition position) => Cells[position.Get_row() * Width + position.Get_column()];
// $G$ DSN-003 (-10) This method is too long. private void Play() { bool isLastMovementWasSkipOver = false; CellPosition lastDestinatioonCellPosition = new CellPosition(); ConsoleUI.PrintBoard(ref m_gameBoard); ConsoleUI.MovmentInstruction(); Player activePlayer = m_bottomPlayer; while (m_gameStatus == e_GameStatus.ActiveGame) { Logic.RegularAndSkipOverMovementsLists movementsListsStruct = new Logic.RegularAndSkipOverMovementsLists(); movementsListsStruct.RegularMovementList = new System.Collections.Generic.List <Movement>(); movementsListsStruct.SkipOverMovementList = new System.Collections.Generic.List <Movement>(); Logic.MakeListOfPossibleMovementsForPlayer(ref m_gameBoard, ref movementsListsStruct, activePlayer.PlayerPosition); if (Logic.IsStructOfListsEmpty(movementsListsStruct) == false) { if (activePlayer.PlayerType == Player.e_PlayerType.Human) { ConsoleUI.PrintCurrentPlayerNameAndCoin(activePlayer); m_currentMovement = ConsoleUI.AskForPlayerMove(m_gameBoard.BoardSize, ref m_gameStatus); } else { m_currentMovement = Logic.ChooseMaximalPointsMovementForPlayerFromStructOfLists(m_gameBoard, movementsListsStruct, activePlayer); } if ((isLastMovementWasSkipOver == false) || ((isLastMovementWasSkipOver == true) && (Movement.IsTwoPositionsEquale(lastDestinatioonCellPosition, m_currentMovement.SourcePosition) == true))) { if (Logic.IsMovementExistsInStructOfLists(movementsListsStruct, m_currentMovement, out isLastMovementWasSkipOver) == true) { if (((movementsListsStruct.SkipOverMovementList.Count != 0) && (Logic.IsMovementExistsInSpecificList(movementsListsStruct.RegularMovementList, m_currentMovement) == true)) == false) { m_gameBoard.ExcuteMovement(m_currentMovement); ConsoleUI.PrintBoard(ref m_gameBoard); ConsoleUI.PrintLastMovementOfActivePlayer(activePlayer, m_currentMovement); lastDestinatioonCellPosition = m_currentMovement.DestinationPosition; if (isLastMovementWasSkipOver == false) { TogglePlayersTurns(ref activePlayer); } else { Logic.MakeListOfPossibleMovementsForPlayer(ref m_gameBoard, ref movementsListsStruct, activePlayer.PlayerPosition); if (Logic.IsMovementFromSpecificCellExistInList(movementsListsStruct.SkipOverMovementList, lastDestinatioonCellPosition) == false) { isLastMovementWasSkipOver = false; TogglePlayersTurns(ref activePlayer); } } } else { ConsoleUI.SkipOverRequiredAnnouncement(); } } else { if (m_gameStatus != e_GameStatus.QuitByUser) { ConsoleUI.InvalidLogicallyMovementAnnouncement(); } } } } else { ConsoleUI.NoMoreMovesAnnouncement(); m_gameStatus = e_GameStatus.NoMovesForActivePlayer; } } }
// $G$ CSS-028 (0) method shouldn't include more then one return command. public bool RemoveCoinFromListOfCoins(ref List <CoinInformation> i_listOfCoins, CellPosition i_cellPosition) //// Will be used when skip over was made { for (int i = 0; i < i_listOfCoins.Count; i++) { if ((i_listOfCoins[i].CellPosition.X == i_cellPosition.X) && (i_listOfCoins[i].CellPosition.Y == i_cellPosition.Y)) { i_listOfCoins.RemoveAt(i); return(true); } } return(false); }
public static void AddPossibleMovementsToStructFromSpecificCellToSpecificDirection(ref Board i_board, ref RegularAndSkipOverMovementsLists i_structOfLists, CoinInformation i_coin, Player.e_PlayerPosition i_playerPosition, CellPosition i_targetCell) { Cell.e_CellOccupation regularCoinOfOpponent = Cell.e_CellOccupation.bottomPlayerRegularCoin, specialCoinOfOpponent = Cell.e_CellOccupation.bottomPlayerSpecialCoin; // assuming top player is the active one //// if top player is NOT the active one...change will be made if (i_playerPosition == Player.e_PlayerPosition.Bottom) { regularCoinOfOpponent = Cell.e_CellOccupation.topPlayerRegularCoin; specialCoinOfOpponent = Cell.e_CellOccupation.topPlayerSpecialCoin; } //// Checking weather target cell is inside the board bounderies if ((i_targetCell.X >= 0) && (i_targetCell.X <= i_board.BoardSize - 1) && (i_targetCell.Y >= 0) && (i_targetCell.Y <= i_board.BoardSize - 1)) { Cell.e_CellOccupation releventCellOccupation = i_board.GameBoard[i_targetCell.X, i_targetCell.Y].GetCellOccupation(); Movement currentMovementToInsert = new Movement(); currentMovementToInsert.SourcePosition = i_coin.CellPosition; if (releventCellOccupation == Cell.e_CellOccupation.notOccupied) { currentMovementToInsert.DestinationPosition = i_targetCell; i_structOfLists.RegularMovementList.Add(currentMovementToInsert); } else if ((releventCellOccupation == regularCoinOfOpponent) || (releventCellOccupation == specialCoinOfOpponent)) { int sourceX = i_coin.CellPosition.X, sourceY = i_coin.CellPosition.Y; // keeping the values of sourceX and sourceY to calculate the vector of movement together with i_tagerCell in order to calculate the skipOver cell CellPosition skipOverTargetCell = new CellPosition(); skipOverTargetCell.X = i_targetCell.X + (i_targetCell.X - sourceX); skipOverTargetCell.Y = i_targetCell.Y + (i_targetCell.Y - sourceY); if ((skipOverTargetCell.X >= 0) && (skipOverTargetCell.X <= i_board.BoardSize - 1) && (skipOverTargetCell.Y >= 0) && (skipOverTargetCell.Y <= i_board.BoardSize - 1)) { releventCellOccupation = i_board.GameBoard[skipOverTargetCell.X, skipOverTargetCell.Y].GetCellOccupation(); if (releventCellOccupation == Cell.e_CellOccupation.notOccupied) { currentMovementToInsert.DestinationPosition = skipOverTargetCell; i_structOfLists.SkipOverMovementList.Add(currentMovementToInsert); } } } } }
// $G$ CSS-028 (0) method shouldn't include more then one return command. public static bool IsMovementFromSpecificCellExistInList(List <Movement> i_listOfMovements, CellPosition i_sourceCellPosition) { foreach (Movement currentMovement in i_listOfMovements) { if (Movement.IsTwoPositionsEquale(currentMovement.SourcePosition, i_sourceCellPosition) == true) { return(true); } } return(false); }
public static Movement AskForPlayerMove(uint i_boardSize, ref e_GameStatus i_gameStatus) { Movement playerMovement = new Movement(); string playerMovementStr = string.Empty; playerMovementStr = Console.ReadLine(); bool allGoodMovementStr = false; while (allGoodMovementStr == false) { if ((playerMovementStr.Length == 5) && (playerMovementStr[2] == '>')) { uint inputSuccessCounter = 0; CellPosition tempCellPos = new CellPosition(); if ((playerMovementStr[0] >= 'A') && (playerMovementStr[0] <= ('A' + i_boardSize - 1))) { tempCellPos.Y = /*(uint)*/ playerMovementStr[0] - 'A'; inputSuccessCounter++; } if ((playerMovementStr[1] >= 'a') && (playerMovementStr[1] <= ('a' + i_boardSize - 1))) { tempCellPos.X = /*(uint)*/ playerMovementStr[1] - 'a'; inputSuccessCounter++; } playerMovement.SourcePosition = tempCellPos; if ((playerMovementStr[3] >= 'A') && (playerMovementStr[3] <= ('A' + i_boardSize - 1))) { tempCellPos.Y = /*(uint)*/ playerMovementStr[3] - 'A'; inputSuccessCounter++; } if ((playerMovementStr[4] >= 'a') && (playerMovementStr[4] <= ('a' + i_boardSize - 1))) { tempCellPos.X = /*(uint)*/ playerMovementStr[4] - 'a'; inputSuccessCounter++; } playerMovement.DestinationPosition = tempCellPos; if (inputSuccessCounter == 4) { allGoodMovementStr = true; } else { Console.WriteLine("You did not enter a valid input, the format should be: COLrow>COLrow.\nPress 'Enter' to continue"); playerMovementStr = Console.ReadLine(); } } else if ((playerMovementStr.Length == 1) && (playerMovementStr[0] == 'Q')) { allGoodMovementStr = true; i_gameStatus = e_GameStatus.QuitByUser; } else { allGoodMovementStr = false; Console.WriteLine("You did not enter a valid input, the format should be: COLrow>COLrow.\nPress 'Enter' to continue"); playerMovementStr = Console.ReadLine(); } } return(playerMovement); }