Пример #1
0
        public void PickPair(ModelBoard i_DataBoard, Position io_FirstChoicePosition, Position io_SecondChoicePosition)
        {
            char signValue;

            // copmputer AI algoritem to pick pair of squares:
            if (ChoosePairFromMemory(io_FirstChoicePosition, io_SecondChoicePosition))
            {
                m_BoardMemory[io_FirstChoicePosition.Row, io_FirstChoicePosition.Col].IsTaken   = true;
                m_BoardMemory[io_SecondChoicePosition.Row, io_SecondChoicePosition.Col].IsTaken = true;
            }
            else
            {
                PickSquare(io_FirstChoicePosition);                                                     // select first square in a naive way.
                signValue = i_DataBoard.GetSignFromCompleteBoard(io_FirstChoicePosition);               // gets the sign value from the complete board
                m_BoardMemory[io_FirstChoicePosition.Row, io_FirstChoicePosition.Col].Sign = signValue; // updates first naive choise sign to memory board

                if (SearchMatchInMemory(signValue, io_FirstChoicePosition, io_SecondChoicePosition))
                {
                    UpdateMemory(i_DataBoard, io_FirstChoicePosition, io_SecondChoicePosition, true);
                }
                else
                {
                    PickSquare(io_SecondChoicePosition); // select secound square in a naive way.

                    if (i_DataBoard.IsIdenticalPair(io_FirstChoicePosition, io_SecondChoicePosition))
                    {
                        UpdateMemory(i_DataBoard, io_FirstChoicePosition, io_SecondChoicePosition, true);
                    }
                    else  // failed to find a match sqaures
                    {
                        UpdateMemory(i_DataBoard, io_FirstChoicePosition, io_SecondChoicePosition, false);
                    }
                }
            }
        }
Пример #2
0
        private void playerVsComputer()
        {
            while (m_GameStillRuning)
            {
                m_MainPlayer.Score = 0;
                bool isMainPlayerTurn = true;
                m_IsRoundRuning = true;
                Computer aiComputer;

                startRound();
                aiComputer = new Computer(m_DataBoard.BoardHeight, m_DataBoard.BoardWidth);

                // turns start:
                while (m_IsRoundRuning)
                {
                    if (isMainPlayerTurn)
                    {
                        MessageOrganizer.TurnMsg(m_MainPlayer.Name);
                    }
                    else
                    {
                        MessageOrganizer.TurnMsg();
                    }

                    MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard);

                    if (isMainPlayerTurn)
                    {
                        playerPairPick();
                    }
                    else // COMPUTER AI PICK
                    {
                        aiComputer.PickPair(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice);
                        showComputerPicks();
                    }

                    if (m_DataBoard.IsIdenticalPair(m_FirstSquareChoice, m_SecondSquareChoice))
                    {
                        if (isMainPlayerTurn)
                        {
                            aiComputer.UpdateMemory(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice, true);
                            m_MainPlayer.Score++;
                        }
                        else
                        {
                            aiComputer.Score++;
                        }

                        if (checkFullBoard(m_MainPlayer.Score, aiComputer.Score))
                        {
                            string winnerName = gameWinner(string.Empty, aiComputer.Score);
                            endRound(winnerName);
                        }
                    }
                    else
                    {
                        aiComputer.UpdateMemory(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice, false);
                        m_DataBoard.RemovePairFromRealTimeBoard(m_FirstSquareChoice, m_SecondSquareChoice);

                        isMainPlayerTurn = !(isMainPlayerTurn);

                        System.Threading.Thread.Sleep(2000); // if its not a matched pair let the viewers see the board for additonal  second(2 second total)
                    }
                }
            }
        }