private ResultDetails PlayMatch(Dictionary <Player, IAIAlgorithm> algorithms, int matchNumber, Action <int> updateTurn) { var board = new CheckerBoard(); board.InitializeBoard(); Stopwatch matchStopwatch = new Stopwatch(); Stopwatch stopwatch = new Stopwatch(); int turns = 0; matchStopwatch.Start(); while (board.GetGameStatus() == GameStatuses.Running) { updateTurn(turns); stopwatch.Reset(); stopwatch.Start(); var move = algorithms[board.NextPlayer].GetMove(board, board.NextPlayer); stopwatch.Stop(); if (move == null) { return(new ResultDetails(MatchResult.NoMoreMoves, matchStopwatch.Elapsed, turns)); } Console.WriteLine($"\tTurn #{matchNumber}.{turns}; Player {board.NextPlayer}; ({move.piece1.Row}, {move.piece1.Column}) to ({move.piece2.Row}, {move.piece2.Column}); Elapsed: {stopwatch.ElapsedMilliseconds} ms"); board.MakeMove(move, board.NextPlayer); if (board.GetGameStatus() != GameStatuses.Running) { var result = board.GetGameStatus(); if (result == GameStatuses.RedWon) { return(new ResultDetails(MatchResult.RedWon, matchStopwatch.Elapsed, algorithms[board.NextPlayer].GetType(), turns)); } else if (result == GameStatuses.BlackWon) { return(new ResultDetails(MatchResult.BlackWon, matchStopwatch.Elapsed, algorithms[board.NextPlayer].GetType(), turns)); } else { throw new Exception($"Unsupported result: {result}"); } } if (++turns >= this.MaxTurnsPerMatch) { return(new ResultDetails(MatchResult.MaxTurnsReached, matchStopwatch.Elapsed, turns)); } } return(new ResultDetails(MatchResult.NoResult, matchStopwatch.Elapsed, turns)); }
private static void dfsTurnDuration() { var board = new CheckerBoard(); board.InitializeBoard(); var dfsai = new DfsAI(1, new ListHelpers(new RandomService())); var sw = new Stopwatch(); sw.Start(); dfsai.GetMove(board, Player.Black); sw.Stop(); Console.WriteLine($"Elapsed: {sw.Elapsed.TotalMilliseconds} ms"); }
private static void checkMctsNoMoves() { var board = new CheckerBoard(); board.InitializeBoard(); board.Parse(@"EEEEECEE REEEEEEE EBEEEEEE EEBEEEEE EEEEEEEE EEEEEEEE EBEEEEEE EEEEEEEE ", Player.Black); var simpleMoves = board.GetSimpleMoves(Player.Black); var jumpMoves = board.GetJumpMoves(Player.Black); }
// Start is called before the first frame update void Start() { board.InitializeBoard(); unitManager.AddUnit(playerTower); unitManager.AddUnit(enemyTower); foreach (Unit.BaseAvator unit in playerUnit) { unitManager.AddUnit(unit); } foreach (Unit.BaseAvator unit in enemyUnit) { unitManager.AddUnit(unit); } board.Setup(unitManager); unitManager.SetBoard(board); unitManager.InitializeUnit(); }