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