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");
        }
Beispiel #2
0
        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)
            {
            }
        }
Beispiel #4
0
        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);
 }
Beispiel #6
0
 public PlayerAdapter(Socket socket)
 {
     _player = new PlayerWrapper(socket);
 }
Beispiel #7
0
 public PlayerAdapter(string aiType, int n = 1)
 {
     _player = new PlayerWrapper(aiType, n);
 }
 public PlayerAdapter(bool remote, int port = 0)
 {
     _player = new PlayerWrapper(remote, port);
 }
Beispiel #9
0
 public PlayerAdapter(int port)
 {
     _player = new PlayerWrapper(port);
 }