/* Returns color of winner in randomly generated game * -------------------------------------------- * boardState - board state from which game continues * currentPlayerColor - color of player that makes current move * passesCount - count of passes made in a row during the current game */ private Color?GetRandomWinner(BoardState boardState, Color currentPlayerColor, int passesCount) { Color oppositePlayerColor = (currentPlayerColor == Color.White) ? Color.Black : Color.White; if (passesCount == 2) { return(GetCurrentWinner(boardState)); } AllowedCellsSearcher cellsSearcher = new AllowedCellsSearcher(boardState, currentPlayerColor); SortedSet <Cell> allowedCellsSet = cellsSearcher.GetAllAllowedCells(); allowedCellsSet.Remove(blackHole); List <Cell> allowedCells = allowedCellsSet.ToList(); if (allowedCells.Count == 0) { return(GetRandomWinner(boardState, oppositePlayerColor, passesCount + 1)); } int moveNumber = rand.Next(allowedCells.Count); MakeMoveIntoBoardState(boardState, allowedCells[moveNumber], currentPlayerColor); return(GetRandomWinner(boardState, oppositePlayerColor, 0)); }
/* * Returns the best cell to make next move into */ private Cell GetCellToMakeMove() { AllowedCellsSearcher cellsSearcher = new AllowedCellsSearcher(currentBoardState, currentColor); SortedSet <Cell> allowedCellsSet = cellsSearcher.GetAllAllowedCells(); allowedCellsSet.Remove(blackHole); List <Cell> allowedCells = allowedCellsSet.ToList(); if (allowedCells.Count == 0) { GameIsOver = true; model.Pass(currentColor); Console.WriteLine("pass"); return(new Cell(0, 0)); } int bestWinRate = 0; int bestWinRateInd = 0; for (int j = 0; j < allowedCells.Count; j++) { int currentWinCount = CountRandomWinsFromMove(allowedCells[j]); if (currentWinCount > bestWinRate) { bestWinRate = currentWinCount; bestWinRateInd = j; } } return(allowedCells[bestWinRateInd]); }