예제 #1
0
        public void doTurn(ref Int32[] touch, ABlast.Board Board)
        {
            Random rnd = new Random();

            touch[0] = rnd.Next(0, 9);
            touch[1] = rnd.Next(0, 9);
        }
        static void Main(string[] args)
        {
            Ai AI = new Ai();

            var socket = IO.Socket(AI.ServerAdr);

            socket.On(Socket.EVENT_CONNECT, () =>
            {
                Console.WriteLine("Connected...");
                socket.Emit("init", AI.Token);
            });

            while (true)
            {
                socket.On("result", (data) =>
                {
                    try
                    {
                        JObject OResource = JObject.FromObject(data);
                        Int32 Score       = Convert.ToInt32(OResource["score"]);
                        Int32 TurnNumber  = Convert.ToInt32(OResource["turn_number"]);

                        JArray AResource = JArray.Parse(OResource["data"].ToString());

                        List <ABlast.Cell> Map = new List <ABlast.Cell>();

                        foreach (var Items in AResource)
                        {
                            foreach (var Item in Items)
                            {
                                if (Item["type"].ToString() == "black")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.JailedBird, (Int32)ABlast.ColorType.Black, (Int32)ABlast.Direction.NoDirection, 0);
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "red")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.JailedBird, (Int32)ABlast.ColorType.Red, (Int32)ABlast.Direction.NoDirection, 0);
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "green")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.JailedBird, (Int32)ABlast.ColorType.Green, (Int32)ABlast.Direction.NoDirection, 0);
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "blue")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.JailedBird, (Int32)ABlast.ColorType.Blue, (Int32)ABlast.Direction.NoDirection, 0);
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "yellow")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.JailedBird, (Int32)ABlast.ColorType.Yellow, (Int32)ABlast.Direction.NoDirection, 0);
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "bomb")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.Bomb, (Int32)ABlast.ColorType.NoColor, (Int32)ABlast.Direction.NoDirection, 0);
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "laser")
                                {
                                    Int32 color = 0;
                                    switch (Item["color"].ToString())
                                    {
                                    case "red":
                                        color = (Int32)ABlast.ColorType.Red;
                                        break;

                                    case "yellow":
                                        color = (Int32)ABlast.ColorType.Yellow;
                                        break;

                                    case "blue":
                                        color = (Int32)ABlast.ColorType.Blue;
                                        break;

                                    case "green":
                                        color = (Int32)ABlast.ColorType.Green;
                                        break;

                                    case "black":
                                        color = (Int32)ABlast.ColorType.Black;
                                        break;
                                    }
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.Laser, (Int32)color, (Int32)ABlast.Direction.NoDirection, 0);
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "rocket")
                                {
                                    Int32 direction = 0;
                                    switch (Item["direction"].ToString())
                                    {
                                    case "0":
                                        direction = 0;
                                        break;

                                    case "1":
                                        direction = 1;
                                        break;
                                    }

                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.Rocket, (Int32)ABlast.ColorType.NoColor, (Int32)direction, 0);
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "glass")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.Glass, (Int32)ABlast.ColorType.NoColor, (Int32)ABlast.Direction.NoDirection, Convert.ToInt32(Item["life_time"].ToString()));
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "wood")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.Wood, (Int32)ABlast.ColorType.NoColor, (Int32)ABlast.Direction.NoDirection, Convert.ToInt32(Item["life_time"].ToString()));
                                    Map.Add(cell);
                                }
                                else if (Item["type"].ToString() == "rock")
                                {
                                    ABlast.Cell cell = new ABlast.Cell((Int32)ABlast.Type.Rock, (Int32)ABlast.ColorType.NoColor, (Int32)ABlast.Direction.NoDirection, Convert.ToInt32(Item["life_time"].ToString()));
                                    Map.Add(cell);
                                }
                            }
                        }

                        ABlast.Board Board = new ABlast.Board(Score, TurnNumber, Map);

                        Int32[] touch = new Int32[2];

                        AI.doTurn(ref touch, Board);

                        socket.Emit("touch", AI.Token, touch[0], touch[1]);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                });
            }
        }