コード例 #1
0
        private bool isValidCapture(Board i_GameBoard, string io_PositionFrom, string io_PositionTo,
                                    ref CheckersPiece io_CurrentChecker, List <CheckersPiece> i_RivalPieces, ref CheckersPiece io_RivalChecker)
        {
            bool   isValid = false;
            ushort rowIndex, colIndex;

            foreach (string positionFrom in Moves.Keys)
            {
                if (io_PositionFrom == positionFrom)
                {
                    if (isPositionInList(io_PositionTo, Moves[positionFrom]))
                    {
                        rowIndex          = i_GameBoard.GetIndexInBoard(ref io_PositionFrom, out colIndex);
                        io_CurrentChecker = CaptureUtils.FindCheckerPiece(rowIndex, colIndex, Pieces);

                        colIndex += (ushort)(io_PositionTo[k_ColIndex] - io_PositionFrom[k_ColIndex]);
                        rowIndex += (ushort)(io_PositionTo[k_RowIndex] - io_PositionFrom[k_RowIndex]);
                        getRivalPosition(ref rowIndex, ref colIndex, io_PositionTo[k_RowIndex] < io_PositionFrom[k_RowIndex],
                                         io_PositionTo[k_ColIndex] < io_PositionFrom[k_ColIndex]);
                        io_RivalChecker = CaptureUtils.FindCheckerPiece((ushort)rowIndex, (ushort)colIndex, i_RivalPieces);

                        isValid = true;
                        break;
                    }
                }
            }

            return(isValid);
        }
コード例 #2
0
 public void MakeCapture(Board i_GameBoard, ref CheckersPiece io_CurrentCheckerPiece, ref string io_PositionTo,
                         ref CheckersPiece io_RivalCheckerPiece)
 {
     CaptureUtils.CaptureRivalCheckerPiece(i_GameBoard, ref io_CurrentCheckerPiece,
                                           io_PositionTo, ref io_RivalCheckerPiece);
     m_CurrentCheckerPiece = io_CurrentCheckerPiece;
 }
コード例 #3
0
        public bool GetMovesAndUpdate(Board i_GameBoard, User i_RivalPlayer)
        {
            bool canCapture = true;
            Dictionary <string, List <string> > moves = new Dictionary <string, List <string> >();

            // If the current checker didn't make a move the turn before.
            if (m_CurrentCheckerPiece == null)
            {
                // If the user can eat, he must! the list will return as ref value. If not, the list will return the regular moves list.
                if (!CaptureUtils.CanUserCapture(i_GameBoard, this, i_RivalPlayer, ref moves))
                {
                    m_Moves    = MoveUtils.CreateRegularMoves(this, i_GameBoard);
                    canCapture = false;
                }
                else
                {
                    m_Moves = moves;
                }
            }
            // If there's a "soldier" that can capture again.
            else
            {
                // If there's capture in a row.
                m_Moves = createCaptureMoveList(i_GameBoard, i_RivalPlayer);
            }

            return(canCapture);
        }
コード例 #4
0
        private CheckersPiece updateCurrentCheckerPiece(ushort i_RowIndex, ushort i_ColIndex)
        {
            CheckersPiece foundCheckerPiece = null;

            foreach (CheckersPiece checkerPiece in m_CheckersPiece)
            {
                if (CaptureUtils.IsSamePosition(checkerPiece, i_RowIndex, i_ColIndex))
                {
                    foundCheckerPiece = checkerPiece;
                    break;
                }
            }

            return(foundCheckerPiece);
        }
コード例 #5
0
        private bool isValidMove(Board i_GameBoard, string i_PositionFrom, string i_PositionTo, ref CheckersPiece io_CurrentChecker)
        {
            bool   isValid = false;
            ushort rowIndex, colIndex;

            foreach (string positionFrom in Moves.Keys)
            {
                if (i_PositionFrom == positionFrom)
                {
                    if (isPositionInList(i_PositionTo, Moves[positionFrom]))
                    {
                        rowIndex          = i_GameBoard.GetIndexInBoard(ref i_PositionFrom, out colIndex);
                        io_CurrentChecker = CaptureUtils.FindCheckerPiece(rowIndex, colIndex, Pieces);

                        isValid = true;
                        break;
                    }
                }
            }

            return(isValid);
        }
コード例 #6
0
        // Certain Tool's Capture Move List:
        private Dictionary <string, List <string> > createCaptureMoveList(Board i_GameBoard, User i_RivalPlayer)
        {
            Dictionary <string, List <string> > captureList = new Dictionary <string, List <string> >();

            if (m_PlayerNumber == ePlayerType.MainPlayer)
            {
                CaptureUtils.CanCaptureDown(i_GameBoard, m_CurrentCheckerPiece, i_RivalPlayer.Pieces, ref captureList);
                if (m_CurrentCheckerPiece.IsKing)
                {
                    CaptureUtils.CanCaptureUp(i_GameBoard, m_CurrentCheckerPiece, i_RivalPlayer.Pieces, ref captureList);
                }
            }
            else
            {
                CaptureUtils.CanCaptureUp(i_GameBoard, m_CurrentCheckerPiece, i_RivalPlayer.Pieces, ref captureList);
                if (m_CurrentCheckerPiece.IsKing)
                {
                    CaptureUtils.CanCaptureDown(i_GameBoard, m_CurrentCheckerPiece, i_RivalPlayer.Pieces, ref captureList);
                }
            }

            return(captureList);
        }