/* * 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]); }
static void Main() { model = new ReversiModel(); generator = new Generator(model); opponentPassed = false; Color opponentColor; try { AIGenerator.Cell blackHole = ReadCell(); playerColor = ReadColor(); opponentColor = playerColor == Color.Black ? Color.White : Color.Black; generator.StartGame(blackHole, playerColor); if (playerColor == Color.Black) { generator.MakeMove(); } while (!generator.GameIsOver || !opponentPassed) { opponentPassed = false; AIGenerator.Cell opponentMoveCell = ReadOpponentMove(); if (!opponentPassed) { model.PutChip(opponentMoveCell.X, opponentMoveCell.Y); } else { model.Pass(opponentColor); } generator.MakeMove(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }