Exemple #1
0
        public static String DoAction(Path path, Me me)
        {
            var action = "MOVE ";

            Console.Error.WriteLine("Gonna Hit " + path.maxHitIndex);


            if (path.road.Count() < 2)
            {
                return("MOVE " + me.p + " I got Nothing !!");
            }
            var im = path.road.First();

            path.road.RemoveFirst();
            var im2    = path.road.First();
            var target = im2.p;

            if (path.maxHitIndex == 0 || (path.maxHitIndex > -1 && path.road.ElementAt(path.maxHitIndex - 1).p.Equals(me.p)))
            {
                action = "BOMB ";
                if (!Safety.isItSafeToBomb(im.p, im2.p, Me.BombRange, 5))
                {
                    target = im.p;
                }
            }


            action = action + target;

            return(action);
        }
Exemple #2
0
        public Path walk(Path result, int steps, int counter = 0)
        {
            if (steps == 0)
            {
                return(result);
            }
            var curPosition = result.getLast();

            counter++;
            steps--;
            var   score      = float.MinValue;
            Path  p          = result;
            float variation  = 0;
            bool  change     = false;
            var   safeToBomb = false;

            foreach (var d in new string[] { "top", "bot", "right", "left", "none" })
            {
                var nextP     = curPosition.p.go(d, 1);
                var gonnaHurt = Safety.amIGonnaHurt(nextP, counter);

                if (Grid.isFree(nextP) || nextP.Equals(curPosition.p))
                {
                    safeToBomb = true;
                    variation += 0.1f;  // more choices
                    var path = walk(result.AddPosition(nextP), steps, counter);
                    if (path.score > score)
                    {
                        change = true;
                        score  = path.score;
                        p      = path;
                    }
                }
            }
            p.score     += variation;
            p.safeToBomb = (p.safeToBomb == false)? false : safeToBomb;
            return(p);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            string[] inputs;
            inputs = Console.ReadLine().Split(' ');
            int width  = int.Parse(inputs[0]);
            int height = int.Parse(inputs[1]);
            int myId   = int.Parse(inputs[2]);
            var target = new Position(6, 5);

            Grid.setGrid(height, width);

            Me    me    = new Me();
            Enemy enemy = new Enemy();

            // game loop
            while (true)
            {
                // calculate the Impact !
                LinkedList <Impact> ims   = new LinkedList <Impact>();
                LinkedList <Item>   its   = new LinkedList <Item>();
                LinkedList <Bomb>   bombs = new LinkedList <Bomb>();
                #region setup
                for (int i = 0; i < height; i++)
                {
                    string row = Console.ReadLine();
                    for (int j = 0; j < row.Length; j++)
                    {
                        Grid.g[j, i] = row[j];
                    }
                }
                int entities = int.Parse(Console.ReadLine());
                for (int i = 0; i < entities; i++)
                {
                    inputs = Console.ReadLine().Split(' ');
                    int entityType = int.Parse(inputs[0]);
                    int owner      = int.Parse(inputs[1]);
                    int x          = int.Parse(inputs[2]);
                    int y          = int.Parse(inputs[3]);
                    int p1         = int.Parse(inputs[4]);
                    int p2         = int.Parse(inputs[5]);

                    if (entityType == 0)
                    {
                        //Player
                        if (owner == myId)
                        {
                            me               = new Me(x, y, p1);
                            Me.BombRange     = p2;
                            Me.numberOfBombs = p1;
                        }
                        else
                        {
                            enemy = new Enemy(x, y, p1);
                        }
                    }
                    else if (entityType == 2)
                    {
                        its.AddLast(new Item(new Position(x, y), p1));
                    }
                    else
                    {
                        ims.AddLast(new Impact(new Position(x, y)));
                        bombs.AddFirst(new Bomb(x, y, p1, p2));
                        //Bomb
                        if (owner == myId)
                        {
                            me.bomb = new Bomb(p1);
                        }
                        else
                        {
                            enemy.bomb = new Bomb(p1);
                        }
                    }
                }
                #endregion
                // Set Gloabals
                Grid.boms = bombs;
                do
                {
                    Safety.SetMapOfDestruction();
                    Console.Error.WriteLine("Calibrating");
                } while (!Safety.calibrateExplosionChaine());


                // apply memory to make the dude move

                Grid.ApplyExplosions(ims);
                Grid.ApplyItems(its);
                Grid.ApplyBomPositions(bombs);



                var path = Brain.navigateDirs(me);

                Console.Error.WriteLine("Score : " + path.score);
                foreach (var im in path.road)
                {
                    Console.Error.WriteLine(im.p + " hits " + im.hits + " is it Safe " + Safety.IsItSafeToStand(im.p));
                }


                var action = Commander.DoAction(path, me);
                Console.WriteLine(action);
            }
        }
Exemple #4
0
        public Path AddPosition(Position p)
        {
            var im = new Impact(p);
            LinkedList <Impact> li = new LinkedList <Impact>(road);

            li.AddLast(im);

            Path path = new Path(li);

            path.score = score;
            var howSafe = Safety.IsItSafeToStand(p);

            if (Safety.isItSafeToBomb(p, p, Me.BombRange, 7))
            {
                var bonusSpeed = (howSafe > 4)? true : false;
                path.score += ((im.hits) * (3 + ((float)3 / (road.Count() + 1))));

                if (im.hits > maxHits || im.hits == maxHits && bonusSpeed)
                {
                    path.maxHits     = im.hits;
                    path.maxHitIndex = road.Count();
                }
                else
                {
                    path.maxHits     = maxHits;
                    path.maxHitIndex = maxHitIndex;
                }
            }

            if (Grid.isItem(p))
            {
                path.score += ((Me.numberOfBombs > 0)? 3 : 9);
            }


            var danger = (howSafe > 3) ? 1 : 100;

            if (Safety.IsItSafeToStand(p) > 0)
            {
                path.score = (path.score - ((3 + ((float)road.Count() / (float)howSafe)) * danger));
            }


            if (road.Count() > 0)
            {
                if (road.Last().p.Equals(p))
                {
                    path.score = path.score - (1 + (float)2 / road.Count());
                }
                if (road.Count() > 1)
                {
                    if (road.Last.Previous.Value.p.Equals(p))
                    {
                        path.score = path.score - (1 + (float)2 / road.Count());
                    }
                }
            }

            path.safeToBomb = safeToBomb;

            return(path);
        }