public static void PlayAgainstStandardAI(IBot bot) { // TODO: One or more of the following: // 1. Get the process that this spawns, so we can terminate it on close // 2. Find a better way to spawn the game process directly, so we don't // have to get a second process that this one spawns // 3. Check if there's already a waiting client so we can reuse it var info = new ProcessStartInfo(GAME_EXECUTABLE_PATH); info.WorkingDirectory = BASE_GAME_PATH + "/Support64"; info.Arguments = GAME_EXECUTABLE_ARGS_PLAYER1; using (Process gameProcess = Process.Start(info)) { using (var client = new SynchronousApiClient("ws://127.0.0.1:5000/sc2api")) { if (!client.InitiateGameAgainstComputer(LADDER_ABYSSAL_REEF_MAP_PATH, Race.Terran, Difficulty.MediumHard)) { return; } var gameState = client.GetGameState(); //SaveMapData(gameState); while (true) { var commands = bot.Act(gameState); client.SendCommands(commands); client.Step(); gameState = client.GetGameState(); } } } }
public static void PlayOneOnOne(IBot bot1, IBot bot2) { // TODO: One or more of the following: // 1. Get the process that this spawns, so we can terminate it on close // 2. Find a better way to spawn the game process directly, so we don't // have to get a second process that this one spawns // 3. Check if there's already a waiting client so we can reuse it // TODO: Reduce duplication var info1 = new ProcessStartInfo(GAME_EXECUTABLE_PATH); info1.WorkingDirectory = BASE_GAME_PATH + "/Support64"; info1.Arguments = GAME_EXECUTABLE_ARGS_PLAYER1; var info2 = new ProcessStartInfo(GAME_EXECUTABLE_PATH); info2.WorkingDirectory = BASE_GAME_PATH + "/Support64"; info2.Arguments = GAME_EXECUTABLE_ARGS_PLAYER2; using (Process gameProcess1 = Process.Start(info1)) { using (Process gameProcess2 = Process.Start(info2)) { using (var client1 = new SynchronousApiClient("ws://127.0.0.1:5000/sc2api")) { bot1.Register(client1); using (var client2 = new SynchronousApiClient("ws://127.0.0.1:5001/sc2api")) { bot2.Register(client2); var initiateGameSuccess = client1.InitiateGameAgainstBot(LADDER_ABYSSAL_REEF_MAP_PATH, bot1.Race, bot2.Race); if (!client2.JoinGameAgainstBot(bot2.Race)) { return; } if (!initiateGameSuccess.Result) { return; } var gameState1 = client1.GetGameState(); var gameState2 = client2.GetGameState(); //SaveMapData(gameState1); while (true) { client1.SendCommands(bot1.Act(gameState1)); client2.SendCommands(bot2.Act(gameState2)); client1.Step(); client2.Step(); gameState1 = client1.GetGameState(); gameState2 = client2.GetGameState(); } } } } } }