private void buildBoard(List <char> i_CardsData) { Random random = new Random(); List <MattLocation> emptyPlaces = new List <MattLocation>(); for (int row = 0; row < m_Rows; row++) { for (int col = 0; col < m_Cols; col++) { emptyPlaces.Add(new MattLocation(row, col)); } } int key = 1; foreach (var card in i_CardsData) { for (int i = 1; i <= 2; i++) { int randomEmptyIndex = random.Next(emptyPlaces.Count); MattLocation location = emptyPlaces[randomEmptyIndex]; emptyPlaces.RemoveAt(randomEmptyIndex); m_Board[location.Row, location.Col] = new BoardCell <char>(card, location, key); } key++; } }
public void GetPicksForPlayerAI(out MattLocation io_Pick1, out MattLocation io_Pick2) { MemoryCell matchMemoryCell; if (m_PlayerAI.IsNoMove() == false) { m_PlayerAI.GetMove(out io_Pick1); OpenCard(io_Pick1); m_PlayerAI.GetMove(out io_Pick2); } else { generateRandomPick(out io_Pick1); OpenCard(io_Pick1); int firstPickCardKey = m_GameBoard.Board[io_Pick1.Row, io_Pick1.Col].Key; if (isFoundMatchCell(firstPickCardKey, out matchMemoryCell) == false) { m_PlayerAI.Memory.Add(new MemoryCell(io_Pick1, firstPickCardKey)); generateRandomPick(out io_Pick2); } else { io_Pick2 = matchMemoryCell.Location; } } }
private void generateRandomPick(out MattLocation io_Pick) { int randomIndexInPossibleMoves; List <MattLocation> possibleMoves = new List <MattLocation>(); Random random = new Random(); bool stop; foreach (var cell in m_GameBoard.Board) { if (cell.Visible == false) { possibleMoves.Add(cell.Location); } } do { randomIndexInPossibleMoves = random.Next(possibleMoves.Count); if (m_PlayerAI.IsCellInMemory(possibleMoves[randomIndexInPossibleMoves]) == true) { possibleMoves.RemoveAt(randomIndexInPossibleMoves); stop = false; } else { stop = true; } }while (stop == false); io_Pick = possibleMoves[randomIndexInPossibleMoves]; }
private void closeCards(MattLocation i_Location1, MattLocation i_Location2) { m_GameBoard.Board[i_Location1.Row, i_Location1.Col].Hide(); m_GameBoard.Board[i_Location2.Row, i_Location2.Col].Hide(); if (s_Opponent == ePlayer.PlayerAI) { saveToMemory(i_Location1, m_GameBoard.Board[i_Location1.Row, i_Location1.Col].Key, i_Location2, m_GameBoard.Board[i_Location2.Row, i_Location2.Col].Key); } }
public void GetMove(out MattLocation io_Pick) { io_Pick = null; if (m_Moves.Count != 0) { io_Pick = m_Moves[0].Location; m_Moves.RemoveAt(0); } }
private void printCurrentSituation(MattLocation i_Pick) { Ex02.ConsoleUtils.Screen.Clear(); printBoard(); Console.WriteLine(playerTurnInfo()); if (m_Logic.GetPlayerTurn == GameLogics.ePlayer.PlayerAI) { Console.WriteLine("\n * Player AI picked : {0}{1} * ", Convert.ToChar(i_Pick.Col + 65), i_Pick.Row + 1); } }
private bool isPairFound(MattLocation i_Location1, MattLocation i_Location2) { bool result = false; if (m_GameBoard.Board[i_Location1.Row, i_Location1.Col] == m_GameBoard.Board[i_Location2.Row, i_Location2.Col]) { result = true; } return(result); }
private void removeFromPlayerAIList(MattLocation i_Location, List <MemoryCell> i_List) { int cardKey = m_GameBoard.Board[i_Location.Row, i_Location.Col].Key; foreach (var memoryCell in i_List) { if (memoryCell.Location == i_Location && memoryCell.CardKey == cardKey) { i_List.Remove(memoryCell); break; } } }
public bool IsCellInMoves(MattLocation i_Location) { bool result = false; foreach (var moveCell in m_Moves) { if (i_Location == moveCell.Location) { result = true; break; } } return(result); }
public bool IsCellInMemory(MattLocation i_Location) { bool result = false; foreach (var cell in m_Memory) { if (i_Location == cell.Location) { result = true; break; } } return(result); }
private void saveMemoryOrAddMove(MattLocation i_Location, int i_CardKey) { MemoryCell matchMemoryCell; if (m_PlayerAI.IsCellInMemory(i_Location) == false) { MemoryCell temp = new MemoryCell(i_Location, i_CardKey); if (isFoundMatchCell(temp.CardKey, out matchMemoryCell) == false) { m_PlayerAI.Memory.Add(temp); } else { m_PlayerAI.Moves.Add(temp); m_PlayerAI.Moves.Add(matchMemoryCell); m_PlayerAI.Memory.Remove(matchMemoryCell); } } }
public void PlayTurn(MattLocation i_Pick1, MattLocation i_Pick2) { if (isPairFound(i_Pick1, i_Pick2) == false) { System.Threading.Thread.Sleep(2000); closeCards(i_Pick1, i_Pick2); m_TurnNumber++; } else { if (s_Opponent == ePlayer.PlayerAI) { System.Threading.Thread.Sleep(2000); deleteFromMemoryAndMovesOfPlayerAI(i_Pick1, i_Pick2); } m_GameBoard.CouplesLeft--; addScore(GetPlayerTurn); } }
private MattLocation pickCard() { string errorMsg; string cardLocation; MattLocation location = null; bool result; do { printBoard(); Console.WriteLine(playerTurnInfo()); Console.WriteLine("Please enter column character and the row number to open a card:"); cardLocation = Console.ReadLine(); if (m_Logic.IsValidColumn(cardLocation, out errorMsg) != false) { if (m_Logic.IsValidRow(cardLocation, out errorMsg) != false) { cardLocation = cardLocation.ToUpper(); if (m_Logic.IsCellValid(Convert.ToInt32(cardLocation[1] - '0') - 1, Convert.ToInt32(cardLocation[0] - 'A'), out errorMsg) != false) { location = new MattLocation(Convert.ToInt32(cardLocation[1] - '0') - 1, Convert.ToInt32(cardLocation[0] - 'A')); m_Logic.OpenCard(location); } } } if (errorMsg != string.Empty) { Ex02.ConsoleUtils.Screen.Clear(); result = false; Console.WriteLine(errorMsg); } else { result = true; } }while (result == false); return(location); }
private void deleteFromMemoryAndMovesOfPlayerAI(MattLocation i_Pick1, MattLocation i_Pick2) { if (m_PlayerAI.IsCellInMemory(i_Pick1) == true) { removeFromPlayerAIList(i_Pick1, m_PlayerAI.Memory); } if (m_PlayerAI.IsCellInMemory(i_Pick2) == true) { removeFromPlayerAIList(i_Pick2, m_PlayerAI.Memory); } if (m_PlayerAI.IsCellInMoves(i_Pick1) == true) { removeFromPlayerAIList(i_Pick1, m_PlayerAI.Moves); } if (m_PlayerAI.IsCellInMoves(i_Pick2) == true) { removeFromPlayerAIList(i_Pick2, m_PlayerAI.Moves); } }
public MemoryCell(MattLocation i_Location, int i_Cardkey) { m_Location = i_Location; m_CardKey = i_Cardkey; }
public BoardCell(T i_Data, MattLocation i_Location, int i_Key) { m_Data = i_Data; m_Location = i_Location; m_Key = i_Key; }
private void saveToMemory(MattLocation i_Location1, int i_CardKey1, MattLocation i_Location2, int i_CardKey2) { saveMemoryOrAddMove(i_Location1, i_CardKey1); saveMemoryOrAddMove(i_Location2, i_CardKey2); }
public void OpenCard(MattLocation i_Location) { m_GameBoard.Board[i_Location.Row, i_Location.Col].Show(); Ex02.ConsoleUtils.Screen.Clear(); }