// public override ApiShipMatter ChooseShip()
        // {
        //     var ship = new ApiShipMatter{Engines = 1, Radiators = 30};
        //     ship.Fuel = maxMatter - ship.TotalWeight();
        //     return ship;
        // }

        public Command[] GetNextCommands(Universe state, int playerId)
        {
            var commands = new List <Command>();

            var ship = state.AliveShips.First(x => x.OwnerPlayerId == playerId);

            // выбираем маневр чтобы не врезаться в планету
            var      bestBurnScore = long.MinValue;
            List <V>?bestBurns     = null;

            foreach (var burns in GetPossibleBurns(ship, state.Tick == 0 ? 3 : 2))
            {
                var stateClone  = state.Clone();
                var turnsToFly  = Simulate(stateClone, burns, maxTicks - state.Tick, playerId);
                var temperature = burns.Sum(BurnTemperature);
                var score       = turnsToFly * 1000 - temperature;
                if (score > bestBurnScore)
                {
                    bestBurnScore = score;
                    bestBurns     = burns.ToList();
                }
            }

            var bestBurn = bestBurns?.FirstOrDefault();

            if (bestBurn != null && bestBurn.CLen != 0)
            {
                commands.Add(new BurnFuel(ship.Uid, bestBurn));
            }

            return(commands.ToArray());
        }
Ejemplo n.º 2
0
 public void BeginEdit()
 {
     if (inEdit)
     {
         return;
     }
     inEdit      = true;
     bakUniverse = universe.Clone() as Universe;
 }
        public AnimationWindow(Universe universe)
        {
            InitializeComponent();
            Title = universe.Name;

            _universe = universe.Clone() as Universe;
            InitializeUniverse();

            _timer.Tick    += Timer_Tick;
            _timer.Interval = new TimeSpan(_fps / 1000);
            _timer.Start();
        }
Ejemplo n.º 4
0
        public Command[] GetNextCommands(Universe universe, int playerId)
        {
            var myShip = universe.AllShips.First(x => x.OwnerPlayerId == playerId);

            if (myShip.IsDead)
            {
                return(new Command[0]);
            }

            GreedyMove?bestMove  = null;
            var        bestScore = double.MinValue;

            foreach (var move in GetAvailableMoves(myShip, maxBurnSpeed: 1))
            {
                var universeClone = universe.Clone();
                var score         = 0.0;
                var count         = 0;
                for (int i = 0; i < depth; i++)
                {
                    if (universeClone.AliveShips.All(s => s.OwnerPlayerId != playerId))
                    {
                        break;
                    }
                    var commands = FixCommand(move.GetCommand(i), universeClone).ToList();
                    if (myShip.OwnerPlayerId == 1)
                    {
                        commands.AddRange(DetonateRivals(universeClone, myShip, commands));
                    }
                    universeClone.NextTick(commands);
                    score += getScore(universeClone, playerId);
                    count++;
                }
                score = count == 0 ? 0 : score / count;
                if (score > bestScore)
                {
                    bestScore = score;
                    bestMove  = move;
                }
            }

            if (bestMove == null)
            {
                return(new Command[0]);
            }

            var bestCommands = FixCommand(bestMove.GetCommand(0), universe).ToArray();

            return(bestCommands);
        }
Ejemplo n.º 5
0
        private IEnumerable <Command> DetonateRivals(Universe universe, Ship me, List <Command> myCommands)
        {
            var detonated = universe.Clone();
            var commands  = detonated.AliveShips.Where(s => s.OwnerPlayerId != me.OwnerPlayerId)
                            .Select(b => (Command) new Detonate(b.Uid))
                            .ToList();

            detonated.NextTick(commands.Concat(myCommands).ToList());
            var meAfterDetonation = detonated.AllShips.First(s => s.Uid == me.Uid);

            if (meAfterDetonation.IsDead || meAfterDetonation.Matter.Total < me.Matter.Total - 4)
            {
                return(commands);
            }
            return(new Command[0]);
        }