コード例 #1
0
ファイル: Move.cs プロジェクト: matanelr/-Checkers-Game-
        public bool isValidDiagonalKingMove(Player.eShapeType i_ShapeOfMove)
        {
            bool isValidKingMove = false;

            if ((m_FromSquare.Row - 1 == m_ToSquare.Row) && (m_FromSquare.Column - 1 == m_ToSquare.Column))
            {
                isValidKingMove = true;
            }

            if ((m_FromSquare.Row - 1 == m_ToSquare.Row) && (m_FromSquare.Column + 1 == m_ToSquare.Column))
            {
                isValidKingMove = true;
            }

            if ((m_FromSquare.Row + 1 == m_ToSquare.Row) && (m_FromSquare.Column - 1 == m_ToSquare.Column))
            {
                isValidKingMove = true;
            }

            if ((m_FromSquare.Row + 1 == m_ToSquare.Row) && (m_FromSquare.Column + 1 == m_ToSquare.Column))
            {
                isValidKingMove = true;
            }

            return(isValidKingMove);
        }
コード例 #2
0
ファイル: Move.cs プロジェクト: matanelr/-Checkers-Game-
        public bool isValidDiagonalMove(Player.eShapeType i_Shape)
        {
            bool isValidMove = false;

            switch (i_Shape)
            {
            case Player.eShapeType.X:
                if ((m_FromSquare.Row - 1 == m_ToSquare.Row) && (m_FromSquare.Column - 1 == m_ToSquare.Column))
                {
                    isValidMove = true;
                }

                if ((m_FromSquare.Row - 1 == m_ToSquare.Row) && (m_FromSquare.Column + 1 == m_ToSquare.Column))
                {
                    isValidMove = true;
                }

                break;

            case Player.eShapeType.O:
                if ((m_FromSquare.Row + 1 == m_ToSquare.Row) && (m_FromSquare.Column - 1 == m_ToSquare.Column))
                {
                    isValidMove = true;
                }

                if ((m_FromSquare.Row + 1 == m_ToSquare.Row) && (m_FromSquare.Column + 1 == m_ToSquare.Column))
                {
                    isValidMove = true;
                }

                break;
            }

            return(isValidMove);
        }
コード例 #3
0
        internal int GetPointsOfPlayer(Player.eShapeType i_Piece)
        {
            int countPlayerPoints = 0;

            switch (i_Piece)
            {
            case Player.eShapeType.X:

                for (int i = 0; i < this.m_Size; i++)
                {
                    for (int j = 0; j < this.m_Size; j++)
                    {
                        Square currentSquare = this.m_Board[i, j];
                        if (currentSquare.Type == Square.eSquareType.X)
                        {
                            countPlayerPoints += 1;
                        }

                        if (currentSquare.Type == Square.eSquareType.K)
                        {
                            countPlayerPoints += 4;
                        }
                    }
                }

                break;

            case Player.eShapeType.O:

                for (int i = 0; i < this.m_Size; i++)
                {
                    for (int j = 0; j < this.m_Size; j++)
                    {
                        Square currentSquare = this.m_Board[i, j];
                        if (currentSquare.Type == Square.eSquareType.O)
                        {
                            countPlayerPoints += 1;
                        }

                        if (currentSquare.Type == Square.eSquareType.U)
                        {
                            countPlayerPoints += 4;
                        }
                    }
                }

                break;
            }

            return(countPlayerPoints);
        }
コード例 #4
0
        private List <Move> getListOfJumpsForPiece(Player.eShapeType i_Shape, Square i_Square)
        {
            int         squareRow    = i_Square.Row;
            int         squareColumn = i_Square.Column;
            Move        currentMove;
            List <Move> leggalJumpsForPiece = m_BoardGame.GetListOfPlayerJumps(i_Shape);

            for (int i = 0; i < leggalJumpsForPiece.Count; i++)
            {
                currentMove = leggalJumpsForPiece[i];

                if (currentMove.FromSquare.Row != squareRow || currentMove.FromSquare.Column != squareColumn)
                {
                    leggalJumpsForPiece.Remove(currentMove);
                }
            }

            return(leggalJumpsForPiece);
        }
コード例 #5
0
        public List <Move> GetListOfPlayerJumps(Player.eShapeType i_Shape)
        {
            List <Move> leggalJumps = new List <Move>();
            short       boardSize   = this.GetSize();

            for (int r = 0; r < boardSize; r++)
            {
                for (int c = 0; c < boardSize; c++)
                {
                    switch (i_Shape)
                    {
                    case Player.eShapeType.O:

                        // regular piece of O
                        if (getTypeOfSquareInBoard(r, c) == Square.eSquareType.O)
                        {
                            if ((getTypeOfSquareInBoard(r + 2, c - 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.X || getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.K))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r + 2, c - 2)));
                            }

                            if ((getTypeOfSquareInBoard(r + 2, c + 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.X || getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.K))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r + 2, c + 2)));
                            }
                        }

                        // King of O
                        if (getTypeOfSquareInBoard(r, c) == Square.eSquareType.U)
                        {
                            if ((getTypeOfSquareInBoard(r + 2, c - 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.X || getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.K))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r + 2, c - 2)));
                            }

                            if ((getTypeOfSquareInBoard(r + 2, c + 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.X || getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.K))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r + 2, c + 2)));
                            }

                            if ((getTypeOfSquareInBoard(r - 2, c - 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.X || getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.K))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r - 2, c - 2)));
                            }

                            if ((getTypeOfSquareInBoard(r - 2, c + 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.X || getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.K))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r - 2, c + 2)));
                            }
                        }

                        break;

                    case Player.eShapeType.X:

                        // regular piece of X
                        if (getTypeOfSquareInBoard(r, c) == Square.eSquareType.X)
                        {
                            if ((getTypeOfSquareInBoard(r - 2, c - 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.O || getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.U))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r - 2, c - 2)));
                            }

                            if ((getTypeOfSquareInBoard(r - 2, c + 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.O || getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.U))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r - 2, c + 2)));
                            }
                        }

                        // king of X
                        if (getTypeOfSquareInBoard(r, c) == Square.eSquareType.K)
                        {
                            if ((getTypeOfSquareInBoard(r + 2, c - 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.O || getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.U))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r + 2, c - 2)));
                            }

                            if ((getTypeOfSquareInBoard(r + 2, c + 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.O || getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.U))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r + 2, c + 2)));
                            }

                            if ((getTypeOfSquareInBoard(r - 2, c - 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.O || getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.U))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r - 2, c - 2)));
                            }

                            if ((getTypeOfSquareInBoard(r - 2, c + 2) == Square.eSquareType.None) && (getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.O || getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.U))
                            {
                                leggalJumps.Add(new Move(GetSquare(r, c), GetSquare(r - 2, c + 2)));
                            }
                        }

                        break;
                    }
                }
            }

            return(leggalJumps);
        }
コード例 #6
0
        internal List <Move> GetListOfPlayerDiagonalMoves(Player.eShapeType i_Shape)
        {
            List <Move> leggalMoves = new List <Move>();
            short       boardSize   = this.GetSize();

            for (int r = 0; r < boardSize; r++)
            {
                for (int c = 0; c < boardSize; c++)
                {
                    switch (i_Shape)
                    {
                    case Player.eShapeType.O:
                        // Regular piece of O
                        if (getTypeOfSquareInBoard(r, c) == Square.eSquareType.O)
                        {
                            if (getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r + 1, c - 1)));
                            }

                            if (getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r + 1, c + 1)));
                            }
                        }

                        // King of O
                        if (getTypeOfSquareInBoard(r, c) == Square.eSquareType.U)
                        {
                            if (getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r + 1, c - 1)));
                            }

                            if (getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r + 1, c + 1)));
                            }

                            if (getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r - 1, c - 1)));
                            }

                            if (getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r - 1, c + 1)));
                            }
                        }

                        break;

                    // regular piece for X
                    case Player.eShapeType.X:
                        if (getTypeOfSquareInBoard(r, c) == Square.eSquareType.X)
                        {
                            if (getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r - 1, c - 1)));
                            }

                            if (getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r - 1, c + 1)));
                            }
                        }

                        // King of X
                        if (getTypeOfSquareInBoard(r, c) == Square.eSquareType.K)
                        {
                            if (getTypeOfSquareInBoard(r + 1, c - 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r + 1, c - 1)));
                            }

                            if (getTypeOfSquareInBoard(r + 1, c + 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r + 1, c + 1)));
                            }

                            if (getTypeOfSquareInBoard(r - 1, c - 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r - 1, c - 1)));
                            }

                            if (getTypeOfSquareInBoard(r - 1, c + 1) == Square.eSquareType.None)
                            {
                                leggalMoves.Add(new Move(GetSquare(r, c), GetSquare(r - 1, c + 1)));
                            }
                        }

                        break;
                    }
                }
            }

            return(leggalMoves);
        }
コード例 #7
0
ファイル: Move.cs プロジェクト: matanelr/-Checkers-Game-
        public bool CheckIsValidMove(Player.eShapeType i_ShapeOfPlayer)
        {
            bool isValidMove = true;


            switch (i_ShapeOfPlayer)
            {
            case Player.eShapeType.X:
                if (m_FromSquare.Type != Square.eSquareType.X && m_FromSquare.Type != Square.eSquareType.K)
                {
                    isValidMove = false;
                }
                else
                {
                    if (m_ToSquare.Type != Square.eSquareType.None)
                    {
                        isValidMove = false;
                    }
                    else
                    {
                        if (m_FromSquare.Type == Square.eSquareType.X)
                        {
                            isValidMove = isValidDiagonalMove(Player.eShapeType.X);
                        }
                        else
                        {
                            isValidMove = isValidDiagonalKingMove(Player.eShapeType.X);
                        }
                    }
                }
                break;

            case Player.eShapeType.O:

                if (m_FromSquare.Type != Square.eSquareType.O && m_FromSquare.Type != Square.eSquareType.U)
                {
                    isValidMove = false;
                }
                else
                {
                    if (m_ToSquare.Type != Square.eSquareType.None)
                    {
                        isValidMove = false;
                    }
                    else
                    {
                        if (m_FromSquare.Type == Square.eSquareType.O)
                        {
                            isValidMove = isValidDiagonalMove(Player.eShapeType.O);
                        }

                        else
                        {
                            isValidMove = isValidDiagonalKingMove(Player.eShapeType.O);
                        }
                    }
                }
                break;
            }

            return(isValidMove);
        }