Example #1
0
        private static BitSolution randomSolution(BitState g, int playerId, int depth)
        {
            var movesTimer = new Stopwatch();

            //var playTimer = new Stopwatch();
            //var scoreTimer = new Stopwatch();

            movesTimer.Start();
            var s = new BitSolution();

            movesTimer.Stop();
            //Console.Error.WriteLine("Time to construct BitSolution: {0}", movesTimer.ElapsedMilliseconds);

            for (int d = 0; d < depth; d++)
            {
                //movesTimer.Start();
                var moves = g.getMoves(playerId);
                //movesTimer.Stop();
                var move = moves[rnd.Next(moves.Count)];
                //playTimer.Start();
                g.play(move, playerId);
                //playTimer.Stop();
                s.moves.Add(move);

                if (!g.getBot(playerId).isAlive)
                {
                    break;
                }
            }

            //scoreTimer.Start();
            s.score = g.score(playerId);
            //scoreTimer.Stop();

            //Console.Error.WriteLine("Moves: {0} ms", movesTimer.ElapsedMilliseconds);
            //Console.Error.WriteLine("Play: {0} ms", playTimer.ElapsedMilliseconds);
            //Console.Error.WriteLine("Score: {0} ms", scoreTimer.ElapsedMilliseconds);
            //Console.Error.WriteLine();

            return(s);
        }
Example #2
0
        static void Main()
        {
            int turnNumber = 0;

            string[] inputs;
            inputs = Console.ReadLine().Split(' ');
            int width  = int.Parse(inputs[0]);
            int height = int.Parse(inputs[1]);
            int myId   = int.Parse(inputs[2]);

            BitMaps.GenerateMoves();
            BitMaps.GenerateBombs();

            // game loop
            while (true)
            {
                turnNumber++;

                char[,] map = new char[width, height];
                List <Robot> bots  = new List <Robot>();
                List <Bomb>  bombs = new List <Bomb>();

                for (int i = 0; i < height; i++)
                {
                    var row = Console.ReadLine().ToCharArray();
                    for (int j = 0; j < width; j++)
                    {
                        map[j, i] = row[j];
                    }
                }

                int entities = int.Parse(Console.ReadLine());
                for (int i = 0; i < entities; i++)
                {
                    inputs = Console.ReadLine().Split(' ');

                    var entityType = int.Parse(inputs[0]);
                    if (entityType == Constants.ENTITY_ROBOT)
                    {
                        var r = new Robot
                        {
                            owner = int.Parse(inputs[1])
                        };

                        var x = int.Parse(inputs[2]);
                        var y = int.Parse(inputs[3]);
                        r.position = BitState.GetBitIndex(x, y);
                        r.param1   = int.Parse(inputs[4]);
                        r.param2   = int.Parse(inputs[5]);

                        bots.Add(r);
                    }
                    else if (entityType == Constants.ENTITY_ITEM)
                    {
                        if (int.Parse(inputs[4]) == Constants.ITEM_RANGE)
                        {
                            map[int.Parse(inputs[2]), int.Parse(inputs[3])] = Constants.MAP_ITEM_RANGE;
                        }
                        else
                        {
                            map[int.Parse(inputs[2]), int.Parse(inputs[3])] = Constants.MAP_ITEM_BOMB;
                        }
                    }
                    else
                    {
                        var r = new Bomb
                        {
                            owner = int.Parse(inputs[1])
                        };

                        var x = int.Parse(inputs[2]);
                        var y = int.Parse(inputs[3]);
                        r.position = BitState.GetBitIndex(x, y);
                        r.param1   = int.Parse(inputs[4]);
                        r.param2   = int.Parse(inputs[5]);

                        bombs.Add(r);
                        map[x, y] = Constants.MAP_BOMB;
                    }
                }

                var bgs = new BitState(map, bots, bombs, turnNumber);

                var best = BitSolution.generateBestRandomSolution(bgs, myId, 20, 80);

                Console.WriteLine(bgs.getBot(myId).getCommand(best.moves[0]) + " " + best.score);

                bgs.play(best.moves[0], myId);
                Console.Error.WriteLine(bgs.score(myId));
            }
        }