public static bool IsCaptureMovePossiblePerSide(ePlayerSide i_Side, Board i_Board, int i_Direction, Piece i_Piece)
        {
            bool        isCaptureMovePossible = false;
            ePlayerSide opponentSide          = GetOtherSide(i_Side);

            if (IsInBorders(i_Board, i_Piece.Location.X + i_Direction, i_Piece.Location.Y - i_Direction) && i_Board.GameBoard[i_Piece.Location.X + i_Direction, i_Piece.Location.Y - i_Direction].CurrentPiece != null)
            {
                if (i_Board.GameBoard[i_Piece.Location.X + i_Direction, i_Piece.Location.Y - i_Direction].CurrentPiece.Side == opponentSide)
                {
                    if (IsInBorders(i_Board, i_Piece.Location.X + (2 * i_Direction), i_Piece.Location.Y - (2 * i_Direction)))
                    {
                        if (i_Board.GameBoard[i_Piece.Location.X + (2 * i_Direction), i_Piece.Location.Y - (2 * i_Direction)].CurrentPiece == null)
                        {
                            isCaptureMovePossible = true;
                        }
                    }
                }
            }

            if (IsInBorders(i_Board, i_Piece.Location.X + i_Direction, i_Piece.Location.Y + i_Direction) && i_Board.GameBoard[i_Piece.Location.X + i_Direction, i_Piece.Location.Y + i_Direction].CurrentPiece != null)
            {
                if (i_Board.GameBoard[i_Piece.Location.X + i_Direction, i_Piece.Location.Y + i_Direction].CurrentPiece.Side == opponentSide)
                {
                    if (IsInBorders(i_Board, i_Piece.Location.X + (2 * i_Direction), i_Piece.Location.Y + (2 * i_Direction)))
                    {
                        if (i_Board.GameBoard[i_Piece.Location.X + (2 * i_Direction), i_Piece.Location.Y + (2 * i_Direction)].CurrentPiece == null)
                        {
                            isCaptureMovePossible = true;
                        }
                    }
                }
            }

            return(isCaptureMovePossible);
        }
Example #2
0
 // Constructors
 public Player(string i_Name, ePlayerSide i_Side, int i_BoardSize, bool i_IsAi)
 {
     m_Name       = i_Name;
     m_Side       = i_Side;
     m_IsAi       = i_IsAi;
     m_TotalScore = 0;
     InitPieceArr(i_Side, i_BoardSize);
 }
        private static bool isMoveSimpleDiagonalLine(ePlayerSide i_Side, Move i_Move)
        {
            int rowDifference = Math.Abs(i_Move.ToRow - i_Move.FromRow);
            int colDifference = Math.Abs(i_Move.FromCol - i_Move.ToCol);

            if (rowDifference == 1 && colDifference == 1)
            {
                return(true);
            }

            return(false);
        }
        private static bool isSimpleMovePossible(Player i_Player, Board i_Board, Move i_Move)
        {
            bool  isPossible  = false;
            Piece movingPiece = i_Board.GameBoard[i_Move.FromRow, i_Move.FromCol].CurrentPiece;

            if (movingPiece != null)
            {
                isPossible = isMoveSimpleDiagonalLine(i_Player.Side, i_Move);

                // if king- also check opposite direction
                if (movingPiece.IsKing)
                {
                    ePlayerSide oppositeSide = MoveValidator.GetOtherSide(i_Player.Side);
                    isPossible = isPossible || isMoveSimpleDiagonalLine(oppositeSide, i_Move);
                }
            }

            return(isPossible);
        }
Example #5
0
        // Public Methods
        // Initialize array of pieces and their location on the board according to it's size
        public void InitPieceArr(ePlayerSide i_Side, int i_BoardSize)
        {
            int numOfPieces = (i_BoardSize / 2) * ((i_BoardSize / 2) - 1);

            m_Pieces = new List <Piece>();
            int endRow, startRow, piecesIndex = 0;

            if (i_Side == ePlayerSide.Up)
            {
                startRow = 0;
                endRow   = (i_BoardSize / 2) - 1;
            }
            else
            {
                startRow = (i_BoardSize / 2) + 1;
                endRow   = i_BoardSize;
            }

            for (int i = startRow; i < endRow; i++)
            {
                for (int j = 0; j < i_BoardSize; j++)
                {
                    if (piecesIndex < numOfPieces)
                    {
                        if ((j % 2 == 1) && (i % 2 == 0))
                        {
                            Point locationPoint = new Point(i, j);
                            Piece boardPiece    = new Piece(locationPoint, i_Side);
                            m_Pieces.Add(boardPiece);
                        }

                        if ((j % 2 == 0) && (i % 2 == 1))
                        {
                            Point locationPoint = new Point(i, j);
                            Piece boardPiece    = new Piece(locationPoint, i_Side);
                            m_Pieces.Add(boardPiece);
                        }
                    }
                }
            }
        }
Example #6
0
 // Constructors
 public Piece(Point i_Location, ePlayerSide i_Side)
 {
     r_Side     = i_Side;
     m_Location = i_Location;
     m_IsKing   = false;
 }
        // Returns the opposite side of the given side
        public static ePlayerSide GetOtherSide(ePlayerSide i_Side)
        {
            ePlayerSide side = (i_Side == ePlayerSide.Down) ? ePlayerSide.Up : ePlayerSide.Down;

            return(side);
        }