public void Enter() { // first we connect to the gameserver var socket = new Socket(SocketType.Stream, ProtocolType.IP); socket.Connect(StartClient.IP, StartClient.Port); Adapter = new KettleAdapter(new NetworkStream(socket)); Adapter.OnGameJoined += OnGameJoined; Adapter.OnEntityChoices += OnEntityChoices; Adapter.OnEntitiesChosen += OnEntitiesChosen; Adapter.OnOptionsBlock += OnOptionsBlock; Adapter.OnUserUI += OnUserUI; Adapter.OnHistory += OnHistory; Adapter.SendMessage(StartClient.JoinGame); // and then we keep listening on the socket while (true) { if (!Adapter.HandleNextPacket()) { Console.WriteLine("Kettle session ended."); return; } } }
public void Enter() { // We wait until someone connects to this server while (true) { Socket gameserver = Listener.Accept(); KettleAdapter gameadapter = new KettleAdapter(new NetworkStream(gameserver)); gameadapter.OnStartClient += OnStartClient; try { while (true) { if (!gameadapter.HandleNextPacket()) { Console.WriteLine("Kettle AI server ended."); break; } } } catch (IOException) { Console.WriteLine("Connection closed"); } } }
public KettleSessionTest(Socket client) { Client = client; Adapter = new KettleAdapter(new NetworkStream(client)); Adapter.OnCreateGame += OnCreateGame; Adapter.OnConcede += OnConcede; Adapter.OnChooseEntities += OnChooseEntities; Adapter.OnSendOption += OnSendOption; }
public static void TestStep1(KettleAdapter adapter) { // test data source: https://github.com/HearthSim/SabberStone/blob/master/hslogs/GameStates.txt _adapter = adapter; Console.WriteLine("creating game"); _game = new Game(new GameConfig { StartPlayer = 1, Player1HeroClass = CardClass.MAGE, Player2HeroClass = CardClass.WARLOCK, SkipMulligan = false, FillDecks = true }); // Start the game and send the following powerhistory to the client _game.StartGame(); List <IPowerHistoryEntry> powerHistory = _game.PowerHistory.Last; foreach (IPowerHistoryEntry h in powerHistory) { QueuePacket(KettleHistoryEntry.From(h)); } SendQueue(); PowerEntityChoices entityChoices1 = PowerChoicesBuilder.EntityChoices(_game, _game.Player1.Choice); SendPacket(new KettleEntityChoices(entityChoices1)); PowerEntityChoices entityChoices2 = PowerChoicesBuilder.EntityChoices(_game, _game.Player2.Choice); SendPacket(new KettleEntityChoices(entityChoices2)); KettleAdapter.OnChooseEntitiesDelegate handleMulligan = null; handleMulligan = (KettleChooseEntities) => { // Handle the response to the mulligan (in a dynamic or hardcoded way) // this means sending the proper response/history and perhaps a ChosenEntities // If both players are handled, we can jump to game phase 2 if (_game.Step == Step.BEGIN_MULLIGAN && _game.Player1.MulliganState == Mulligan.DONE && _game.Player2.MulliganState == Mulligan.DONE) { _adapter.OnChooseEntities -= handleMulligan; _game.NextStep = Step.MAIN_BEGIN; TestStep2(); } }; _adapter.OnChooseEntities += handleMulligan; }
public KettleSession(Socket client) { Client = client; AiThreads = new List <Thread>(); Adapter = new KettleAdapter(new NetworkStream(client)); Adapter.OnCreateGame += OnCreateGame; Adapter.OnConcede += OnConcede; Adapter.OnChooseEntities += OnChooseEntities; Adapter.OnSendOption += OnSendOption; Adapter.OnStartClient += OnStartClient; }