//Test robot mode (black) static void Test2() { ReversiModel model = new ReversiModel(); RandomUser robot = new RandomUser(model); model.SwitchMove += (s, ea) => { Console.WriteLine("Switch move {0}", ea.CurrentPlayerColor); }; model.SwitchMove += (s, ea) => { Console.WriteLine(ea.AllowedCells.Count); foreach (Cell cell in ea.AllowedCells) { Console.WriteLine("{0} {1}", cell.X, cell.Y); } }; robot.Enable(Color.White); model.NewGame(); while (true) { int x = int.Parse(Console.ReadLine()); int y = int.Parse(Console.ReadLine()); model.PutChip(x, y); } }
//Simulates human to human game mode static void Test1() { ReversiModel model = new ReversiModel(); model.WrongMove += (s, ea) => { Console.WriteLine("Wrong move"); }; model.SwitchMove += (s, ea) => { Console.WriteLine("Switch move {0}", ea.CurrentPlayerColor); }; model.SwitchMove += (s, ea) => { foreach (Cell cell in ea.AllowedCells) { Console.WriteLine("{0} {1}", cell.X, cell.Y); } }; model.CountChanged += (s, ea) => { Console.WriteLine("count {0} {1}", ea.CountBlack, ea.CountWhite); }; model.NewGame(); while (true) { int x = int.Parse(Console.ReadLine()); int y = int.Parse(Console.ReadLine()); model.PutChip(x, y); } }
//convert coordinates and put chip private void PutChip(string cellName) { int x = Int32.Parse(cellName[0].ToString()); int y = Int32.Parse(cellName[1].ToString()); model.PutChip(x, y); }
/* * Method that makes random move into one of allowed cells * ----------------------------------------- * allowedCells - cells where user currently can put chip into */ private void MakeMove(SortedSet <Cell> allowedCells) { int randAllowedCellNumber = rand.Next(allowedCells.Count); Cell currentMoveCell = allowedCells.ToList()[randAllowedCellNumber]; model.PutChip(currentMoveCell.X, currentMoveCell.Y); }
/* * Makes next move if it is possible */ public void MakeMove() { GameIsOver = false; Cell moveCell = GetCellToMakeMove(); if (GameIsOver) { return; } model.PutChip(moveCell.X, moveCell.Y); Console.WriteLine("{0}{1}", (char)('A' + moveCell.Y), (char)('1' + moveCell.X)); }
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); } }
//Test robot mode (playing for color you want) static void Test3(Color userColor) { ReversiModel model = new ReversiModel(); RandomUser robot = new RandomUser(model); model.NewGameStarted += (s, ea) => { Console.WriteLine("Game started."); }; model.SwitchMove += (s, ea) => { Console.WriteLine("Switch move {0}", ea.CurrentPlayerColor); }; model.SwitchMove += (s, ea) => { Console.WriteLine(ea.AllowedCells.Count); foreach (Cell cell in ea.AllowedCells) { Console.WriteLine("{0} {1}", cell.X, cell.Y); } }; Color robotColor; if (userColor == Color.Black) { robotColor = Color.White; } else { robotColor = Color.Black; } robot.Enable(robotColor); model.NewGame(); while (true) { int x = int.Parse(Console.ReadLine()); int y = int.Parse(Console.ReadLine()); model.PutChip(x, y); } }