Exemplo n.º 1
0
        private bool isKingMove(Vector.Vector2 i_Destinition, GameBoard io_GameBoard)
        {
            bool    result    = false;
            int     kingOfset = -1;
            Vector2 rivalLocation;

            if (IsKing())
            {
                result = tryKingEat(false, i_Destinition, io_GameBoard, kingOfset, out rivalLocation);
                if (result)
                {
                    io_GameBoard.OnEatMove(rivalLocation);
                }
                else
                {
                    result = tryKingEat(false, i_Destinition, io_GameBoard, -kingOfset, out rivalLocation);
                    if (result)
                    {
                        io_GameBoard.OnEatMove(rivalLocation);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public bool TryEat(bool i_JustScaning, Vector.Vector2 i_Destinition, GameBoard io_GameBoard)
        {
            int     ofset     = this.GetOfset;
            int     kingOfset = -1;
            bool    result    = false;
            Vector2 rivalLocation;

            if (this.GetGroup == GameLogic.CurrentPlayerGroup && GameLogic.CheckBorders(i_Destinition, io_GameBoard.BoardHeight) && io_GameBoard.IsLocationEmpty(i_Destinition))
            {
                if (this.m_Location.GetColumn - i_Destinition.GetColumn == -2 * ofset && this.m_Location.GetRow - i_Destinition.GetRow == 2 * ofset)
                {
                    rivalLocation = new Vector2(this.m_Location.GetColumn + (1 * ofset), this.m_Location.GetRow - (1 * ofset));
                    result        = GameLogic.CheckBordersOfMove(this.GetLocation, i_Destinition, io_GameBoard.BoardHeight) &&
                                    io_GameBoard.GetTypeOfPieceByLocation(rivalLocation) == this.GetOtherGroupPlayer();
                    if (result && !i_JustScaning)
                    {
                        io_GameBoard.OnEatMove(rivalLocation);
                        eat(rivalLocation, i_Destinition, io_GameBoard);
                    }
                }
                else if (this.m_Location.GetColumn - i_Destinition.GetColumn == 2 * ofset && this.m_Location.GetRow - i_Destinition.GetRow == 2 * ofset)
                {
                    rivalLocation = new Vector2(this.m_Location.GetColumn - (1 * ofset), this.m_Location.GetRow - (1 * ofset));
                    result        = GameLogic.CheckBordersOfMove(this.GetLocation, i_Destinition, io_GameBoard.BoardHeight) && io_GameBoard.GetTypeOfPieceByLocation(rivalLocation) == this.GetOtherGroupPlayer();
                    if (result && !i_JustScaning)
                    {
                        io_GameBoard.OnEatMove(rivalLocation);
                        eat(rivalLocation, i_Destinition, io_GameBoard);
                    }
                }
                else if (this.m_Type == 'K' || this.m_Type == 'U')
                {
                    if (!i_JustScaning)
                    {
                        result = tryKingEat(i_JustScaning, i_Destinition, io_GameBoard, kingOfset, out rivalLocation);
                        if (result)
                        {
                            io_GameBoard.OnEatMove(rivalLocation);
                        }
                        else
                        {
                            result = tryKingEat(i_JustScaning, i_Destinition, io_GameBoard, -kingOfset, out rivalLocation);
                            if (result)
                            {
                                io_GameBoard.OnEatMove(rivalLocation);
                            }
                        }
                    }
                }
                else
                {
                    result = false;
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        private bool isNewKing(Vector.Vector2 i_Destinition, GameBoard io_GameBoard)
        {
            bool result = false;

            if (GetGroup == 'X' && i_Destinition.GetRow == 0)
            {
                result = true;
                io_GameBoard[i_Destinition] = new Piece(io_GameBoard[this.m_Location].GetKingTypeByGroup(), i_Destinition);
            }
            else if (GetGroup == 'O' && i_Destinition.GetRow == io_GameBoard.BoardHeight - 1)
            {
                result = true;
                io_GameBoard[i_Destinition] = new Piece(io_GameBoard[this.m_Location].GetKingTypeByGroup(), i_Destinition);
            }

            return(result);
        }
Exemplo n.º 4
0
        private void eat(Vector2 i_RivalLocation, Vector.Vector2 i_Destinition, GameBoard io_GameBoard)
        {
            GameLogic.AddScore(io_GameBoard[i_RivalLocation]);

            io_GameBoard[i_RivalLocation] = null;
            if (!isNewKing(i_Destinition, io_GameBoard))
            {
                io_GameBoard[i_Destinition] = new Piece(this.m_Type, i_Destinition);
            }
            else
            {
                io_GameBoard.OnNewKing(io_GameBoard[i_Destinition]);
            }

            io_GameBoard.OnMove(io_GameBoard[i_Destinition]);
            io_GameBoard[this.m_Location] = null;
        }
Exemplo n.º 5
0
        public bool Move(Vector.Vector2 i_Destinition, GameBoard io_GameBoard)
        {
            bool result = false;

            if (io_GameBoard[i_Destinition] == null && this.GetGroup == GameLogic.CurrentPlayerGroup)
            {
                result = isNormalMove(i_Destinition, io_GameBoard) || isKingMove(i_Destinition, io_GameBoard);
                if (result)
                {
                    if (!isNewKing(i_Destinition, io_GameBoard))
                    {
                        io_GameBoard[i_Destinition] = new Piece(this.m_Type, i_Destinition);
                    }

                    io_GameBoard[this.m_Location] = null;
                    io_GameBoard.OnMove(io_GameBoard[i_Destinition]);
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        private bool isNormalMove(Vector.Vector2 i_Destinition, GameBoard io_GameBoard)
        {
            bool result;

            int rowDistance       = this.m_Location.GetRow - i_Destinition.GetRow;
            int columnrowDistance = this.m_Location.GetColumn - i_Destinition.GetColumn;

            if (this.GetPieceType == 'X' && rowDistance == -1)
            {
                result = false;
            }
            else if (this.GetPieceType == 'O' && rowDistance == 1)
            {
                result = false;
            }
            else
            {
                result = io_GameBoard.IsLocationEmpty(i_Destinition) && Math.Abs(rowDistance) == 1 && Math.Abs(columnrowDistance) == 1;
            }

            return(result);
        }
Exemplo n.º 7
0
        private bool tryKingEat(bool i_JustScaning, Vector.Vector2 i_Destinition, GameBoard io_GameBoard, int i_KingOfset, out Vector2 io_RivalLocation)
        {
            bool    result        = false;
            Vector2 rivalLocation = null;

            if (this.m_Location.GetColumn - i_Destinition.GetColumn == -2 * i_KingOfset)
            {
                if (this.m_Location.GetRow - i_Destinition.GetRow == 2 * i_KingOfset)
                {
                    rivalLocation = new Vector2(this.m_Location.GetColumn + (1 * i_KingOfset), this.m_Location.GetRow - (1 * i_KingOfset));
                    result        = GameLogic.CheckBordersOfMove(this.GetLocation, i_Destinition, io_GameBoard.BoardHeight) && io_GameBoard.GetTypeOfPieceByLocation(rivalLocation) == this.GetOtherGroupPlayer();

                    if (result && !i_JustScaning)
                    {
                        eat(rivalLocation, i_Destinition, io_GameBoard);
                    }
                }
                else if (this.m_Location.GetRow - i_Destinition.GetRow == -2 * i_KingOfset)
                {
                    rivalLocation = new Vector2(this.m_Location.GetColumn + (1 * i_KingOfset), this.m_Location.GetRow + (1 * i_KingOfset));
                    result        = GameLogic.CheckBordersOfMove(this.GetLocation, i_Destinition, io_GameBoard.BoardHeight) && io_GameBoard.GetTypeOfPieceByLocation(rivalLocation) == this.GetOtherGroupPlayer();

                    if (result && !i_JustScaning)
                    {
                        eat(rivalLocation, i_Destinition, io_GameBoard);
                    }
                }

                if (result == true)
                {
                    io_GameBoard.SubtractionSumOfPiecesGroupOnBoard(GetOtherGroupPlayer());
                }
            }

            io_RivalLocation = rivalLocation;
            return(result);
        }
Exemplo n.º 8
0
        public static bool CheckMove(Piece i_CurrentPiece, Vector.Vector2 i_Destinition, GameBoard io_GameBoard, ref bool io_HasAnotherEatMove, ref bool o_PrintMustEatError, bool i_IsPcMove, ref Vector2 o_PcMoveLocation)
        {
            bool    result = false, hasMoved = false, didEat = false, isEatMove, isGenericEatMoveAvailable = false;
            Vector2 pcStartMoveLocation = new Vector2(-1, -1);

            o_PrintMustEatError = false;
            if (!i_IsPcMove)
            {
                if (i_CurrentPiece != null)
                {
                    if (CheckBordersOfMove(i_CurrentPiece.GetLocation, i_Destinition, io_GameBoard.BoardHeight) && i_CurrentPiece.GetGroup == s_currentPlayerGroup)
                    {
                        isEatMove = didEat = i_CurrentPiece.TryEat(false, i_Destinition, io_GameBoard);
                        if (!isEatMove)
                        {
                            isGenericEatMoveAvailable = isEatMoveAvailable(io_GameBoard, (Piece.eSoldierTypes)i_CurrentPiece.GetPieceType);
                            if (isGenericEatMoveAvailable)
                            {
                                o_PrintMustEatError = true;
                                result = false;
                            }
                        }

                        if (!isGenericEatMoveAvailable)
                        {
                            if (didEat)
                            {
                                io_HasAnotherEatMove = isSpecificEatMoveAvailable(io_GameBoard, io_GameBoard[i_Destinition]);
                                if (!io_HasAnotherEatMove)
                                {
                                    result = true;
                                }
                            }

                            if ((!io_HasAnotherEatMove || isEatMove) && !didEat)
                            {
                                hasMoved = i_CurrentPiece.Move(i_Destinition, io_GameBoard);
                                result   = hasMoved || didEat;
                            }
                            else if (io_HasAnotherEatMove && !isEatMove)
                            {
                                o_PrintMustEatError = true;
                            }

                            if (io_HasAnotherEatMove)
                            {
                                result = !true;
                            }
                        }
                    }
                }
            }
            else
            {
                o_PcMoveLocation = MakePcRandomMove(io_GameBoard, ref hasMoved, ref io_HasAnotherEatMove, out pcStartMoveLocation);
                if (!hasMoved || io_HasAnotherEatMove)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }

            return(result);
        }
Exemplo n.º 9
0
 public static bool CheckBorders(Vector.Vector2 i_Location, int i_Length)
 {
     return(i_Location.GetColumn >= 0 && i_Location.GetColumn < i_Length && i_Location.GetRow >= 0 && i_Location.GetRow < i_Length);
 }