Esempio n. 1
0
        public Choice GetSecondChoice()
        {
            Choice result = null;

            if (m_SecondChoice != null)
            {
                result = new Choice(m_SecondChoice);
            }
            else
            {
                if (m_FirstChoice != null)
                {
                    if (r_ActiveCellsMemory.ContainsKey(m_FirstChoice.Letter))
                    {
                        result = new Choice(r_ActiveCellsMemory[m_FirstChoice.Letter][0]);
                    }
                }
                else
                {
                    result = getEducatedGuess();
                }
            }

            m_FirstChoice  = null;
            m_SecondChoice = null;

            return(result);
        }
Esempio n. 2
0
 private void removeLetterFromMemory(Board.Cell i_Cell)
 {
     if (i_Cell != null)
     {
         r_ActiveCellsMemory.Remove(i_Cell.Letter);
     }
 }
Esempio n. 3
0
        public void PerformComputerMove()
        {
            while (true)
            {
                Choice firstChoice = m_ComputerPlayer.GetFirstChoice();
                m_FirstChoice = m_Board.GetCellAt(firstChoice.Line, firstChoice.Col);
                m_Board.GetCellAt(firstChoice.Line, firstChoice.Col).Selected = true;
                Thread.Sleep(400);
                Choice secondChoice = m_ComputerPlayer.GetSecondChoice();
                m_SecondChoice = m_Board.GetCellAt(secondChoice.Line, secondChoice.Col);
                m_Board.GetCellAt(secondChoice.Line, secondChoice.Col).Selected = true;
                Thread.Sleep(400);

                if (IsMatchFound)
                {
                    performComputerPlayerForget();
                    incrementCurrentPlayerScore();
                    setChoicesPermanentOnBoard();
                    checkForGameOver();
                    if (IsGameOver)
                    {
                        break;
                    }
                }
                else
                {
                    performComputerPlayerSave();
                    clearLastChoicesFromBoard();
                    swapPlayers();
                    break;
                }
            }
        }
Esempio n. 4
0
 public void ForgetCellThatIsAlreadyVisibleOnBoard(Board.Cell i_Cell)
 {
     if (i_Cell != null)
     {
         r_AlreadyVisibleCellsOnBoard.Add(new Board.Cell(i_Cell));
         removeLetterFromMemory(i_Cell);
     }
 }
Esempio n. 5
0
 public ComputerPlayer(int i_Lines, int i_Cols)
 {
     r_BoardLines = i_Lines;
     r_BoardCols  = i_Cols;
     r_MaxMemory  = computeMemory(i_Cols, i_Lines);
     r_AlreadyVisibleCellsOnBoard = new List <Board.Cell>();
     m_FirstChoice       = null;
     m_SecondChoice      = null;
     r_ActiveCellsMemory = new Dictionary <char, List <Board.Cell> >();
 }
Esempio n. 6
0
 public ComputerPlayer(int i_Lines, int i_Cols)
 {
     r_BoardLines = i_Lines;
     r_BoardCols = i_Cols;
     r_MaxMemory = computeMemory(i_Cols, i_Lines);
     r_AlreadyVisibleCellsOnBoard = new List<Board.Cell>();
     m_FirstChoice = null;
     m_SecondChoice = null;
     r_ActiveCellsMemory = new Dictionary<char, List<Board.Cell>>();
 }
Esempio n. 7
0
        private bool isInActiveMemory(Board.Cell i_Cell)
        {
            bool result;

            if (i_Cell != null)
            {
                result = isInActiveMemory(i_Cell.Line, i_Cell.Col);
            }
            else
            {
                result = false;
            }

            return(result);
        }
Esempio n. 8
0
        public Choice GetFirstChoice()
        {
            m_FirstChoice = m_SecondChoice = null;
            Choice result;

            if (knowsAboutPairPosition())
            {
                result = new Choice(m_FirstChoice);
            }
            else
            {
                result = getEducatedGuess();
                m_SecondChoice = null;
            }

            return result;
        }
Esempio n. 9
0
        private bool knowsAboutPairPosition()
        {
            bool foundPair = false;

            foreach (var kvp in r_ActiveCellsMemory)
            {
                if (kvp.Value.Count == 2)
                {
                    m_FirstChoice  = kvp.Value[0];
                    m_SecondChoice = kvp.Value[1];
                    foundPair      = true;
                    break;
                }
            }

            return(foundPair);
        }
Esempio n. 10
0
        public Choice GetFirstChoice()
        {
            m_FirstChoice = m_SecondChoice = null;
            Choice result;

            if (knowsAboutPairPosition())
            {
                result = new Choice(m_FirstChoice);
            }
            else
            {
                result         = getEducatedGuess();
                m_SecondChoice = null;
            }

            return(result);
        }
Esempio n. 11
0
        public void RememberCell(Board.Cell i_Cell)
        {
            if (i_Cell != null)
            {
                if (actualMemoryInUse() >= r_MaxMemory)
                {
                    removeFirstCellFromActiveMemory();
                }

                if (isInActiveMemory(i_Cell))
                {
                    return;
                }

                if (!r_ActiveCellsMemory.ContainsKey(i_Cell.Letter))
                {
                    r_ActiveCellsMemory.Add(i_Cell.Letter, new List <Board.Cell>());
                }

                r_ActiveCellsMemory[i_Cell.Letter].Add(new Board.Cell(i_Cell));
            }
        }
Esempio n. 12
0
 private void performHumanSecondMove(int i_Line, int i_Col)
 {
     m_SecondChoice = m_Board.GetCellAt(i_Line, i_Col);
     m_Board.GetCellAt(i_Line, i_Col).Selected = true;
     Thread.Sleep(200);
 }
Esempio n. 13
0
 private void performHumanFirstMove(int i_Line, int i_Col)
 {
     m_FirstChoice = m_Board.GetCellAt(i_Line, i_Col);
     m_Board.GetCellAt(i_Line, i_Col).Selected = true;
 }
Esempio n. 14
0
        public void PerformComputerMove()
        {
            while (true)
            {
                Choice firstChoice = m_ComputerPlayer.GetFirstChoice();
                m_FirstChoice = m_Board.GetCellAt(firstChoice.Line, firstChoice.Col);
                m_Board.GetCellAt(firstChoice.Line, firstChoice.Col).Selected = true;
                Thread.Sleep(400);
                Choice secondChoice = m_ComputerPlayer.GetSecondChoice();
                m_SecondChoice = m_Board.GetCellAt(secondChoice.Line, secondChoice.Col);
                m_Board.GetCellAt(secondChoice.Line, secondChoice.Col).Selected = true;
                Thread.Sleep(400);

                if (IsMatchFound)
                {
                    performComputerPlayerForget();
                    incrementCurrentPlayerScore();
                    setChoicesPermanentOnBoard();
                    checkForGameOver();
                    if (IsGameOver)
                    {
                        break;
                    }
                }
                else
                {
                    performComputerPlayerSave();
                    clearLastChoicesFromBoard();
                    swapPlayers();
                    break;
                }
            }
        }
Esempio n. 15
0
 private void performHumanSecondMove(int i_Line, int i_Col)
 {
     m_SecondChoice = m_Board.GetCellAt(i_Line, i_Col);
     m_Board.GetCellAt(i_Line, i_Col).Selected = true;
     Thread.Sleep(200);
 }
Esempio n. 16
0
        private bool knowsAboutPairPosition()
        {
            bool foundPair = false;

            foreach (var kvp in r_ActiveCellsMemory)
            {
                if (kvp.Value.Count == 2)
                {
                    m_FirstChoice = kvp.Value[0];
                    m_SecondChoice = kvp.Value[1];
                    foundPair = true;
                    break;
                }
            }

            return foundPair;
        }
Esempio n. 17
0
        public Choice GetSecondChoice()
        {
            Choice result = null;

            if (m_SecondChoice != null)
            {
                result = new Choice(m_SecondChoice);
            }
            else
            {
                if (m_FirstChoice != null)
                {
                    if (r_ActiveCellsMemory.ContainsKey(m_FirstChoice.Letter))
                    {
                        result = new Choice(r_ActiveCellsMemory[m_FirstChoice.Letter][0]);
                    }
                }
                else
                {
                    result = getEducatedGuess();
                }
            }

            m_FirstChoice = null;
            m_SecondChoice = null;

            return result;
        }
Esempio n. 18
0
 private void performHumanFirstMove(int i_Line, int i_Col)
 {
     m_FirstChoice = m_Board.GetCellAt(i_Line, i_Col);
     m_Board.GetCellAt(i_Line, i_Col).Selected = true;
 }