Esempio n. 1
0
        public List <Utilities.ValidStep> getAllValidSteps(char i_shape)
        {
            Utilities.ValidStep curretnValidStep;
            Utilities.Point     currentPoint;
            string stringShape = i_shape.ToString();

            List <Utilities.ValidStep> AllValidSteps = new List <Utilities.ValidStep>();

            for (int j = 0; j < m_HeightAndWidth; ++j)
            {
                for (int i = 0; i < m_HeightAndWidth; ++i)
                {
                    if (isAValidPoint(i, j, stringShape))
                    {
                        currentPoint     = new Utilities.Point(i, j);
                        curretnValidStep = new Utilities.ValidStep(currentPoint);

                        checkAllDirectionsOfPoint(curretnValidStep, currentPoint, stringShape);
                        AllValidSteps.Add(curretnValidStep);
                    }
                }
            }

            return(AllValidSteps);
        }
Esempio n. 2
0
        private bool checkContinueOfSequence(Utilities.Point i_validStepPoint, int i_xDirection, int i_yDirection, String i_playerShape)
        {
            int currentXpoint = i_validStepPoint.X();
            int currentYpoint = i_validStepPoint.Y();

            currentXpoint += i_xDirection;
            currentYpoint += i_yDirection;

            if ((isPointInBorder(currentXpoint, currentYpoint)))
            {
                if ((m_board[currentXpoint, currentYpoint] != null) && (m_board[currentXpoint, currentYpoint] != i_playerShape))
                {
                    while ((isPointInBorder(currentXpoint, currentYpoint)))
                    {
                        if (m_board[currentXpoint, currentYpoint] == i_playerShape)
                        {
                            return(true);
                        }
                        currentXpoint += i_xDirection;
                        currentYpoint += i_yDirection;
                    }
                }
            }
            return(false);
        }
Esempio n. 3
0
        private bool isAValidPoint(int i, int j, string i_shape)
        {
            if ((m_board[i, j] != null))
            {
                return(false);
            }

            Utilities.Point currentPoint = new Utilities.Point(i, j);

            return((checkContinueOfSequence(currentPoint, (int)Direction.LEFT, (int)Direction.NoChange, i_shape)) ||

                   (checkContinueOfSequence(currentPoint, (int)Direction.LEFT, (int)Direction.UP, i_shape)) ||

                   (checkContinueOfSequence(currentPoint, (int)Direction.NoChange, (int)Direction.UP, i_shape)) ||

                   (checkContinueOfSequence(currentPoint, (int)Direction.RIGHT, (int)Direction.UP, i_shape)) ||

                   (checkContinueOfSequence(currentPoint, (int)Direction.RIGHT, (int)Direction.NoChange, i_shape)) ||

                   (checkContinueOfSequence(currentPoint, (int)Direction.RIGHT, (int)Direction.DOWN, i_shape)) ||

                   (checkContinueOfSequence(currentPoint, (int)Direction.NoChange, (int)Direction.DOWN, i_shape)) ||

                   (checkContinueOfSequence(currentPoint, (int)Direction.LEFT, (int)Direction.DOWN, i_shape)));
        }
Esempio n. 4
0
        public Utilities.checkNextStepForTheProgram CheckVaildStepAndUpdateBoard(Utilities.Point i_pointToCheck)
        {
            if (m_whichPlayerPlay == 1)
            {
                if (!tryDoHumanTurn(i_pointToCheck, m_playerOne))
                {
                    if (CounterAmountOfPlayerWithNoTurn == amoutOfPlayerWithNoTurn.TwoPlayer)
                    {
                        return(Utilities.checkNextStepForTheProgram.TwoPlayerCantPlay);
                    }

                    return(Utilities.checkNextStepForTheProgram.IllegalStep);
                }

                if (!m_playerTwo.isAHuman())
                {
                    if (CounterAmountOfPlayerWithNoTurn == amoutOfPlayerWithNoTurn.TwoPlayer)
                    {
                        return(Utilities.checkNextStepForTheProgram.TwoPlayerCantPlay);
                    }

                    tryDoComputerTurn();
                    m_whichPlayerPlay = 1;
                }
                else
                {
                    m_whichPlayerPlay = 2;
                }

                return(Utilities.checkNextStepForTheProgram.ValidStep);
            }
            else
            {
                if (!tryDoHumanTurn(i_pointToCheck, m_playerTwo))
                {
                    if (CounterAmountOfPlayerWithNoTurn == amoutOfPlayerWithNoTurn.TwoPlayer)
                    {
                        return(Utilities.checkNextStepForTheProgram.TwoPlayerCantPlay);
                    }
                    return(Utilities.checkNextStepForTheProgram.IllegalStep);
                }
                else
                {
                    m_whichPlayerPlay = 1;
                }
                return(Utilities.checkNextStepForTheProgram.ValidStep);
            }
        }
Esempio n. 5
0
        private bool isStepIsValid(List <Utilities.ValidStep> i_validSteps, Utilities.Point i_pointToCheck)
        {
            int sizeOfList = i_validSteps.Count;

            Utilities.ValidStep[] CloneValidSteps = new Utilities.ValidStep[sizeOfList];
            i_validSteps.CopyTo((CloneValidSteps));

            foreach (Utilities.ValidStep currentStepToCheck in CloneValidSteps)
            {
                if (!(currentStepToCheck.GetPoint().X() == i_pointToCheck.X() && currentStepToCheck.GetPoint().Y() == i_pointToCheck.Y()))
                {
                    i_validSteps.Remove(currentStepToCheck);
                }
            }

            return(i_validSteps.Count > 0);
        }
Esempio n. 6
0
        private void checkAllDirectionsOfPoint(Utilities.ValidStep i_validStep, Utilities.Point i_currentPoint, string i_stringShape)
        {
            if (checkContinueOfSequence(i_currentPoint, (int)Direction.LEFT, (int)Direction.NoChange, i_stringShape))
            {
                i_validStep.AddDirection(new Utilities.Point((int)Direction.LEFT, (int)Direction.NoChange));
            }

            if (checkContinueOfSequence(i_currentPoint, (int)Direction.LEFT, (int)Direction.UP, i_stringShape))
            {
                i_validStep.AddDirection(new Utilities.Point((int)Direction.LEFT, (int)Direction.UP));
            }

            if (checkContinueOfSequence(i_currentPoint, (int)Direction.NoChange, (int)Direction.UP, i_stringShape))
            {
                i_validStep.AddDirection(new Utilities.Point((int)Direction.NoChange, (int)Direction.UP));
            }

            if (checkContinueOfSequence(i_currentPoint, (int)Direction.RIGHT, (int)Direction.UP, i_stringShape))
            {
                i_validStep.AddDirection(new Utilities.Point((int)Direction.RIGHT, (int)Direction.UP));
            }

            if (checkContinueOfSequence(i_currentPoint, (int)Direction.RIGHT, (int)Direction.NoChange, i_stringShape))
            {
                i_validStep.AddDirection(new Utilities.Point((int)Direction.RIGHT, (int)Direction.NoChange));
            }

            if (checkContinueOfSequence(i_currentPoint, (int)Direction.RIGHT, (int)Direction.DOWN, i_stringShape))
            {
                i_validStep.AddDirection(new Utilities.Point((int)Direction.RIGHT, (int)Direction.DOWN));
            }

            if (checkContinueOfSequence(i_currentPoint, (int)Direction.NoChange, (int)Direction.DOWN, i_stringShape))
            {
                i_validStep.AddDirection(new Utilities.Point((int)Direction.NoChange, (int)Direction.DOWN));
            }

            if (checkContinueOfSequence(i_currentPoint, (int)Direction.LEFT, (int)Direction.DOWN, i_stringShape))
            {
                i_validStep.AddDirection(new Utilities.Point((int)Direction.LEFT, (int)Direction.DOWN));
            }
        }
Esempio n. 7
0
        private bool tryDoHumanTurn(Utilities.Point i_pointToCheck, Player i_PlayerToPlay)
        {
            List <Utilities.ValidStep> validSteps;

            if ((isTurnPossible(out validSteps, i_PlayerToPlay)))
            {
                m_board.ReduceBlankCells();
                CounterAmountOfPlayerWithNoTurn = amoutOfPlayerWithNoTurn.ZeroPlayer;

                if ((isStepIsValid(validSteps, i_pointToCheck)))
                {
                    m_board.updateBoard(validSteps[0], i_PlayerToPlay.getShape().ToString());
                    return(true);
                }
            }
            else
            {
                updateAmountOfPlayerThatDontPlay();
            }


            return(false);
        }