private static RoboPlayerPlugin SetupRoboPlayer(RoboManager roboManager, String kiExecutable, bool relative) { RoboPlayerPlugin roboPlugin = RoboUtils.RegisterPlugin(roboManager, kiExecutable, relative); roboManager.ActivatePlugin(roboPlugin); return(roboPlugin); }
private static void RoboManager_GameStateChange(RoboManager sender, EventArgs <RoboGameState> e) { switch (e.Value) { case RoboGameState.Stopped: autoEvent.Set(); break; } }
private static RoboManager SetupRoboManager() { Console.WriteLine("Init RoboManager"); RoboManager roboManager = new RoboManager(); roboManager.GameStateChange += RoboManager_GameStateChange; return(roboManager); }
private static String FindPluginName(RoboManager roboManager, String initialName) { IEnumerable <String> pluginNames = roboManager.AvailablePlugins.Select(plugin => plugin.Name); String pluginName = initialName; int nameDifferentiater = 1; while (pluginNames.Contains(pluginName)) { nameDifferentiater++; pluginName = initialName + nameDifferentiater; } return(pluginName); }
// MonoRobots.exe --play <relative_ki> <relative_board> <difficulty?> private static void PlayGame(String kiPath, String boardPath, Difficulty difficulty) { RoboManager roboManager = SetupRoboManager(); RoboPlayerPlugin roboPlugin = SetupRoboPlayer(roboManager, kiPath, true); RoboBoard board = RoboUtils.LoadBoard(boardPath, true, difficulty); Console.WriteLine("Start..."); ExecuteGame(roboManager, board, RoboUtils.CreateCardPile()); Console.Write(GetResults(roboManager)); Console.WriteLine("End..."); }
public static RoboPlayerPlugin RegisterPlugin(RoboManager roboManager, String executablePath, bool isRelativePath) { String pluginName = Path.GetFileName(executablePath); pluginName = FindPluginName(roboManager, pluginName.Substring(0, pluginName.IndexOf('.'))); RoboPlayerFileIOWrapper roboPlugin = new RoboPlayerFileIOWrapper(); roboPlugin.ExecutablePath = (isRelativePath ? Directory.GetCurrentDirectory() + "/" : "") + executablePath; roboPlugin.Name = pluginName; roboManager.AvailablePlugins.Add(roboPlugin); Console.WriteLine("Initialized KI: " + roboPlugin.ExecutablePath); return(roboPlugin); }
private static String GetResults(RoboManager roboManager) { StringBuilder builder = new StringBuilder("All players reached the destination or died:\r\n\r\n"); foreach (RoboPlayer player in roboManager.ActivePlayers.Select(plugin => plugin.Player).OrderBy(elem => elem.TotalPlayedCards)) { player.EndGame(); builder.Append(player.Name.ToUpper()); switch (player.PlayerState) { case RoboPlayerState.Dead: builder.AppendLine(" died painfully after " + player.TotalTimeElapsed.Milliseconds + " milliseconds online! (RIP)"); builder.AppendLine("(Elapsed rounds: " + player.Round + "; Played cards: " + player.TotalPlayedCards + ")"); break; case RoboPlayerState.Error: builder.AppendLine(" had a system error after " + player.TotalTimeElapsed.Milliseconds + " milliseconds online! (BEEEeeep)"); builder.AppendLine("(Elapsed rounds: " + player.Round + "; Played cards: " + player.TotalPlayedCards + ")"); break; case RoboPlayerState.Finished: builder.AppendLine(" reached the destination after " + player.TotalTimeElapsed.Milliseconds + " milliseconds online! (Yeah)"); builder.AppendLine("(Elapsed rounds: " + player.Round + "; Played cards: " + player.TotalPlayedCards + ")"); break; case RoboPlayerState.Ready: builder.AppendLine(" is still ready??? Someone is cheating!!!"); break; case RoboPlayerState.Stopped: builder.AppendLine(" is out of energy - a late joiner?!"); break; case RoboPlayerState.Thinking: builder.AppendLine(" is still thinking?! Hello?! Game is over?!"); break; } builder.AppendLine(); } return(builder.ToString()); }
// MonoRobots.exe --stats <relative_ki> <relative_boards> <relative_decks> private static void Statistics(String kiPath, String boardsPath, String decksPath, Difficulty difficulty) { RoboManager roboManager = SetupRoboManager(); Dictionary <String, Dictionary <String, List <RoboPlayerResult> > > allResults = new Dictionary <String, Dictionary <String, List <RoboPlayerResult> > >(); int roundsPlayedInTotal = 0; foreach (String boardFileName in getFileEnumerable(boardsPath)) { RoboBoard board = RoboUtils.LoadBoard(boardFileName, true, difficulty); foreach (String pluginPath in getFileEnumerable(kiPath)) { RoboPlayerPlugin roboPlugin = SetupRoboPlayer(roboManager, pluginPath, true); Dictionary <String, List <RoboPlayerResult> > boardResults = new Dictionary <String, List <RoboPlayerResult> >(); allResults[boardFileName] = boardResults; List <RoboPlayerResult> playerResults = new List <RoboPlayerResult>(); boardResults.Add(pluginPath, playerResults); foreach (String deckFileName in getFileEnumerable(decksPath)) { RoboCard[] pile = RoboUtils.LoadCardDeck(deckFileName); ExecuteGame(roboManager, board, pile); roundsPlayedInTotal++; RoboPlayerResult singleStat = new RoboPlayerResult(roboPlugin.Player); playerResults.Add(singleStat); } roboManager.DeactivatePlugin(roboPlugin); } } Console.WriteLine("RoundsPlayed: " + roundsPlayedInTotal); Console.Write(GetFormattedStatistics(allResults)); }
public static RoboPlayerPlugin RegisterPlugin(RoboManager roboManager, String executablePath) { return(RegisterPlugin(roboManager, executablePath, false)); }
private static void ExecuteGame(RoboManager roboManager, RoboBoard board, RoboCard[] deck) { roboManager.StartGame(board, deck); roboManager.StartRound(); autoEvent.WaitOne(); }