Пример #1
0
        /**
         * This method receives a move object and returns whether the move is a legit jumpable move or not.
         */
        public bool IsJumpableMove(Move i_Move)
        {
            bool jumpableMove = true;
            CheckersCoordinates currentLocation = i_Move.CurrentLocation;
            CheckersCoordinates targetLocation  = i_Move.TargetLocation;
            int    columnsDelta = targetLocation.Column - currentLocation.Column;
            int    rowsDelta    = targetLocation.Row - currentLocation.Row;
            Player movePlayer   = i_Move.Player != null ? i_Move.Player : GetCurrentPlayer();

            if (Math.Abs(columnsDelta) != Move.k_JumpMovesOffset || Math.Abs(rowsDelta) != Move.k_JumpMovesOffset)
            {
                jumpableMove = false;
            }
            else
            {
                Soldier jumpableSoldier = getJumpedSoldier(i_Move);

                // Checking that there is a jumpable soldier to jump over and that it's the opponent's soldier.
                if (jumpableSoldier == null || movePlayer.PlayerType == jumpableSoldier.PlayerType)
                {
                    jumpableMove = false;
                }
                else if (m_LastMove != null && m_LastMove.HasDoubleJump && !currentLocation.Equals(m_LastMove.TargetLocation))
                {
                    // Checking that if the last move is a double jump move, then the last soldier played is the current soldier.
                    jumpableMove = false;
                }
            }

            return(jumpableMove);
        }