示例#1
0
        private void SetBot(ControlledThrustBot bot)
        {
            // Remove
            RemoveBot();

            RefillContainers(bot);

            // Set bot
            _map.AddItem(bot);
            _bot = bot;

            bot.PhysicsBody.BodyMoved += PhysicsBody_BodyMoved;
            PhysicsBody_BodyMoved(this, new EventArgs());

            // Timer
            _graphTimer.Start();
        }
示例#2
0
        private void RemoveBot()
        {
            // Timer
            _graphTimer.Stop();

            // Thrust balancer
            if (_cancelCurrentBalancer != null)
            {
                _cancelCurrentBalancer.Cancel();
                _cancelCurrentBalancer = null;
            }

            // Bot
            if (_bot != null)
            {
                _bot.PhysicsBody.BodyMoved -= PhysicsBody_BodyMoved;
                _map.RemoveItem(_bot);
                _bot = null;
            }
        }
示例#3
0
        private void BalanceBot_Spin(ControlledThrustBot bot)
        {
            if (_cancelCurrentBalancer != null)
            {
                _cancelCurrentBalancer.Cancel();
                _cancelCurrentBalancer = null;
            }

            if (bot.Thrusters == null || bot.Thrusters.Length == 0)
            {
                MessageBox.Show("This bot has no thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            Vector3D ideal = new Vector3D(1, 0, 0);

            _cancelCurrentBalancer = new CancellationTokenSource();

            var newBestFound = new Action <ThrusterMap>(o => bot.ForwardMap = o);        // using forward map, even though this is spin

            ThrustControlUtil.DiscoverSolutionAsync2(bot, null, ideal, _cancelCurrentBalancer.Token, null, newBestFound);
        }
示例#4
0
        private static void RefillContainers(ControlledThrustBot bot)
        {
            bot.ShouldLearnFromLifeEvents = false;

            if (bot.Energy != null)
            {
                bot.Energy.QuantityCurrent = bot.Energy.QuantityMax;
            }
            if (bot.Fuel != null)
            {
                bot.Fuel.QuantityCurrent = bot.Fuel.QuantityMax;
            }
            if (bot.Ammo != null)
            {
                bot.Ammo.QuantityCurrent = bot.Ammo.QuantityMax;
            }
            if (bot.Plasma != null)
            {
                bot.Plasma.QuantityCurrent = bot.Plasma.QuantityMax;
            }

            bot.ShouldLearnFromLifeEvents = true;
        }
示例#5
0
        private void BalanceBot_Forward(ControlledThrustBot bot)
        {
            if (_cancelCurrentBalancer != null)
            {
                _cancelCurrentBalancer.Cancel();
                _cancelCurrentBalancer = null;
            }

            if (bot.Thrusters == null || bot.Thrusters.Length == 0)
            {
                MessageBox.Show("This bot has no thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            Vector3D ideal = new Vector3D(0, 0, 1);

            _cancelCurrentBalancer = new CancellationTokenSource();

            var newBestFound  = new Action <ThrusterMap>(o => bot.ForwardMap = o);
            var logGeneration = new Action <Tuple <ThrusterMap, double[]>[]>(o => _generation = o);

            ThrustControlUtil.DiscoverSolutionAsync2(bot, ideal, null, _cancelCurrentBalancer.Token, newBestFound: newBestFound, logGeneration: logGeneration);
        }
示例#6
0
        private void SetBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int numThrusters;
                if (!int.TryParse(txtNumThrusters.Text, out numThrusters))
                {
                    MessageBox.Show("Couldn't parse the number of thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                else if (numThrusters < 2)
                {
                    MessageBox.Show("Must have at least two thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                #region DNA

                List <ShipPartDNA> parts = new List <ShipPartDNA>();

                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0.283735185991315), Scale = new Vector3D(2.05963659008885, 2.05963659008885, 0.301082085094996)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, -0.490401090473184), Scale = new Vector3D(1.92697281805995, 1.92697281805995, 1.1591130722673)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = SensorSpin.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0.57985483357727), Scale = new Vector3D(1, 1, 1)
                });

                parts.AddRange(GetRandomThrusters(numThrusters, chkRandRotateThrusters.IsChecked.Value, (ThrusterTypeValues)cboThrusterTypes.SelectedItem, chkSomeDestroyed.IsChecked.Value));

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map           = _map,
                    Material_Ship = _material_Bot,
                    World         = _world,
                };

                BotConstruction_Result seed = BotConstructor.ConstructBot(dna, core);
                ControlledThrustBot    bot  = new ControlledThrustBot(seed);

                SetBot(bot);

                // Start looking for a solution immediately
                if (chkBalanceThrusters.IsChecked.Value)
                {
                    BalanceBot_Forward(_bot);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private static void RefillContainers(ControlledThrustBot bot)
        {
            bot.ShouldLearnFromLifeEvents = false;

            if (bot.Energy != null)
            {
                bot.Energy.QuantityCurrent = bot.Energy.QuantityMax;
            }
            if (bot.Fuel != null)
            {
                bot.Fuel.QuantityCurrent = bot.Fuel.QuantityMax;
            }
            if (bot.Ammo != null)
            {
                bot.Ammo.QuantityCurrent = bot.Ammo.QuantityMax;
            }
            if (bot.Plasma != null)
            {
                bot.Plasma.QuantityCurrent = bot.Plasma.QuantityMax;
            }

            bot.ShouldLearnFromLifeEvents = true;
        }
        private void BalanceBot_Spin(ControlledThrustBot bot)
        {
            if (_cancelCurrentBalancer != null)
            {
                _cancelCurrentBalancer.Cancel();
                _cancelCurrentBalancer = null;
            }

            if (bot.Thrusters == null || bot.Thrusters.Length == 0)
            {
                MessageBox.Show("This bot has no thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            Vector3D ideal = new Vector3D(1, 0, 0);

            _cancelCurrentBalancer = new CancellationTokenSource();

            var newBestFound = new Action<ThrusterMap>(o => bot.ForwardMap = o);        // using forward map, even though this is spin

            ThrustControlUtil.DiscoverSolutionAsync2(bot, null, ideal, _cancelCurrentBalancer.Token, null, newBestFound);
        }
        private void SetBot(ControlledThrustBot bot)
        {
            // Remove
            RemoveBot();

            RefillContainers(bot);

            // Set bot
            _map.AddItem(bot);
            _bot = bot;

            bot.PhysicsBody.BodyMoved += PhysicsBody_BodyMoved;
            PhysicsBody_BodyMoved(this, new EventArgs());
        }
        private void RemoveBot()
        {
            // Thrust balancer
            if (_cancelCurrentBalancer != null)
            {
                _cancelCurrentBalancer.Cancel();
                _cancelCurrentBalancer = null;
            }

            // Bot
            if (_bot != null)
            {
                _bot.PhysicsBody.BodyMoved -= PhysicsBody_BodyMoved;

                _map.RemoveItem(_bot);

                //_bot.Dispose();       // Map_ItemRemoved event listener already disposed it
                _bot = null;
            }
        }
        private void SetBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int numThrusters;
                if (!int.TryParse(txtNumThrusters.Text, out numThrusters))
                {
                    MessageBox.Show("Couldn't parse the number of thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                else if (numThrusters < 2)
                {
                    MessageBox.Show("Must have at least two thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                #region DNA

                List<ShipPartDNA> parts = new List<ShipPartDNA>();

                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0.283735185991315), Scale = new Vector3D(2.05963659008885, 2.05963659008885, 0.301082085094996) });

                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, -0.490401090473184), Scale = new Vector3D(1.92697281805995, 1.92697281805995, 1.1591130722673) });

                parts.Add(new ShipPartDNA() { PartType = SensorSpin.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0.57985483357727), Scale = new Vector3D(1, 1, 1) });

                parts.AddRange(GetRandomThrusters(numThrusters, chkRandRotateThrusters.IsChecked.Value, (ThrusterTypeValues)cboThrusterTypes.SelectedItem));

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                BotConstruction_Result seed = BotConstructor.ConstructBot(dna, core);
                ControlledThrustBot bot = new ControlledThrustBot(seed);

                SetBot(bot);

                // Start looking for a solution immediately
                if (chkBalanceThrusters.IsChecked.Value)
                {
                    BalanceBot_Forward(_bot);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }