예제 #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);
        }
예제 #2
0
 private void removeLetterFromMemory(Board.Cell i_Cell)
 {
     if (i_Cell != null)
     {
         r_ActiveCellsMemory.Remove(i_Cell.Letter);
     }
 }
예제 #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;
                }
            }
        }
예제 #4
0
 public void ForgetCellThatIsAlreadyVisibleOnBoard(Board.Cell i_Cell)
 {
     if (i_Cell != null)
     {
         r_AlreadyVisibleCellsOnBoard.Add(new Board.Cell(i_Cell));
         removeLetterFromMemory(i_Cell);
     }
 }
예제 #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> >();
 }
예제 #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>>();
 }
예제 #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);
        }
예제 #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;
        }
예제 #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);
        }
예제 #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);
        }
예제 #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));
            }
        }
예제 #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);
 }
예제 #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;
 }
예제 #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;
                }
            }
        }
예제 #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);
 }
예제 #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;
        }
예제 #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;
        }
예제 #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;
 }