Пример #1
0
        public void UpdateAvailableMovesList(Player i_Player)
        {
            eKindOfCell      playersColor = i_Player.DiskColor;
            List <Direction> foundDirection;
            bool             isMoveAvailable;
            PickedCell       foundCell = new PickedCell(0, 0);

            if (i_Player.AvailableMoves.Count != 0)
            {
                i_Player.ClearAvailableMovesList();
            }

            for (int i = 1; i < m_BoardMatrix.GetLength(1) - 1; i++)
            {
                for (int j = 1; j < m_BoardMatrix.GetLength(1) - 1; j++)
                {
                    if (m_BoardMatrix[i, j].CellKind == eKindOfCell.Empty)
                    {
                        // list of neighbours, potential for move
                        foundDirection = findFoeNeighbourDirection(playersColor, i, j);
                        if (foundDirection.Count != 0)
                        {
                            isMoveAvailable = findIfThereIsAMove(foundDirection, i, j, playersColor);
                            if (isMoveAvailable)
                            {
                                foundCell.PickARow    = i;
                                foundCell.PickAColumn = j;
                                i_Player.SetNewAvailableMove(foundCell);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void updateBoardAfterAMove(PickedCell i_CellToUpdate, Player i_Player)
        {
            eKindOfCell      playersColor = i_Player.DiskColor;
            List <Direction> foundDirections;

            foundDirections = findFoeNeighbourDirection(playersColor, i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn);
            flipFoeDisks(foundDirections, i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn, playersColor);
            m_BoardMatrix[i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn].CellKind = i_Player.DiskColor;

            UpdateAvailableMovesList(m_BlackPlayer);
            UpdateAvailableMovesList(m_WhitePlayer);
        }
Пример #3
0
        public bool PlayMoveFromBoard(int i_Row, int i_Column, Player i_Player)
        {
            Player     nextPlayer;
            bool       isEndOfGame;
            PickedCell pickedCell = new PickedCell(i_Row, i_Column);

            updateBoardAfterAMove(pickedCell, i_Player);
            m_TurnInPlay = !m_TurnInPlay;
            nextPlayer   = WhoPlaysNext();

            isEndOfGame = checkSkipOfTurnOrEndOfGame(nextPlayer);

            if (isEndOfGame == false)
            {
                nextPlayer = WhoPlaysNext();
                if (nextPlayer.PlayerType == ePlayerType.Computer)
                {
                    pickedCell = chooseCellRandomaly(nextPlayer);
                    updateBoardAfterAMove(pickedCell, nextPlayer);
                    m_TurnInPlay = !m_TurnInPlay;
                    nextPlayer   = WhoPlaysNext();

                    if (isBoardFull() || !areThereAvailableMovesForAnyPlayer())
                    {
                        isEndOfGame = true;
                        PlayersScoreWhenGameEnded();
                    }
                    else if (!areThereAvailableMovesForPlayer(nextPlayer))
                    {
                        m_TurnInPlay = !m_TurnInPlay;
                    }
                }
            }
            else
            {
                PlayersScoreWhenGameEnded();
            }

            return(isEndOfGame);
        }
Пример #4
0
        private void updateBoardAfterAMove(PickedCell i_CellToUpdate, Player i_Player)
        {
            eKindOfCell playersColor = i_Player.DiskColor;
            List<Direction> foundDirections;

            foundDirections = findFoeNeighbourDirection(playersColor, i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn);
            flipFoeDisks(foundDirections, i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn, playersColor);
            m_BoardMatrix[i_CellToUpdate.PickARow, i_CellToUpdate.PickAColumn].CellKind = i_Player.DiskColor;

            UpdateAvailableMovesList(m_BlackPlayer);
            UpdateAvailableMovesList(m_WhitePlayer);
        }
Пример #5
0
        public void UpdateAvailableMovesList(Player i_Player)
        {
            eKindOfCell playersColor = i_Player.DiskColor;
            List<Direction> foundDirection;
            bool isMoveAvailable;
            PickedCell foundCell = new PickedCell(0, 0);

            if (i_Player.AvailableMoves.Count != 0)
            {
                i_Player.ClearAvailableMovesList();
            }

            for (int i = 1; i < m_BoardMatrix.GetLength(1) - 1; i++)
            {
                for (int j = 1; j < m_BoardMatrix.GetLength(1) - 1; j++)
                {
                    if (m_BoardMatrix[i, j].CellKind == eKindOfCell.Empty)
                    {
                        // list of neighbours, potential for move
                        foundDirection = findFoeNeighbourDirection(playersColor, i, j);
                        if (foundDirection.Count != 0)
                        {
                            isMoveAvailable = findIfThereIsAMove(foundDirection, i, j, playersColor);
                            if (isMoveAvailable)
                            {
                                foundCell.PickARow = i;
                                foundCell.PickAColumn = j;
                                i_Player.SetNewAvailableMove(foundCell);
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        public bool PlayMoveFromBoard(int i_Row, int i_Column, Player i_Player)
        {
            Player nextPlayer;
            bool isEndOfGame;
            PickedCell pickedCell = new PickedCell(i_Row, i_Column);

            updateBoardAfterAMove(pickedCell, i_Player);
            m_TurnInPlay = !m_TurnInPlay;
            nextPlayer = WhoPlaysNext();

            isEndOfGame = checkSkipOfTurnOrEndOfGame(nextPlayer);

            if (isEndOfGame == false)
            {
                nextPlayer = WhoPlaysNext();
                if (nextPlayer.PlayerType == ePlayerType.Computer)
                {
                    pickedCell = chooseCellRandomaly(nextPlayer);
                    updateBoardAfterAMove(pickedCell, nextPlayer);
                    m_TurnInPlay = !m_TurnInPlay;
                    nextPlayer = WhoPlaysNext();

                    if (isBoardFull() || !areThereAvailableMovesForAnyPlayer())
                    {
                        isEndOfGame = true;
                        PlayersScoreWhenGameEnded();
                    }
                    else if (!areThereAvailableMovesForPlayer(nextPlayer))
                    {
                        m_TurnInPlay = !m_TurnInPlay;
                    }
                }
            }
            else
            {
                PlayersScoreWhenGameEnded();
            }

            return isEndOfGame;
        }
Пример #7
0
 public void SetNewAvailableMove(PickedCell i_Cell)
 {
     m_AvailableMovesForPlayer.Add(i_Cell);
 }
Пример #8
0
 public void SetNewAvailableMove(PickedCell i_Cell)
 {
     m_AvailableMovesForPlayer.Add(i_Cell);
 }