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");
        }
示例#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);
        }
示例#3
0
        public PlayerClient(string ip, int port)
        {
            clientConnectionContainer = ConnectionFactory.CreateClientConnectionContainer(ip, port);
            clientConnectionContainer.ConnectionEstablished += ConnectionEstablished;
            clientConnectionContainer.ConnectionLost        += ConnectionLost;

            _player = new PlayerWrapper(false);

            while (!clientConnectionContainer.IsAlive)
            {
            }
        }
示例#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);
        }
示例#5
0
 public PlayerIllegal(string configuration)
 {
     _configuration = configuration;
     _player        = new PlayerWrapper("smart", 1);
 }
示例#6
0
 public PlayerAdapter(Socket socket)
 {
     _player = new PlayerWrapper(socket);
 }
示例#7
0
 public PlayerAdapter(string aiType, int n = 1)
 {
     _player = new PlayerWrapper(aiType, n);
 }
示例#8
0
 public PlayerAdapter(bool remote, int port = 0)
 {
     _player = new PlayerWrapper(remote, port);
 }
示例#9
0
 public PlayerAdapter(int port)
 {
     _player = new PlayerWrapper(port);
 }