Exemplo n.º 1
0
        private void Collection_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormCollection form = (FormCollection)sender;

            if (form.DialogResult == DialogResult.OK && form.features != null)
            {
                features = form.features;

                if (form.features.Count != features.Count)
                {
                    MessageBox.Show("Feature collection has been heavily modified, network will be deleted!", "Attention",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                    nn = null;
                    toolStripStatusLabel2.Text = "---";
                    toolStripStatusLabel4.Text = "0";
                    toolStripStatusLabel6.Text = "0";
                }
                else
                {
                    if (nn != null)
                    {
                        nn._state.features = features;
                    }
                }

                PopulateListView();
            }
        }
Exemplo n.º 2
0
 public virtual void Initialise()
 {
     coords = new ChunkCoords(transform.position, EntityNetwork.CHUNK_SIZE);
     EntityNetwork.AddEntity(this, coords);
     RepositionInNetwork(true);
     healthComponent?.SetToUpperLimit();
     enabled = true;
 }
 private void OnDestroy()
 {
     if (Singleton == this)
     {
         CustomMessagingManager.UnregisterNamedMessageHandler("NetworkInput");
         CustomMessagingManager.UnregisterNamedMessageHandler("NetworkState");
         Singleton = null;
     }
 }
Exemplo n.º 4
0
        public void SelectNetwork(EntityNetwork nn)
        {
            this.nn = nn;

            if (nn != null)
            {
                inputHidden  = BuildEntityMatrix(nn._state._weightInputHidden, new Point(0, 0), 16, 16 * 3, 16);
                hiddenOutput = BuildEntityMatrix(nn._state._weightHiddenOutput, new Point(16, 0), 16, 16 * 3, 16);
            }
        }
    private void Awake()
    {
        if (Singleton != null)
        {
            Destroy(gameObject);
            return;
        }

        Singleton = this;
        // TODO: DontDestroyOnLoad(gameObject);
    }
Exemplo n.º 6
0
    public void AssignUnoccupiedCoords(GatherBot b)
    {
        if (b == null)
        {
            return;
        }
        CheckEmptyMarkedCoords();
        botOccupiedCoords.Clear();
        botOccupiedCoords.AddRange(emptyCoords);

        for (int i = 0; i < childBots.Count; i++)
        {
            EntityNetwork.IterateCoordsInRange(
                childBots[i].GetIntendedCoords(),
                1,
                cc =>
            {
                botOccupiedCoords.Add(cc);
                return(false);
            },
                false);
        }

        //find a random nearby coordinate that is not already occupied
        int         searchRange = 1;
        ChunkCoords location    = ChunkCoords.Invalid;

        while (location == ChunkCoords.Invalid)
        {
            EntityNetwork.IterateCoordsOnRangeBorder(
                coords,
                searchRange,
                cc =>
            {
                if (botOccupiedCoords.Contains(cc))
                {
                    return(false);
                }
                if (Random.value < 0.1f)
                {
                    location = cc;
                    return(true);
                }

                return(false);
            },
                false);
            searchRange++;
        }

        Vector2 pos = ChunkCoords.GetCenterCell(location, EntityNetwork.CHUNK_SIZE);

        b.HiveOrders(pos);
    }
Exemplo n.º 7
0
        private void Form_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormCreateNetwork form = (FormCreateNetwork)sender;

            if (form.DialogResult == DialogResult.OK)
            {
                nn = new EntityNetwork(features, form.hiddenLayer, form.learningRate);
                toolStripStatusLabel2.Text = nn._state.name;
                toolStripStatusLabel4.Text = nn._state._weightInputHidden.GetLength(0).ToString();
                toolStripStatusLabel6.Text = nn._state._learningRate.ToString("0.00");
            }
        }
Exemplo n.º 8
0
    public virtual void DestroySelf(Entity destroyer, float dropModifier)
    {
        if (destroyer)
        {
            destroyer.DestroyedAnEntity(this);
        }
        if (EntityNetwork.ConfirmLocation(this, coords))
        {
            EntityNetwork.RemoveEntity(this);
        }
        IInventoryHolder target = destroyer as IInventoryHolder;

        DropLoot(target, dropModifier);
        Destroy(gameObject);
    }
Exemplo n.º 9
0
    private void Awake()
    {
        if (instance != this && instance != null)
        {
            Destroy(gameObject);
            return;
        }
        instance = this;

        Debug.Log("Loading Entity Network");
        gridIsSetUp = true;
        Debug.Log("Entity Network Loaded");
        OnLoaded?.Invoke();
        OnLoaded = null;
    }
Exemplo n.º 10
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
            return;
        }

        holder.SetActive(true);
        AddListener(() =>
        {
            holder.SetActive(false);
        });

        if (FindObjectOfType <SceneryController>())
        {
            int ID = loadingReady.Count;
            loadingReady.Add(false);
            SceneryController.AddListener(() =>
            {
                Ready(ID);
            });
        }

        if (FindObjectOfType <EntityGenerator>())
        {
            int ID = loadingReady.Count;
            loadingReady.Add(false);
            EntityGenerator.AddListener(() =>
            {
                Ready(ID);
            });
        }

        if (FindObjectOfType <EntityNetwork>())
        {
            int ID = loadingReady.Count;
            loadingReady.Add(false);
            EntityNetwork.AddListener(() =>
            {
                Ready(ID);
            });
        }
    }
Exemplo n.º 11
0
    private void CoordsChanged(ChunkCoords newCoords, ChunkCoords oldCoords)
    {
        HashSet <ChunkCoords> activeCoords  = new HashSet <ChunkCoords>();
        HashSet <ChunkCoords> removedCoords = new HashSet <ChunkCoords>();

        //send some active objects to the transition pool
        for (int i = active.Count - 1; i >= 0; i--)
        {
            StarFieldMaterialPropertyManager sfmpm = active[i];
            activeCoords.Add(sfmpm.coord);
            if (ChunkCoords.SquareDistance(sfmpm.coord, newCoords) > ViewDistance)
            {
                removedCoords.Add(sfmpm.coord);
                active.RemoveAt(i);
                transitionActive.Add(sfmpm);
            }
        }

        //activate or create new items to fill in the scenery
        EntityNetwork.IterateCoordsInRange(newCoords,
                                           ViewDistance,
                                           cc =>
        {
            int dist = ChunkCoords.SquareDistance(cc, oldCoords);
            if (dist <= ViewDistance && dist != -1)
            {
                return(false);
            }
            ChunkCoords loopedCoords = cc;
            if (hasLoopPoint)
            {
                loopedCoords.x = Mathf.Abs(cc.x) % loopSize;
                loopedCoords.y = Mathf.Abs(cc.y) % loopSize;
            }
            FillSpace(loopedCoords);
            //create new cosmic items
            if (Chunk(loopedCoords).Count == 0)
            {
                FillChunk(loopedCoords);
            }

            SetUpScenery(cc, loopedCoords);
            return(false);
        },
                                           true);
    }
Exemplo n.º 12
0
        public FormCoverage(Image image, EntityNetwork nn)
        {
            InitializeComponent();

            /// Load source image

            sourceBitmap = new Bitmap(image);
            this.nn      = nn;

            entityBox1.Mode = EntityMode.ImageLayer0;
            entityBox1.LoadImage(image);
            entityBox1.Mode = EntityMode.Selection;

            /// Fill combobox by Features

            for (int i = 0; i < nn._state.features.Count; i++)
            {
                comboBox1.Items.Add(nn.GetFeatureName(i));
            }
        }
Exemplo n.º 13
0
    /// Disables all entities previously in view, gets a new list of entities and enables them.
    private void UpdateEntitiesInView(ChunkCoords newCoords, ChunkCoords oldCoords)
    {
        //keep track of coords previous in view
        //query the EntityNetwork for a list of coordinates in view based on camera's size
        int range = ENTITY_VIEW_RANGE + RangeModifier;

        EntityNetwork.IterateEntitiesInRange(
            oldCoords,
            range,
            e =>
        {
            ChunkCoords eCC = e.GetCoords();
            if (!IsInRange(newCoords, eCC, range) ||
                !newCoords.IsValid() ||
                !eCC.IsValid())
            {
                e.RepositionInNetwork(true);
            }

            return(false);
        });

        EntityNetwork.IterateEntitiesInRange(
            newCoords,
            range,
            e =>
        {
            ChunkCoords eCC = e.GetCoords();
            if (IsInRange(oldCoords, eCC, range) ||
                !oldCoords.IsValid() ||
                !eCC.IsValid())
            {
                e.RepositionInNetwork(true);
            }

            return(false);
        });

        CheckPhysicsRange(newCoords, oldCoords);
    }
Exemplo n.º 14
0
    public void RepositionInNetwork(bool forceUpdate)
    {
        ChunkCoords newCc = new ChunkCoords(transform.position, EntityNetwork.CHUNK_SIZE);

        if (newCc == coords && !forceUpdate)
        {
            return;
        }

        EntityNetwork.Reposition(this, newCc);

        bool foundInPhysicsRange     = CheckIfInPhysicsRange();
        bool foundInViewRange        = CheckInCameraViewRange();
        bool justEnteredPhysicsRange = !IsInPhysicsRange && foundInPhysicsRange;
        bool justExitedPhysicsRange  = IsInPhysicsRange && !foundInPhysicsRange;
        bool justEnteredViewRange    = !IsInViewRange && foundInViewRange;
        bool justExitedViewRange     = IsInViewRange && !foundInViewRange;

        if (justEnteredPhysicsRange)
        {
            IsInPhysicsRange = true;
            OnEnterPhysicsRange();
        }
        if (justExitedPhysicsRange)
        {
            IsInPhysicsRange = false;
            OnExitPhysicsRange();
        }
        if (justEnteredViewRange)
        {
            IsInViewRange = true;
            OnEnterViewRange();
        }
        if (justExitedViewRange)
        {
            IsInViewRange = false;
            OnExitViewRange();
        }
    }
Exemplo n.º 15
0
    private ChunkCoords ClosestValidNonFilledChunk(SpawnableEntity se)
    {
        int         minRange = Mathf.Max(0, se.rarityZoneOffset);
        ChunkCoords coords   = ChunkCoords.Invalid;

        while (coords == ChunkCoords.Invalid)
        {
            EntityNetwork.IterateCoordsOnRangeBorder(ChunkCoords.Zero, minRange,
                                                     cc =>
            {
                if (!Chunk(cc))
                {
                    coords = cc;
                    return(true);
                }

                return(false);
            },
                                                     true);
            minRange++;
        }
        return(ChunkCoords.Invalid);
    }
Exemplo n.º 16
0
        private void loadNetworkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult res = openFileDialog2.ShowDialog();

            if (res == DialogResult.OK)
            {
                string filename = openFileDialog2.FileName;

                XmlSerializer ser = new XmlSerializer(typeof(EntityNetwork.State));

                using (FileStream fs = new FileStream(filename, FileMode.Open))
                {
                    EntityNetwork.State state = (EntityNetwork.State)ser.Deserialize(fs);

                    nn = new EntityNetwork(state);

                    features = nn._state.features;

                    toolStripStatusLabel2.Text = state.name;
                    toolStripStatusLabel4.Text = state._weightInputHidden.GetLength(0).ToString();
                    toolStripStatusLabel6.Text = state._learningRate.ToString("0.00");
                }
            }
        }
Exemplo n.º 17
0
    private void SearchForNearestAsteroid()
    {
        int searchRange = 1;

        Asteroid closestAsteroid = null;
        float    closestDistance = float.PositiveInfinity;

        while (closestAsteroid == null)
        {
            EntityNetwork.IterateEntitiesInRange(
                coords,
                searchRange,
                e =>
            {
                if (e is Asteroid asteroid)
                {
                    if ((hive != null && hive.VerifyGatheringTarget(this, e)) ||
                        hive == null)
                    {
                        float dist = Vector2.Distance(transform.position, e.transform.position);
                        if (dist < closestDistance)
                        {
                            closestDistance = dist;
                            closestAsteroid = asteroid;
                        }
                    }
                }

                return(false);
            });
            searchRange++;
        }

        targetEntity = closestAsteroid;
        searchTimer  = Pause.timeSinceOpen;
    }
Exemplo n.º 18
0
    private void CheckPhysicsRange(ChunkCoords newCoords, ChunkCoords oldCoords)
    {
        int range = Constants.MAX_PHYSICS_RANGE;

        EntityNetwork.IterateEntitiesInRange(
            oldCoords,
            range,
            e =>
        {
            ChunkCoords eCC = e.GetCoords();
            if (!IsInRange(newCoords, eCC, range) ||
                !newCoords.IsValid() ||
                !eCC.IsValid())
            {
                e.RepositionInNetwork(true);
            }

            return(false);
        });

        EntityNetwork.IterateEntitiesInRange(
            newCoords,
            range,
            e =>
        {
            ChunkCoords eCC = e.GetCoords();
            if (IsInRange(oldCoords, eCC, range) ||
                !oldCoords.IsValid() ||
                !eCC.IsValid())
            {
                e.RepositionInNetwork(true);
            }

            return(false);
        });
    }
Exemplo n.º 19
0
    protected virtual void Scanning()
    {
        if (rb.velocity.sqrMagnitude < 0.01f)
        {
            if (!scanStarted)
            {
                if (IsInViewRange)
                {
                    StartCoroutine(ScanRings());
                }
                scanStarted = true;
                entitiesScanned.Clear();
                new Thread(() =>
                {
                    EntityNetwork.IterateEntitiesInRange(
                        coords,
                        1,
                        e =>
                    {
                        if (e != this)
                        {
                            entitiesScanned.Add(e);
                        }

                        return(false);
                    });
                }).Start();
            }
            else
            {
                scanTimer += Time.deltaTime;
            }

            if (scanTimer >= scanDuration)
            {
                scanTimer   = 0f;
                scanStarted = false;
                //look for the first unusual entity in the scan
                for (int i = 0; i < entitiesScanned.Count; i++)
                {
                    Entity e = entitiesScanned[i];
                    if (IsScary(e))
                    {
                        hive?.MarkCoordAsEmpty(coords);
                        SetState(AIState.Exploring);
                        return;
                    }
                    ICombat threat = e.GetICombat();
                    if (threat != null && IsSuspicious(threat))
                    {
                        nearbySuspects.Add(threat);
                    }
                }

                if (nearbySuspects.Count > 0)
                {
                    SetState(AIState.Suspicious);
                    return;
                }

                //choose state
                if (entitiesScanned.Count >= 10)
                {
                    SetState(AIState.Gathering);
                }
                else
                {
                    hive?.MarkCoordAsEmpty(coords);
                    SetState(AIState.Exploring);
                }
            }
        }
    }
Exemplo n.º 20
0
 private void OnDestroy()
 {
     EntityNetwork.RemoveEntity(this);
     mainCam     = null;
     mainCamCtrl = null;
 }
Exemplo n.º 21
0
        public FormDebugger(EntityNetwork nn)
        {
            InitializeComponent();

            SelectNetwork(nn);
        }