public static bool isItSafeToBomb(Position bomb, Position me, int range, int steps)
        {
            var explode = IsItSafeToStand(bomb);

            if (explode > 0 && explode < 4)
            {
                return(false);
            }


            if (bomb.x != me.x && bomb.y != me.y)
            {
                return(true);
            }

            if (Math.Abs(bomb.x - me.x) >= range)
            {
                return(true);
            }

            if (Math.Abs(bomb.y - me.y) >= range)
            {
                return(true);
            }

            if (steps == 0)
            {
                return(false);
            }
            steps--;

            foreach (var d in new String[] { "top", "bot", "right", "left" })
            {
                var nextP = me.go(d, 1);
                if (Grid.isFree(nextP) && !nextP.Equals(bomb))
                {
                    if (isItSafeToBomb(bomb, nextP, range, steps))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
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);
        }