// Start is called before the first frame update
    public void StartSimulation()
    {
        board   = new int[simulationDimensions.x][][];
        boardGo = new GameObject[simulationDimensions.x][][];
        for (int i = 0; i < simulationDimensions.x; i++)
        {
            board[i]   = new int[simulationDimensions.y][];
            boardGo[i] = new GameObject[simulationDimensions.y][];
            for (int j = 0; j < simulationDimensions.y; j++)
            {
                board[i][j]   = new int[simulationDimensions.z];
                boardGo[i][j] = new GameObject[simulationDimensions.z];
                for (int k = 0; k < simulationDimensions.z; k++)
                {
                    boardGo[i][j][k] = Instantiate(brickPrefab, new Vector3Int(i, j, k), Quaternion.identity);
                    boardGo[i][j][k].SetActive(false);
                }
            }
        }
        board[simulationDimensions.x / 2][simulationDimensions.y / 2][simulationDimensions.z / 2] = 1;

        waspsGo = new GameObject[numberOfWasp];
        wasps   = new Wasp[numberOfWasp];
        for (int i = 0; i < numberOfWasp; i++)
        {
            wasps[i]   = new Wasp(RandomVector3Int(Vector3Int.zero, simulationDimensions));
            waspsGo[i] = Instantiate(waspPrefab, wasps[i].position, Quaternion.identity);
        }

        simulationRunning = true;
        updateBricksUI    = true;
    }
示例#2
0
 /// <summary>
 /// Display WASP information
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void wasps_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         Wasp w = e.NewItems[0] as Wasp;
         try
         {
             WaspData wd = new WaspData
             {
                 ChargingState = w.IsCharging.ToString(),
                 FW            = string.Format("{0}", w.FirmwareVersion),
                 MAC           = BitConverter.ToString(w.MAC),
                 Name          = w.Name,
                 Type          = TypeDescriptor.GetConverter(w.ProductType).ConvertToString(w.ProductType),
                 Voltage       = string.Format("{0:0.00}", w.BatteryLevel),
                 FuelGauge     = string.Format("{0:0.0}%", w.FuelGauge * 100)
             };
             _waspData.Add(wd);
         }
         catch (ArgumentNullException)
         {
             // USB mode does not have MAC address at this time
         }
     }
 }
示例#3
0
        private static void CreateMonsters()   // Just because i want random kind of monsters, in different lvls i go through this loop. And the settings gives them random lvls and names.
        {
            for (int i = 0; i < 15; i++)
            {
                Dragon dragon = new Dragon();
                fireMonsters.Add(dragon);

                Demon demon = new Demon();
                fireMonsters.Add(demon);

                Tortoise tortoise = new Tortoise();
                waterMonsters.Add(tortoise);

                SwampTroll troll = new SwampTroll();
                waterMonsters.Add(troll);

                Crocodile croc = new Crocodile();
                waterMonsters.Add(croc);

                RabiesBear bear = new RabiesBear();
                grassMonsters.Add(bear);

                Wasp wasp = new Wasp();
                grassMonsters.Add(wasp);

                Scarab scarab = new Scarab();
                grassMonsters.Add(scarab);
            }

            DragonLord dL = new DragonLord();  // but only one dragon lord.

            fireMonsters.Add(dL);
        }
示例#4
0
 /// <summary>
 /// Called when a WASP is added or removed
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Wasps_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         int count = e.NewItems.Count;
         for (int i = 0; i < e.NewItems.Count; i++)
         {
             if (((Wasp)e.NewItems[i]).Name == _deviceNames[0])
             {
                 _waspUT = (Wasp)e.NewItems[i];
                 _waspUT.PropertyChanged += Wasp_PropertyChanged;
                 WaspCollection.SendExtendedWaspQuery(_waspUT.WaspIPAddress);
                 _waspReady.Set();
                 buttonPoE.IsEnabled   = true;
                 buttonRadio.IsEnabled = true;
                 break;
             }
             else if (((Wasp)e.NewItems[i]).Name == _deviceNames[1])
             {
                 _waspUT = (Wasp)e.NewItems[i];
                 _waspReady.Set();
                 buttonOta.IsEnabled = true;
                 break;
             }
         }
     }
 }
示例#5
0
 public WaspAI(Enemy wasp)
     : base(wasp)
 {
     currentStatus = "high";
     person = (Wasp)_person;
     timeLimit = person.setting.highFartingTime.random();
 }
示例#6
0
        /// <summary>
        /// Called when the connection completes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Wasp_ConnectionEvent(object sender, ConnectionEventArgs e)
        {
            if (e.Connection == NorthPoleEngineering.WaspClassLibrary.ConnectionState.Connected)
            {
                Wasp wasp = sender as Wasp;

                // check if not WASP-B
                if (wasp.ProductType != ProductTypes.WASP_B)
                {
                    // create a list of ANT radios we want to control
                    List <object> radios     = new List <object>();
                    RadioTypes[]  radioTypes = { wasp.Radio1Type, wasp.Radio2Type, wasp.Radio3Type, wasp.Radio4Type };

                    for (int i = 0; i < radioTypes.Length; i++)
                    {
                        if (radioTypes[i] == RadioTypes.ANT)
                        {
                            // order is radio index, radio mode
                            radios.AddRange(new object[] { i, Wasp.AntRadioModes.Controlled });

                            // connect to the radio reset event
                            AntRadio antRadio = wasp.GetAntRadio(i);
                            antRadio.ResetEvent += Radio_ResetEvent;;
                            antRadio.Retries     = 0;
                        }
                    }

                    if (radios.Count > 0)
                    {
                        // this will reset the radios
                        wasp.SetAntRadioMode(radios.ToArray());
                    }
                }
            }
        }
示例#7
0
    /// <summary>
    /// Spawns a wasp randomly
    /// </summary>
    private void SpawnRandomWaspAnim()
    {
        Wasp newWasp = Instantiate(m_wasp);

        newWasp.transform.parent = m_wasp.transform.parent;
        newWasp.Initialize(null);
        newWasp.gameObject.SetActive(true);
        AddToInteractiveObjectList(newWasp);
    }
        private void Step()
        {
            Vector2Int hollow = structure.PopFirstHollow();

            List <Wasp> waspWhichCanPutTemplate = new List <Wasp>();

            foreach (var wasp in trainer.wasps)
            {
                bool dontFitShape = false;
                if (structure.TemplateFitIn(hollow, wasp, shape, out dontFitShape))
                {
                    if (dontFitShape)
                    {
                        wasp.ModifyHealth(trainer.waspPunishment);
                    }
                    else
                    {
                        waspWhichCanPutTemplate.Add(wasp);
                        wasp.ModifyHealth(trainer.waspReward);
                    }
                }
            }

            if (waspWhichCanPutTemplate.Count == 0)
            {
                if (trainer.probOfUseSameBrickNumber != 0)
                {
                    waspWhichCanPutTemplate.Add(CreateWaspFor(hollow, lastBrickNumber));
                    waspWhichCanPutTemplate.Last().health *= trainer.probOfUseSameBrickNumber;
                }
                if (trainer.probOfCreateNewBrickNumber != 0)
                {
                    lastBrickNumber++;
                    waspWhichCanPutTemplate.Add(CreateWaspFor(hollow, lastBrickNumber));
                    waspWhichCanPutTemplate.Last().health *= trainer.probOfCreateNewBrickNumber;
                }

                foreach (var w in waspWhichCanPutTemplate)
                {
                    trainer.AddWasp(w);
                }
            }

            Wasp selectedTemplate = Wasp.Select(waspWhichCanPutTemplate);

            var newBricks = structure.AddBricks(hollow, selectedTemplate);

            if (newBricks.Count > 0)
            {
                structure.RecalculateHollows(newBricks);
            }

            foreach (var wasp in trainer.wasps)
            {
                wasp.health += trainer.healthStepDecay;
            }
        }
示例#9
0
        /// <summary>
        /// Called when a sensor is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listViewSensors_DoubleClick(object sender, EventArgs e)
        {
            AntDevice antDevice = (AntDevice)listViewSensors.SelectedItems[0].Tag;

            _fitnessEquipment = antDevice as FitnessEquipment;

            Wasp wasp = antDevice.GetStrongestWasp();

            wasp.ConnectionEvent += Wasp_ConnectionEvent;;
            wasp.RequestConnection();
        }
 /// <summary>
 /// WASP Collection Changed event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <remarks>WASP comes up, get a connection to it</remarks>
 private void WASP_CollectionChangedEvent(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         _thisWasp = e.NewItems[0] as Wasp;
         Title    += " connected to " + _thisWasp.Name;
         _thisWasp.ConnectionEvent += WaspConnected;
         _thisWasp.RequestConnection();
     }
     else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
     {
         Title = "Configure WASP-N";
         Dispatcher.Invoke(new Action(() => { buttonConf.IsEnabled = false; }));
     }
 }
    private bool PutBricks(Wasp w)
    {
        List <int> bricks = rules[0].bricks;

        Vector3Int w_pos = w.position;

        int[,] around = SenseAround(w_pos);

        for (int offset = 0; offset < bricks.Count; offset += 9 * 3)
        {
            for (int rot = 0; rot < 4; rot++)
            {
                bool canPutBrick = true;

                for (int brickIndex = 0; brickIndex < 27; brickIndex++)
                {
                    int y = brickIndex / 9;
                    int p = brickIndex % 9;

                    if (y == 1 && p == 4)
                    {
                        continue;
                    }

                    if (bricks[offset + brickIndex] != around[rot, brickIndex])
                    {
                        canPutBrick = false;
                        break;
                    }
                }

                if (canPutBrick)
                {
                    int brickToPut = bricks[offset + 9 + 4];
                    Debug.Log("Putting " + brickToPut);
                    board[w.position.x][w.position.y][w.position.z] = brickToPut;
                    return(true);
                }
            }
        }

        return(false);
    }
        private Wasp CreateWaspFor(Vector2Int center, int newBrickNumber)
        {
            Wasp wasp = new Wasp();

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    Vector2Int pos   = new Vector2Int(i, j) + center;
                    int        brick = shape.Contains(pos)? newBrickNumber : 0;
                    brick = structure.HaveBrickIn(pos)? structure.GetBrick(pos) : brick;
                    wasp.template[i + 1, j + 1] = brick;
                }
            }

            wasp.health = trainer.initialWaspsPoints;

            return(wasp);
        }
示例#13
0
    public List <Vector2Int> AddBricks(Vector2Int center, Wasp wasps)
    {
        List <Vector2Int> newBricks = new List <Vector2Int>();

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                Vector2Int pos = new Vector2Int(i, j) + center;
                if (!bricks.ContainsKey(pos))
                {
                    if (wasps.template[i + 1, j + 1] != 0)
                    {
                        newBricks.Add(pos);
                        bricks.Add(pos, wasps.template[i + 1, j + 1]);
                    }
                }
            }
        }

        return(newBricks);
    }
示例#14
0
        /// <summary>
        /// Called when a WASP is added or removed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Wasps_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                int count = e.NewItems.Count;
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    if (((Wasp)e.NewItems[i]).Name == _deviceNames[0])
                    {
                        _waspUT = (Wasp)e.NewItems[i];
                        _waspReady.Set();
                        buttonPoE.IsEnabled   = true;
                        buttonRadio.IsEnabled = true;
                        Progress.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { label1.Content = string.Format("{0} F/W version {1}.{2}.{3}",
                                                                                                                                                         _waspUT.Name, _waspUT.VersionMajor, _waspUT.VersionMinor, _waspUT.ProductVersion); }));
                        break;
                    }
                    else if (((Wasp)e.NewItems[i]).Name == _deviceNames[1])
                    {
                        _waspUT = (Wasp)e.NewItems[i];
                        _waspUT.PropertyChanged += Wasp_PropertyChanged;
                        WaspCollection.SendExtendedWaspQuery(_waspUT.WaspIPAddress);
                        Progress.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => {
                            label1.Content = string.Format("{0} F/W version {1}.{2}.{3}", _waspUT.Name, _waspUT.VersionMajor, _waspUT.VersionMinor, _waspUT.ProductVersion);
                        }));

                        _waspReady.Set();
                        buttonOta.IsEnabled = true;
                        break;
                    }
                    else if (((Wasp)e.NewItems[i]).BasestationMode)
                    {
                        _waspUsb            = (Wasp)e.NewItems[i];
                        buttonUsb.IsEnabled = true;
                    }
                }
            }
        }
示例#15
0
    public bool TemplateFitIn(Vector2Int center, Wasp wasp, HashSet <Vector2Int> shape, out bool dontFitShape)
    {
        bool mismatch = false;

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                Vector2Int pos = new Vector2Int(i, j) + center;
                if (shape != null && !shape.Contains(pos)) // && template.template[i + 1, j + 1] != 0) {
                {
                    dontFitShape = true;
                    return(false);
                }
                if (bricks.ContainsKey(pos) && bricks[pos] != wasp.template[i + 1, j + 1])
                {
                    mismatch = true;
                }
            }
        }
        dontFitShape = false;
        return(!mismatch);
    }
    // Start is called before the first frame update
    public void Generate(List <Wasp> wasps)
    {
        BrickStructure structure = new BrickStructure();

        var bricks = InitStructure(structure);

        structure.RecalculateHollows(bricks);

        int iter = 0;

        while (structure.HaveHollows() && iter < maxIter)
        {
            List <Wasp> posibleTemplates = new List <Wasp>();
            Vector2Int  hollow           = structure.PopFirstHollow();

            foreach (var wasp in wasps)
            {
                if (structure.TemplateFitIn(hollow, wasp))
                {
                    posibleTemplates.Add(wasp);
                }
            }

            if (posibleTemplates.Count > 0)
            {
                var newBricks = structure.AddBricks(hollow, Wasp.Select(posibleTemplates));
                if (newBricks.Count > 0)
                {
                    structure.RecalculateHollows(newBricks);
                }
            }
            iter++;
        }

        GetComponent <StructureRenderer>().Render(structure);
    }
示例#17
0
    public bool TemplateFitIn(Vector2Int center, Wasp wasp)
    {
        bool b;

        return(TemplateFitIn(center, wasp, null, out b));
    }
 private void AddWasp(Wasp wasp)
 {
     wasps.Add(wasp);
 }