Beispiel #1
0
        public void Update(Board board)
        {
            Board    = board;
            Weights  = new float[board.Size, board.Size];
            AfkTimes = new int[board.Size, board.Size];

            IsIncreasedBlast = IncreasedRadiusHandler.IsIncreased(board, this);
            CanRemoteDamaged = RemoveControlHandler.CanDamaged(board, this);

            AfkPlayersHandler.UpdateAfkTimes(board, this);

            BombermanState.Update(board);

            FreeDirections                = FreeDirectionsHandler.GetFreeDirections(board, Utils.DirectionsWithStop);
            SafeFromGhostsDirections      = GhostHandler.GetSafeDirections(board, Utils.DirectionsWithStop);
            SafeFromAngryGhostsDirections = AngryGhostHandler.GetSafeDirections(board, this, Utils.DirectionsWithStop);
            TimesToBoom = TimesToBoomHandler.GetTimesToBoom(board, this);

            CanDamageBuff = CanDamageBuffHandler.GetCanDamageBuffMass(board, this);

            TimesToGhostMove = GhostPositionsHandler.GetTimeToGhostMove(board, this);

            // TODO: fix this method
            // GhostsWeights = GhostsWeightsHandler.GetGhostsWeights(board, this);

            Weights = DestroyableStaticObjectsWeightsHandler.Handle(board, this, Weights);

            BuffsWeightsHandler.UpdateWeights(board, this);

            IEnumerable <Direction> directions = Utils.DirectionsWithStop;

            if (UseFreeDirections)
            {
                var intersected = directions.Intersect(FreeDirections).ToArray();
                if (intersected.Any())
                {
                    directions = intersected;
                }
            }

            if (UseSafeFromGhostsDirections)
            {
                var intersected = directions.Intersect(SafeFromGhostsDirections).ToArray();
                if (intersected.Any())
                {
                    directions = intersected;
                }
            }

            if (UseSafeFromAngryGhostsDirections)
            {
                var intersected = directions.Intersect(SafeFromAngryGhostsDirections).ToArray();
                if (intersected.Any())
                {
                    directions = intersected;
                }
            }

            DirectionWeights =
                new DeepDirectionsWeightsHandler().GetWeights(board, this, directions, board.GetBomberman());

            if (DirectionWeights.Max(kvp => kvp.Value) <= 0) // костыль для обработки некорректного поведения, когда бомберман стоит впритык к мит чопперу
            {
                DirectionWeights = new DeepDirectionsWeightsHandler().GetWeights(board, this, FreeDirections.ToArray(), board.GetBomberman());
            }
        }
Beispiel #2
0
        public static SnakeAction Solve(GameBoard gameBoard)
        {
            DateTime start = DateTime.Now;

            GameSettings.UpdateSettings();

            if (DeadAndSleepHandler.IsDeadOrSleep(gameBoard))
            {
                MySnakeParameters.Reset();

                return(new SnakeAction(false, false, Direction.Up));
            }

            MySnakeParameters.UpdateBeforeMove(gameBoard);
            Log(MySnakeParameters.Body, "My snake body");

            var freeDirections = FreeDirectionsHandler.GetFreeDirections(gameBoard);

            Log(freeDirections, "Free directions");

            var enemyPlayersInfo = EnemySnakesHandler.GetEnemyPlayersInfo(gameBoard);

            Log(enemyPlayersInfo, "Enemy players info");

            var nonCollisionDirections = CollisionsHandler.GetFreeForCollisionDirections(gameBoard, enemyPlayersInfo, freeDirections.ToArray());

            Log(nonCollisionDirections, "Non collision directions");

            var staticWeights = StaticWeightsHandler.GetStaticWeights(gameBoard);

            Log(staticWeights, "Static weights");

            var dynamicWeights = DynamicWeightsHandler.GetWeights(gameBoard, nonCollisionDirections.ToArray());

            Log(dynamicWeights, "Dynamic weights");

            Direction direction = Direction.Up;

            if (freeDirections.Count > 0)
            {
                direction = freeDirections[_random.Next(freeDirections.Count)];
            }
            if (nonCollisionDirections.Count > 0)
            {
                direction = nonCollisionDirections[_random.Next(nonCollisionDirections.Count)];
            }

            long w = 0;

            foreach (var kvp in dynamicWeights)
            {
                if (kvp.Value > w)
                {
                    w         = kvp.Value;
                    direction = kvp.Key;
                }
            }

            Console.WriteLine("Tick number: " + MySnakeParameters.TickNumber);
            Console.WriteLine("Lingth before: " + MySnakeParameters.Length);
            Console.WriteLine("Evil time before: " + MySnakeParameters.EvilsDuration);
            MySnakeParameters.UpdateAfterMove(gameBoard, direction);
            Console.WriteLine("Lingth after: " + MySnakeParameters.Length);
            Console.WriteLine("Evil time after: " + MySnakeParameters.EvilsDuration);

            Console.WriteLine((DateTime.Now - start).Milliseconds);
            return(new SnakeAction(false, false, direction));
        }