コード例 #1
0
        internal bool ValidInstrumentDirection(eInstrumentType instrumentTypeFrom, eOptionalMoves requiredMove)
        {
            bool isValidMove = true;

            //soldier1 can move only up
            if (instrumentTypeFrom == eInstrumentType.PlayerOneSoldier)
            {
                if (requiredMove != eOptionalMoves.EatUpLeft && requiredMove != eOptionalMoves.EatUpRight &&
                    requiredMove != eOptionalMoves.MoveUpLeft && requiredMove != eOptionalMoves.MoveUpRight)
                {
                    isValidMove = false;
                }
            }
            //soldier2 can move only down
            else if (instrumentTypeFrom == eInstrumentType.PlayerTwoSoldier)
            {
                if (requiredMove != eOptionalMoves.EatDownLeft && requiredMove != eOptionalMoves.EatDownRight &&
                    requiredMove != eOptionalMoves.MoveDownLeft && requiredMove != eOptionalMoves.MoveDownRight)
                {
                    isValidMove = false;
                }
            }

            return(isValidMove);
        }
コード例 #2
0
        private LinkedList <ComputerValidOptionNode> computerRandomMoveOptionList()
        {
            eOptionalMoves direction = eOptionalMoves.InvalidMove;
            LinkedList <ComputerValidOptionNode> validOptionList = new LinkedList <ComputerValidOptionNode>();
            ComputerValidOptionNode currentNode;

            for (int i = 0; i < m_Board.Size; i++)
            {
                for (int j = 0; j < m_Board.Size; j++)
                {
                    foreach (eOptionalMoves currentDirection in Enum.GetValues(typeof(eOptionalMoves)))
                    {
                        if (m_MovementValidation.IsCorrectPlayerIsInCell(m_Board[i, j]))
                        {
                            if (m_MovementValidation.ValidMoveByType(i, j, currentDirection) && m_MovementValidation.ValidInstrumentDirection(m_Board[i, j], currentDirection))
                            {
                                currentNode = new ComputerValidOptionNode(i, j, currentDirection);
                                validOptionList.AddFirst(currentNode);
                            }
                        }
                    }
                }
            }

            return(validOptionList);
        }
コード例 #3
0
        internal void RegularComputerMove()
        {
            int[]          soldierToBeKingIndex = new int[2];
            int[]          maxEatGainIndex      = new int[2];
            int            maxGain = 0;
            int            currentGain;
            eOptionalMoves maxGainDirection = eOptionalMoves.InvalidMove;
            eOptionalMoves kingDirection    = eOptionalMoves.InvalidMove;

            for (int i = 0; i < m_Board.Size; i++)
            {
                for (int j = 0; j < m_Board.Size; j++)
                {
                    if (m_MovementValidation.IsCorrectPlayerIsInCell(m_Board[i, j]))
                    {
                        foreach (eOptionalMoves direction in Enum.GetValues(typeof(eOptionalMoves)))
                        {
                            if (m_MovementValidation.ValidMoveByType(i, j, direction) && m_MovementValidation.ValidInstrumentDirection(m_Board[i, j], direction))
                            {
                                currentGain = computerEatCounterByMovement(i, j, 0, direction);
                                if (currentGain > maxGain)
                                {
                                    maxGain            = currentGain;
                                    maxEatGainIndex[0] = i;
                                    maxEatGainIndex[1] = j;
                                    maxGainDirection   = direction;
                                }

                                if (computerMoveToBeKingByDirection(i, j, direction))
                                {
                                    soldierToBeKingIndex[0] = i;
                                    soldierToBeKingIndex[1] = j;
                                    kingDirection           = direction;
                                }
                            }
                        }
                    }
                }
            }

            if (maxGainDirection != eOptionalMoves.InvalidMove && maxGain >= 1)
            {
                computerMakeMove(maxEatGainIndex[0], maxEatGainIndex[1], maxGainDirection);
            }
            else if (kingDirection != eOptionalMoves.InvalidMove)
            {
                computerMakeMove(soldierToBeKingIndex[0], soldierToBeKingIndex[1], kingDirection);
            }
            else
            {
                computerRandomMove();
            }
        }
コード例 #4
0
 private void tryComputerMove()
 {
     if (m_GameHandler.CurrentTurnPlayerID == Player.ePlayerID.PlayerTwo && m_GameHandler.PlayerTwo.PlayerID == Player.ePlayerID.Computer)
     {
         if (!m_GameHandler.EndOfRound)
         {
             m_GameHandler.ComputerMove();
             m_AnimationMove = m_GameHandler.LastMove();
             animate(m_Board[m_GameHandler.ComputerCurrentMoveRowOrigin(), m_GameHandler.ComputerCurrentMoveColOrigin()]);
         }
     }
 }
コード例 #5
0
        internal Player(string i_Name, ePlayerID i_PlayerID, Board i_Board)
        {
            m_PlayerName         = i_Name;
            m_PlayerID           = i_PlayerID;
            m_Board              = i_Board;
            m_LastMove           = eOptionalMoves.InvalidMove;
            m_MovementValidation = new MovementValidation(this, m_Board);

            if (i_PlayerID == ePlayerID.Computer)
            {
                m_ArtificialIntelligence = new ArtificialIntelligence(this, m_Board);
            }
        }
コード例 #6
0
        internal void RealPlayerMove(int io_RowFrom, int io_ColFrom, int io_RowTo, int io_ColTo)
        {
            eOptionalMoves validPlayerMove;

            try
            {
                validPlayerMove          = m_MovementValidation.ValidPlayerMove(io_RowFrom, io_ColFrom, io_RowTo, io_ColTo);
                m_LastMove               = validPlayerMove;
                m_LastMovementLandingRow = io_RowTo;
                m_LastMovementLandingCol = io_ColTo;
                MakeTheMove(io_RowFrom, io_ColFrom, io_RowTo, io_ColTo);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #7
0
        internal bool ValidMoveByType(int i_Row, int i_Col, eOptionalMoves io_MoveType)
        {
            bool validByMoveType;

            switch (io_MoveType)
            {
            case eOptionalMoves.MoveDownRight:
                validByMoveType = MoveDownRight(i_Row, i_Col);
                break;

            case eOptionalMoves.MoveDownLeft:
                validByMoveType = MoveDownLeft(i_Row, i_Col);
                break;

            case eOptionalMoves.MoveUpRight:
                validByMoveType = MoveUpRight(i_Row, i_Col);
                break;

            case eOptionalMoves.MoveUpLeft:
                validByMoveType = MoveUpLeft(i_Row, i_Col);
                break;

            case eOptionalMoves.EatDownRight:
                validByMoveType = EatDownRight(i_Row, i_Col);
                break;

            case eOptionalMoves.EatDownLeft:
                validByMoveType = EatDownLeft(i_Row, i_Col);
                break;

            case eOptionalMoves.EatUpRight:
                validByMoveType = EatUpRight(i_Row, i_Col);
                break;

            case eOptionalMoves.EatUpLeft:
                validByMoveType = EatUpLeft(i_Row, i_Col);
                break;

            default:
                validByMoveType = false;
                break;
            }

            return(validByMoveType);
        }
コード例 #8
0
        internal bool IsValidMoveAsPlayer(string i_Move)
        {
            bool isValidMoveResult = true;
            //convert the move into integer
            int colMoveFrom = CharToLocationAtBoard(i_Move[0]);
            int rowMoveFrom = CharToLocationAtBoard(i_Move[1]);
            int colMoveTo   = CharToLocationAtBoard(i_Move[3]);
            int rowMoveTo   = CharToLocationAtBoard(i_Move[4]);
            //check what is the spcific instrument type in board
            eInstrumentType instrumentTypeFrom = m_Board[rowMoveFrom, colMoveFrom];
            //catalog move type
            eOptionalMoves requiredMove = ConvertToEnumMove(rowMoveFrom, rowMoveTo, colMoveFrom, colMoveTo);

            if (requiredMove == eOptionalMoves.InvalidMove)
            {
                isValidMoveResult = false;
                Console.Write("Invalid move. Please try again: ");
            }
            else if (!ValidMoveByType(rowMoveFrom, colMoveFrom, requiredMove))
            {
                isValidMoveResult = false;
                Console.Write("Invalid move. Please try again: ");
            }
            else if (!IsCorrectPlayerIsInCell(instrumentTypeFrom))
            {
                isValidMoveResult = false;
                Console.Write("Invalid move, it is not your instrument. Please try again: ");
            }
            else if (!ValidInstrumentDirection(instrumentTypeFrom, requiredMove))
            {
                isValidMoveResult = false;
                Console.Write("Invalid move, a soldier can go only forward. Please try again: ");
            }
            else if (CheckIfCanEat())
            {
                if (requiredMove != eOptionalMoves.EatDownLeft && requiredMove != eOptionalMoves.EatDownRight &&
                    requiredMove != eOptionalMoves.EatUpLeft && requiredMove != eOptionalMoves.EatUpRight)
                {
                    isValidMoveResult = false;
                    Console.Write("Invalid move, you should make a capture. Please try again: ");
                }
            }

            return(isValidMoveResult);
        }
コード例 #9
0
        private bool computerMoveToBeKingByDirection(int i_Row, int i_Col, eOptionalMoves io_MoveDirection)
        {
            bool isToBeKing = false;

            if (io_MoveDirection != eOptionalMoves.MoveDownLeft || io_MoveDirection != eOptionalMoves.MoveDownRight)
            {
                isToBeKing = false;
            }
            else if (i_Row == m_Board.Size - 2 && m_Board[i_Row, i_Col] == eInstrumentType.PlayerTwoSoldier)
            {
                if (m_MovementValidation.ValidInstrumentDirection(eInstrumentType.PlayerTwoSoldier, io_MoveDirection))
                {
                    isToBeKing = true;
                }
            }

            return(isToBeKing);
        }
コード例 #10
0
        internal void ContinuesComputerMove(int i_Row, int i_Col)
        {
            eOptionalMoves[] eatDirectionOptions =
            {
                eOptionalMoves.EatDownLeft, eOptionalMoves.EatDownRight, eOptionalMoves.EatUpLeft,
                eOptionalMoves.EatUpRight
            };

            eOptionalMoves direction = eOptionalMoves.InvalidMove;

            foreach (eOptionalMoves currentDirection in eatDirectionOptions)
            {
                if (m_MovementValidation.ValidMoveByType(i_Row, i_Col, currentDirection) && m_MovementValidation.ValidInstrumentDirection(m_Board[i_Row, i_Col], currentDirection))
                {
                    direction = currentDirection;
                }
            }

            computerMakeMove(i_Row, i_Col, direction);
        }
コード例 #11
0
        private void computerMakeMove(int i_Row, int i_Col, eOptionalMoves i_Direction)
        {
            m_AIPlayer.LastMove    = i_Direction;
            m_CurrentMoveRowOrigin = i_Row;
            m_CurrentMoveColOrigin = i_Col;

            switch (i_Direction)
            {
            case eOptionalMoves.MoveDownRight:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row + 1, i_Col + 1);
                break;

            case eOptionalMoves.MoveDownLeft:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row + 1, i_Col - 1);
                break;

            case eOptionalMoves.EatDownRight:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row + 2, i_Col + 2);
                break;

            case eOptionalMoves.EatDownLeft:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row + 2, i_Col - 2);
                break;

            case eOptionalMoves.MoveUpRight:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row - 1, i_Col + 1);
                break;

            case eOptionalMoves.MoveUpLeft:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row - 1, i_Col - 1);
                break;

            case eOptionalMoves.EatUpRight:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row - 2, i_Col + 2);
                break;

            case eOptionalMoves.EatUpLeft:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row - 2, i_Col - 2);
                break;
            }
        }
コード例 #12
0
        internal bool ValidInstrumentDirection(eInstrumentType i_InstrumentTypeFrom, eOptionalMoves i_RequiredMove)
        {
            bool isValidMove = true;

            if (i_InstrumentTypeFrom == eInstrumentType.PlayerOneSoldier)
            {
                isValidMove = i_RequiredMove == eOptionalMoves.EatUpLeft ||
                              i_RequiredMove == eOptionalMoves.EatUpRight ||
                              i_RequiredMove == eOptionalMoves.MoveUpLeft ||
                              i_RequiredMove == eOptionalMoves.MoveUpRight;
            }
            else if (i_InstrumentTypeFrom == eInstrumentType.PlayerTwoSoldier)
            {
                isValidMove = i_RequiredMove == eOptionalMoves.EatDownLeft ||
                              i_RequiredMove == eOptionalMoves.EatDownRight ||
                              i_RequiredMove == eOptionalMoves.MoveDownLeft ||
                              i_RequiredMove == eOptionalMoves.MoveDownRight;
            }

            return(isValidMove);
        }
コード例 #13
0
        internal eOptionalMoves ConvertToEnumMove(int i_RowFrom, int i_RowTo, int i_ColFrom, int i_ColTo)
        {
            eOptionalMoves requiredMove = eOptionalMoves.InvalidMove;

            if (i_ColFrom == i_ColTo + 2 && i_RowFrom == i_RowTo + 2)
            {
                requiredMove = eOptionalMoves.EatUpLeft;
            }
            else if (i_ColFrom == i_ColTo + 1 && i_RowFrom == i_RowTo + 1)
            {
                requiredMove = eOptionalMoves.MoveUpLeft;
            }
            else if (i_ColFrom == i_ColTo - 2 && i_RowFrom == i_RowTo + 2)
            {
                requiredMove = eOptionalMoves.EatUpRight;
            }
            else if (i_ColFrom == i_ColTo - 1 && i_RowFrom == i_RowTo + 1)
            {
                requiredMove = eOptionalMoves.MoveUpRight;
            }
            else if (i_ColFrom == i_ColTo + 2 && i_RowFrom == i_RowTo - 2)
            {
                requiredMove = eOptionalMoves.EatDownLeft;
            }
            else if (i_ColFrom == i_ColTo + 1 && i_RowFrom == i_RowTo - 1)
            {
                requiredMove = eOptionalMoves.MoveDownLeft;
            }
            else if (i_ColFrom == i_ColTo - 2 && i_RowFrom == i_RowTo - 2)
            {
                requiredMove = eOptionalMoves.EatDownRight;
            }
            else if (i_ColFrom == i_ColTo - 1 && i_RowFrom == i_RowTo - 1)
            {
                requiredMove = eOptionalMoves.MoveDownRight;
            }

            return(requiredMove);
        }
コード例 #14
0
        internal bool IsValidMoveAsPlayer(int io_RowFrom, int io_ColFrom, int io_RowTo, int io_ColTo)
        {
            bool isValidMoveResult = true;

            eInstrumentType instrumentTypeFrom = m_Board[io_RowFrom, io_ColFrom];
            eOptionalMoves  requiredMove       = ConvertToEnumMove(io_RowFrom, io_RowTo, io_ColFrom, io_ColTo);

            if (requiredMove == eOptionalMoves.InvalidMove)
            {
                isValidMoveResult = false;
                throw new Exception("Invalid move. Please try again.");
            }
            else if (!ValidMoveByType(io_RowFrom, io_ColFrom, requiredMove))
            {
                isValidMoveResult = false;
                throw new Exception("Invalid move. Please try again.");
            }
            else if (!IsCorrectPlayerIsInCell(instrumentTypeFrom))
            {
                isValidMoveResult = false;
                throw new Exception("Invalid move, it is not your instrument. Please try again.");
            }
            else if (!ValidInstrumentDirection(instrumentTypeFrom, requiredMove))
            {
                isValidMoveResult = false;
                throw new Exception("Invalid move, a soldier can go only forward. Please try again.");
            }
            else if (CheckIfCanEat())
            {
                if (requiredMove != eOptionalMoves.EatDownLeft && requiredMove != eOptionalMoves.EatDownRight &&
                    requiredMove != eOptionalMoves.EatUpLeft && requiredMove != eOptionalMoves.EatUpRight)
                {
                    isValidMoveResult = false;
                    throw new Exception("Invalid move, you should make a capture. Please try again.");
                }
            }

            return(isValidMoveResult);
        }
コード例 #15
0
        private void computerMakeMove(int i_Row, int i_Col, eOptionalMoves i_Direction)
        {
            m_AIPlayer.LastMove = computerMoveToString(i_Row, i_Col, i_Direction);
            switch (i_Direction)
            {
            case eOptionalMoves.MoveDownRight:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row + 1, i_Col + 1);
                break;

            case eOptionalMoves.MoveDownLeft:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row + 1, i_Col - 1);
                break;

            case eOptionalMoves.EatDownRight:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row + 2, i_Col + 2);
                break;

            case eOptionalMoves.EatDownLeft:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row + 2, i_Col - 2);
                break;

            case eOptionalMoves.MoveUpRight:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row - 1, i_Col + 1);
                break;

            case eOptionalMoves.MoveUpLeft:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row - 1, i_Col - 1);
                break;

            case eOptionalMoves.EatUpRight:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row - 2, i_Col + 2);
                break;

            case eOptionalMoves.EatUpLeft:
                m_AIPlayer.MakeTheMove(i_Row, i_Col, i_Row - 2, i_Col - 2);
                break;
            }
        }
コード例 #16
0
        private void tryToMakeMove()
        {
            int colMoveFrom = m_PreviousPressedButton.ColIndex;
            int rowMoveFrom = m_PreviousPressedButton.RowIndex;
            int colMoveTo   = m_CurrentPressedButton.ColIndex;
            int rowMoveTo   = m_CurrentPressedButton.RowIndex;

            try
            {
                m_GameHandler.TryToMakeMove(rowMoveFrom, colMoveFrom, rowMoveTo, colMoveTo);
                m_AnimationMove = m_GameHandler.LastMove();
                animate(m_Board[rowMoveFrom, colMoveFrom]);
                m_CurrentPressedButton  = null;
                m_PreviousPressedButton = null;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Damka", MessageBoxButtons.OK);
                m_CurrentPressedButton  = null;
                m_PreviousPressedButton = null;
                updateDisplay();
            }
        }
コード例 #17
0
        private string computerMoveToString(int i_Row, int i_Col, eOptionalMoves io_MoveDirection)
        {
            string computerMove = null;
            char   rowFrom      = (char)(i_Row + 97);
            char   colFrom      = (char)(i_Col + 65);
            char   colChaerDest;
            char   rowCharDest;
            int    rowTo = 0;
            int    colTo = 0;

            switch (io_MoveDirection)
            {
            case (eOptionalMoves.MoveDownRight):
                rowTo = rowFrom + 1;
                colTo = colFrom + 1;
                break;

            case (eOptionalMoves.MoveDownLeft):
                rowTo = rowFrom + 1;
                colTo = colFrom - 1;
                break;

            case (eOptionalMoves.MoveUpRight):
                rowTo = rowFrom - 1;
                colTo = colFrom + 1;
                break;

            case (eOptionalMoves.MoveUpLeft):
                rowTo = rowFrom - 1;
                colTo = colFrom - 1;
                break;

            case (eOptionalMoves.EatDownRight):
                rowTo = rowFrom + 2;
                colTo = colFrom + 2;
                break;

            case (eOptionalMoves.EatDownLeft):
                rowTo = rowFrom + 2;
                colTo = colFrom - 2;
                break;

            case (eOptionalMoves.EatUpRight):
                rowTo = rowFrom - 2;
                colTo = colFrom + 2;
                break;

            case (eOptionalMoves.EatUpLeft):
                rowTo = rowFrom - 2;
                colTo = colFrom - 2;
                break;

            default:
                computerMove = "Invalid computer move";
                break;
            }

            if (computerMove == null)
            {
                rowCharDest  = (char)(rowTo);
                colChaerDest = (char)(colTo);
                computerMove = string.Format("{0}{1}>{2}{3}",
                                             colFrom,
                                             rowFrom,
                                             colChaerDest,
                                             rowCharDest
                                             );
            }

            return(computerMove);
        }
コード例 #18
0
 public ComputerValidOptionNode(int i_Row, int i_Col, eOptionalMoves i_Direction)
 {
     m_RowIndex  = i_Row;
     m_ColIndex  = i_Col;
     m_Direction = i_Direction;
 }
コード例 #19
0
        private int computerEatCounterByMovement(int i_Row, int i_Col, int i_EatCounter, eOptionalMoves io_MoveType)
        {
            int answer;

            if (!m_MovementValidation.ValidMoveByType(i_Row, i_Col, io_MoveType))
            {
                answer = i_EatCounter;
            }
            else
            {
                switch (io_MoveType)
                {
                case (eOptionalMoves.EatDownRight):
                    answer = computerEatCounterByMovement(i_Row + 2, i_Col + 2, i_EatCounter + 1, io_MoveType);
                    break;

                case (eOptionalMoves.EatDownLeft):
                    answer = computerEatCounterByMovement(i_Row + 2, i_Col - 2, i_EatCounter + 1, io_MoveType);
                    break;

                case (eOptionalMoves.EatUpRight):
                    answer = computerEatCounterByMovement(i_Row - 2, i_Col + 2, i_EatCounter + 1, io_MoveType);
                    break;

                case (eOptionalMoves.EatUpLeft):
                    answer = computerEatCounterByMovement(i_Row - 2, i_Col - 2, i_EatCounter + 1, io_MoveType);
                    break;

                default:
                    answer = i_EatCounter;
                    break;
                }
            }

            return(answer);
        }