Пример #1
0
 public void ReceiveCommand(GameStateCommand command)
 {
     switch (command.Key)
     {
         case "round":
             Round = int.Parse(command.Value);
             break;
         case "this_piece_type":
         {
             PieceType pieceType;
             PieceType = Enum.TryParse(command.Value, out pieceType) ? pieceType : PieceType.None;
             break;
         }
         case "next_piece_type":
         {
             PieceType pieceType;
             NextPieceType = Enum.TryParse(command.Value, out pieceType) ? pieceType : PieceType.None;
             break;
         }
         case "this_piece_position":
             var parse = (command.Value).Split(',');
             PiecePositionX = int.Parse(parse[0]);
             PiecePositionY = int.Parse(parse[1]);
             break;
         default:
             Console.WriteLine("Invalid game state command: {0}", command.Key);
             break;
     }
 }
Пример #2
0
        public void ReceiveCommand(GameStateCommand command)
        {
            switch (command.Key)
            {
            case "round":
                Round = int.Parse(command.Value);
                break;

            case "this_piece_type":
            {
                PieceType pieceType;
                PieceType = Enum.TryParse(command.Value, out pieceType) ? pieceType : PieceType.None;
                break;
            }

            case "next_piece_type":
            {
                PieceType pieceType;
                NextPieceType = Enum.TryParse(command.Value, out pieceType) ? pieceType : PieceType.None;
                break;
            }

            case "this_piece_position":
                var parse = (command.Value).Split(',');
                PiecePositionX = int.Parse(parse[0]);
                PiecePositionY = int.Parse(parse[1]);
                break;

            default:
                Console.WriteLine("Invalid game state command: {0}", command.Key);
                break;
            }
        }
Пример #3
0
        public EngineCommand PollCommand(Bot bot)
        {
            var line = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(line))
            {
                return(null);
            }

            EngineCommand command = null;
            var           parse   = line.Split(' ');

            switch (parse[0])
            {
            case "settings":
                command = new SettingsCommand(bot.MatchSettings, parse[1], parse[2]);
                break;

            case "update":
                if (parse[1] == "game")
                {
                    command = new GameStateCommand(bot.GameState, parse[2], parse[3]);
                }
                else
                {
                    if (bot.MatchSettings.PlayerNames.Contains(parse[1]))
                    {
                        if (!bot.Players.ContainsKey(parse[1]))
                        {
                            bot.Players.Add(parse[1], new PlayerState(bot.MatchSettings.FieldWidth, bot.MatchSettings.FieldHeight));
                        }

                        var player = bot.Players[parse[1]];
                        command = new PlayerCommand(player, parse[1], parse[2], parse[3]);
                    }
                    else
                    {
                        Console.WriteLine("Invalid player: '{0}'", parse[1]);
                    }
                }
                break;

            case "action":
                command = new BotCommand(bot, parse[1], parse[2]);
                break;
            }

            if (command == null)
            {
                Console.WriteLine("Invalid command: '{0}'", parse[0]);
            }

            return(command);
        }
Пример #4
0
        public EngineCommand PollCommand(Bot bot)
        {
            var line = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(line))
                return null;

            EngineCommand command = null;
            var parse = line.Split(' ');
            switch (parse[0])
            {
                case "settings":
                    command = new SettingsCommand(bot.MatchSettings, parse[1], parse[2]);
                    break;
                case "update":
                    if (parse[1] == "game")
                    {
                        command = new GameStateCommand(bot.GameState, parse[2], parse[3]);
                    }
                    else
                    {
                        if (bot.MatchSettings.PlayerNames.Contains(parse[1]))
                        {
                            if (!bot.Players.ContainsKey(parse[1]))
                            {
                                bot.Players.Add(parse[1], new PlayerState(bot.MatchSettings.FieldWidth, bot.MatchSettings.FieldHeight));
                            }

                            var player = bot.Players[parse[1]];
                            command = new PlayerCommand(player, parse[1], parse[2], parse[3]);
                        }
                        else
                        {
                            Console.WriteLine("Invalid player: '{0}'", parse[1]);
                        }
                    }
                    break;
                case "action":
                    command = new BotCommand(bot, parse[1], parse[2]);
                    break;
            }

            if (command == null)
            {
                Console.WriteLine("Invalid command: '{0}'", parse[0]);
            }

            return command;
        }