public JToken JsonCommand(JToken jtoken, string name = "no name", string AIType = "dumb", int n = 1) { JsonValidation.ValidateJTokenPlayer(jtoken); switch (jtoken.ElementAt(0).ToObject <string>()) { case "register": if (AIType == "less dumb") { _player = new PlayerWrapper(name, AIType, n); } else { _player = new PlayerWrapper(name, AIType); } return(JToken.Parse(JsonConvert.SerializeObject(name))); case "receive-stones": _player.ReceiveStones(jtoken.ElementAt(1).ToObject <string>()); return(JToken.Parse(JsonConvert.SerializeObject(null))); case "make-a-move": try { return(JToken.Parse(JsonConvert.SerializeObject(_player.MakeAMove( jtoken.ElementAt(1).ToObject <string[][][]>())))); } catch (PlayerException e) { return(JToken.Parse(JsonConvert.SerializeObject(e.Message))); } } throw new InvalidJsonInputException("Unrecognized JSONCommand passed to PlayerWrapper"); }
public PlayerClientIllegal(string ip, int port, string aiType, string configuration) { _configuration = configuration; if (aiType == "illegal") { _player = new PlayerWrapper(aiType, configuration); } else { _player = new PlayerWrapper("smart", 1); } _name = "illegal player - " + configuration; if (ip == "localhost") { ip = "127.0.0.1"; } IPAddress ipAddress = IPAddress.Parse(ip); IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port); // Creation TCP/IP Socket using Socket Class Costructor sender = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); ConnectToServer(localEndPoint); }
public PlayerClient(string ip, int port) { clientConnectionContainer = ConnectionFactory.CreateClientConnectionContainer(ip, port); clientConnectionContainer.ConnectionEstablished += ConnectionEstablished; clientConnectionContainer.ConnectionLost += ConnectionLost; _player = new PlayerWrapper(false); while (!clientConnectionContainer.IsAlive) { } }
public PlayerClient(string ip, int port, string aiType, int n = 1, string name = "my player client") { _player = new PlayerWrapper(aiType, n); _name = name; if (ip == "localhost") { ip = "127.0.0.1"; } IPAddress ipAddress = IPAddress.Parse(ip); IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port); // Creation TCP/IP Socket using Socket Class Costructor sender = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); ConnectToServer(localEndPoint); }
public PlayerIllegal(string configuration) { _configuration = configuration; _player = new PlayerWrapper("smart", 1); }
public PlayerAdapter(Socket socket) { _player = new PlayerWrapper(socket); }
public PlayerAdapter(string aiType, int n = 1) { _player = new PlayerWrapper(aiType, n); }
public PlayerAdapter(bool remote, int port = 0) { _player = new PlayerWrapper(remote, port); }
public PlayerAdapter(int port) { _player = new PlayerWrapper(port); }