public void Generate()
    {
        Rect rect = new Rect(0, 0, transform.localScale.x, transform.localScale.y);

        int length = SpawnZones.Count;

        for (int i = 0; i < length; i++)
        {
            SpawnZones[i].Die();
        }

        spawnZones = new List <ZoneItem>();

        texture = new Texture2D((int)rect.width, (int)rect.height)
        {
            wrapMode   = TextureWrapMode.Clamp,
            filterMode = FilterMode.Point
        };

        rootZone = new SubZone(rect);
        CreateBSP(rootZone);

        TextureApply();

        GetComponent <Renderer>().material.mainTexture = texture;
    }
    public void CreateBSP(SubZone subDungeon)
    {
        if (subDungeon.IAmLeaf())
        {
            //partition if the sub-dungeon is too large
            if (subDungeon.rect.width > maxZoneSize || subDungeon.rect.height > maxZoneSize)
            {
                if (subDungeon.Split(minZoneSize, maxZoneSize))
                {
                    CreateBSP(subDungeon.left);
                    CreateBSP(subDungeon.right);
                }
                else
                {
                    Color color = Random.ColorHSV();

                    SetSubTextureColor(subDungeon.rect, color);

                    ZoneItem zone = Instantiate(zonePrefab, transform);

                    zone.colorPicker = color;
                    zone.Rect        = subDungeon.rect;
                    zone.name        = "Zone " + (SpawnZones.Count + 1) + " - " + zone.transform.position;

                    zone.randomizeSpawnSet = RandomizeSpawnSets;

                    SpawnZones.Add(zone);
                }
            }
        }
    }
Exemple #3
0
 public Column(SubZone zone)
 {
     this.zone        = zone;
     this.neurons     = new ArrayList();
     active           = 0.0f;
     lastActiveNeuron = 0;
     confDeepanalyse  = 1;
 }
Exemple #4
0
 public void setUpSubZone(SubZone zone)
 {
     if (upSubZone != null)
     {
         DebugLog.Log("ERROR setUpSubZone: upSubZone is set already");
     }
     upSubZone = zone;
 }
Exemple #5
0
 public void addInputs(SubZone zone)
 {
     if (zone.getColumns().Length != inputs.Length)
     {
         DebugLog.Log("ERROR: addInputs invalid input");
         return;
     }
     for (int i = 0; i < zone.getColumns().Length; i++)
     {
         inputs[i]        = zone.getColumns()[i];
         inputsActives[i] = 0;
     }
 }
Exemple #6
0
    public InputMatrix(int count)
    {
        inputs          = new NInput[count];
        oldInputsActive = new float[count];
        inputsMotor     = new float[count];
        for (int i = 0; i < count; i++)
        {
            inputs[i]          = new NInput();
            oldInputsActive[i] = 0.0f;
            inputsMotor[i]     = 0.0f;
        }

        upSubZone = null;
    }
Exemple #7
0
    public bool HW1()
    {
        string dbgout = "";

        DebugLog.Log("HW1 - Simple");
        InputMatrix  in1  = new InputMatrix(5);
        SubZone      sz1  = new SubZone(5);
        OutputMatrix out1 = new OutputMatrix(5);

        in1.setUpSubZone(sz1);
        sz1.setDownSubZones(in1);
        sz1.setUpSubZone(out1);
        out1.addInputs(sz1);
        DebugLog.Log("Learn");
        bool[][] in_p1 = new bool[][] {
            new bool[] { true, false, false, false, false },
            new bool[] { false, true, false, false, false },
            new bool[] { false, false, true, false, false },
            new bool[] { false, false, false, true, false },
            new bool[] { false, false, false, false, true },
        };
        for (int i = 0; i < in_p1.Length; i++)
        {
            in1.setBooleans(in_p1[i]);
            sz1.setColumnNeurons(i, in1.inputs);
        }
        for (int n = 0; n < in_p1.Length; n++)
        {
            out1.reset();
            DebugLog.Log("Analyse " + n + " pattern");
            in1.setBooleans(in_p1[n]);
            dbgout = "";
            for (int i = 0; i < in1.inputs.Length; i++)
            {
                dbgout += (in1.inputs[i].active > 0.8f ? "A" : "_") + " ";
            }
            DebugLog.Log("Pattern : " + dbgout);
            in1.sendSignals();
            sz1.analyze();
            dbgout = "";
            for (int i = 0; i < out1.inputs.Length; i++)
            {
                dbgout += (out1.inputsActives[i] > 0.8f ? "A" : "_") + " ";
            }
            DebugLog.Log("Columns : " + dbgout);
            out1.reset();
        }
        //sz1.teach();
        return(true);
    }
Exemple #8
0
    public bool Split(float minZoneSize, float maxZoneSize)
    {
        if (!IAmLeaf())
        {
            return(false);
        }

        bool splitH;

        if (rect.width / rect.height >= ZONE_SIZE_RATIO)
        {
            splitH = false;
        }
        else if (rect.height / rect.width >= ZONE_SIZE_RATIO)
        {
            splitH = true;
        }
        else
        {
            splitH = Random.Range(0.0f, 1.0f) > ZONE_SPLIT_VALUE;
        }

        if (Mathf.Min(rect.height, rect.width) * ZONE_SPLIT_VALUE < minZoneSize)
        {
            return(false);
        }

        float splitBorder = splitH ? rect.width - minZoneSize : rect.height - minZoneSize;
        int   split       = (int)Random.Range(minZoneSize, splitBorder);

        if (splitH)
        {
            left  = new SubZone(new Rect(rect.x, rect.y, rect.width, split));
            right = new SubZone(new Rect(rect.x, rect.y + split, rect.width, rect.height - split));
        }
        else
        {
            left  = new SubZone(new Rect(rect.x, rect.y, split, rect.height));
            right = new SubZone(new Rect(rect.x + split, rect.y, rect.width - split, rect.height));
        }

        return(true);
    }
            //public override string ToString() { return Name; }
            public override string ToString()
            {
                string displayAs = "";

                //string subzonetext = " (" + SubZone + ", " + Zone + ")";
                //if (subzonetext.Contains("no subzone")) subzonetext = "";

                //return Category + " - " + Name + subzonetext;
                if (!FilteringByCategory)
                {
                    displayAs = Category + " - ";
                }
                displayAs = displayAs + Name;
                if (!SubZone.Contains("no subzone"))
                {
                    displayAs = displayAs + " (" + SubZone;
                }
                if (SubZone.Contains("no subzone") && !FilteringByZone)
                {
                    displayAs = displayAs + " (";
                }
                if (!SubZone.Contains("no subzone") && !FilteringByZone)
                {
                    displayAs = displayAs + ", ";
                }
                if (!FilteringByZone)
                {
                    displayAs = displayAs + Zone + ")";
                }
                if (FilteringByZone && !SubZone.Contains("no subzone"))
                {
                    displayAs = displayAs + ")";
                }

                return(displayAs);
            }
Exemple #10
0
        public Zone getZoneTemplate(SubZone subzone, Map world, string zone_type)
        {
            var template = new Zone();

            template.mapid     = world.id;
            template.priority  = subzone.priority;
            template.zone_type = zone_type;
            template.area_type = subzone.points_info.type.ToUpper();

            string desc = Utility.LevelStringIndex.GetString(subzone.desc);

            if (desc.StartsWith("_") || desc == "")
            {
                desc = subzone.name + desc;
            }
            if (zone_type == "ITEM_USE")
            {
                template.name = getFormattedZoneName(desc, 0);
            }
            else
            {
                template.name = getFormattedZoneName(desc, world.id);
            }
            //template.description = (Utility.LevelStringIndex.GetString(subzone.desc) + "_" + world.id.ToString()).ToUpper();
            zoneDescription.Add(template.name + " // " + subzone.name + " : " + world.id.ToString());

            if (subzone.norecall != null)
            {
                template.norecall = subzone.norecall.ToUpper() == "TRUE" ? true : false;
            }
            if (subzone.noride != null)
            {
                template.noride = subzone.noride.ToUpper() == "TRUE" ? true : false;
            }


            if (zone_type == "ARTIFACT")
            {
                // make list of siege artifacts that affect this area
                var artifact_infos = Utility.ZoneDataFile.artifact_infos != null?Utility.ZoneDataFile.artifact_infos.artifact_info.Where(n => n != null) : new List <ArtifactInfo>();

                List <int> siegeId = new List <int>();
                foreach (var artifact in artifact_infos)
                {
                    if (artifact.artifact_result_area1 == subzone.name)
                    {
                        siegeId.Add(Convert.ToInt32(artifact.artifact_name.Split('_')[1].Substring(0, 4)));
                    }
                }
                if (siegeId.Count > 0)
                {
                    template.siege_id = siegeId;
                }
            }
            else
            {
                template.siege_id = null;
            }
            if (zone_type == "FORT")
            {
                List <int> abyssid = new List <int>();
                abyssid.Add(subzone.abyss_id);
                template.siege_id = abyssid;
            }

            template.points        = new Points();
            template.points.top    = subzone.points_info.top;
            template.points.bottom = subzone.points_info.bottom;
            template.points.point  = new List <Point>();

            IEnumerable points = subzone.points_info.points.data as IEnumerable;

            foreach (ParserBase.Data point in points)
            {
                Point newpoint = new Point();
                newpoint.x = Math.Round(point.x, 4);
                newpoint.y = Math.Round(point.y, 4);
                template.points.point.Add(newpoint);
            }

            return(template);
        }
Exemple #11
0
    private float GetSubZoneWeight(SubZone subZone)
    {
        float weight = 0;

        subZoneDirection = GetDirectionFromAngle(GetNormAngle(subZone.minAngle + Mathf.DeltaAngle(subZone.minAngle, subZone.maxAngle) * 0.5f));

        for (int o = 0; o < bioElements.Count; o++)
        {
            pointDistance      = Vector2.Distance(Coordinates.ConvertWorldToVector2(bioElements[o].position), coords.position);
            pointRelativeAngle = Vector2.SignedAngle(Vector2.right, Coordinates.ConvertWorldToVector2(bioElements[o].position) - coords.position);
            if (pointDistance < subZone.maxRange && pointDistance >= subZone.minRange && IsBetweenAngle(pointRelativeAngle, subZone.minAngle, subZone.maxAngle))
            {
                weight += currentState == VigilanceState.calm ? benefPointFactorBioCalm : 0;
                weight += currentState == VigilanceState.worried ? benefPointFactorBioWorried : 0;
                weight += currentState == VigilanceState.panicked ? benefPointFactorBioPanicked : 0;
            }
        }

        switch (currentState)
        {
        case VigilanceState.calm:
            weight += Mathf.Cos(Mathf.Deg2Rad * Vector2.Angle(targetDirection, subZoneDirection)) * distanceFactorWeightWhileCalm;
            break;

        case VigilanceState.worried:
            weight += Mathf.Cos(Mathf.Deg2Rad * Vector2.Angle(targetDirection, subZoneDirection)) * distanceFactorWeightWhileWorried;
            break;

        case VigilanceState.panicked:
            weight += Mathf.Cos(Mathf.Deg2Rad * Vector2.Angle(targetDirection, subZoneDirection)) * distanceFactorWeightWhilePanicked;
            break;
        }

        if (environnement.ZoneIn(coords.position) != 0)
        {
            if (environnement.zones[environnement.ZoneIn(coords.position) - 1].state == ZoneState.SeaWay)
            {
                switch (currentState)
                {
                case VigilanceState.calm:
                    weight += beneftPointFactorSeaWayCalm;
                    break;

                case VigilanceState.worried:
                    weight += beneftPointFactorSeaWayWorried;
                    break;

                case VigilanceState.panicked:
                    weight += beneftPointFactorSeaWayPanicked;
                    break;
                }
            }
            else if (environnement.zones[environnement.ZoneIn(coords.position) - 1].state == ZoneState.WindyZone)
            {
                switch (currentState)
                {
                case VigilanceState.calm:
                    weight += beneftPointFactorWindyZoneCalm;
                    break;

                case VigilanceState.worried:
                    weight += beneftPointFactorWindyZoneWorried;
                    break;

                case VigilanceState.panicked:
                    weight += beneftPointFactorWindyZonePanicked;
                    break;
                }
            }
            else if (environnement.zones[environnement.ZoneIn(coords.position) - 1].state == ZoneState.SeaTurbulent)
            {
                switch (currentState)
                {
                case VigilanceState.calm:
                    weight += beneftPointFactorSeaTurbulentCalm;
                    break;

                case VigilanceState.worried:
                    weight += beneftPointFactorSeaTurbulentWorried;
                    break;

                case VigilanceState.panicked:
                    weight += beneftPointFactorSeaTurbulentPanicked;
                    break;
                }
            }
        }

        pointDistance      = Vector2.Distance(ship.coords.position, coords.position);
        pointRelativeAngle = Vector2.SignedAngle(Vector2.right, ship.coords.position - coords.position);
        if (pointDistance < subZone.maxRange && pointDistance >= subZone.minRange && IsBetweenAngle(pointRelativeAngle, subZone.minAngle, subZone.maxAngle))
        {
            weight = -1000;
            subZone.needToBeAvoided = true;
        }



        for (int b = 0; b < sonobuoys.Count; b++)
        {
            pointDistance      = Vector2.Distance(Coordinates.ConvertWorldToVector2(sonobuoys[b].position), coords.position);
            pointRelativeAngle = Vector2.SignedAngle(Vector2.right, Coordinates.ConvertWorldToVector2(sonobuoys[b].position) - coords.position);
            if (pointDistance < subZone.maxRange && pointDistance >= subZone.minRange && IsBetweenAngle(pointRelativeAngle, subZone.minAngle, subZone.maxAngle))
            {
                switch (currentState)
                {
                case VigilanceState.calm:
                    weight += beneftPointFactorSonobuoyCalm;
                    break;

                case VigilanceState.worried:
                    weight += beneftPointFactorSonobuoyWorried;
                    break;

                case VigilanceState.panicked:
                    weight += beneftPointFactorSonobuoyPanicked;
                    break;
                }

                subZone.needToBeAvoided = true;
            }
        }

        return(weight);
    }
Exemple #12
0
    private Vector2 FindNextIntermediatePosition()
    {
        allSubZones.Clear();
        float startAngle = Vector2.SignedAngle(Vector2.right, targetDirection) - (360 / (subZone12Subdivision * subZone3SubSubdivision));

        for (int i = 0; i < subZone12Subdivision; i++)
        {
            allSubZones.Add(new SubZone(GetNormAngle(startAngle + i * subZoneAngleWidth12), GetNormAngle(startAngle + (i + 1) * subZoneAngleWidth12), minRange, detectionRangeCalm, i, "SZ_" + i + "_0", this));
            if (isSubmarineDisplayed)
            {
                Debug.DrawRay(Coordinates.ConvertVector2ToWorld(coords.position),
                              Coordinates.ConvertVector2ToWorld(GetDirectionFromAngle(allSubZones[allSubZones.Count - 1].minAngle) * detectionRangeCalm),
                              Color.green);
            }

            if (currentState == VigilanceState.worried ||
                currentState == VigilanceState.panicked)
            {
                allSubZones.Add(new SubZone(GetNormAngle(startAngle + i * subZoneAngleWidth12), GetNormAngle(startAngle + (i + 1) * subZoneAngleWidth12), detectionRangeCalm, detectionRangeWorried, i, "SZ_" + i + "_1", this));

                if (isSubmarineDisplayed)
                {
                    Debug.DrawRay(Coordinates.ConvertVector2ToWorld(coords.position + GetDirectionFromAngle(allSubZones[allSubZones.Count - 1].minAngle) * detectionRangeCalm),
                                  Coordinates.ConvertVector2ToWorld(GetDirectionFromAngle(allSubZones[allSubZones.Count - 1].minAngle) * (detectionRangeWorried - detectionRangeCalm)),
                                  Color.cyan);
                }


                if (currentState == VigilanceState.panicked)
                {
                    for (int y = 0; y < subZone3SubSubdivision; y++)
                    {
                        allSubZones.Add(new SubZone(GetNormAngle(startAngle + i * subZoneAngleWidth12 + y * subZoneAngleWidth3), GetNormAngle(startAngle + i * subZoneAngleWidth12 + (y + 1) * subZoneAngleWidth3), detectionRangeWorried, detectionRangePanicked, i, "SZ_" + i + "_2." + y, this));
                        if (isSubmarineDisplayed)
                        {
                            Debug.DrawRay(Coordinates.ConvertVector2ToWorld(coords.position + GetDirectionFromAngle(allSubZones[allSubZones.Count - 1].minAngle) * detectionRangeWorried), Coordinates.ConvertVector2ToWorld(GetDirectionFromAngle(allSubZones[allSubZones.Count - 1].minAngle) * (detectionRangePanicked - detectionRangeWorried)), Color.red);
                        }
                    }
                }
            }

            /*if (isSubmarineDisplayed)
             *  circleGismos.Add(new CircleGizmo(coords.position, detectionRangeCalm, Color.green));*/

            if (currentState == VigilanceState.worried ||
                currentState == VigilanceState.panicked)
            {
                /*if (isSubmarineDisplayed)
                 *  circleGismos.Add(new CircleGizmo(coords.position, detectionRangeWorried, Color.cyan));*/


                if (currentState == VigilanceState.panicked)
                {
                    /*if (isSubmarineDisplayed)
                     *  circleGismos.Add(new CircleGizmo(coords.position, detectionRangePanicked, Color.red));*/
                }
            }
        }
        SubZone bestSubZone = allSubZones[0];

        for (int i = 0; i < allSubZones.Count; i++)
        {
            allSubZones[i].weight = GetSubZoneWeight(allSubZones[i]);
        }

        for (int i = 0; i < allSubZones.Count; i++)
        {
            if (allSubZones[i].needToBeAvoided && avoidEffectSliceReach > 0)
            {
                for (int y = 0; y < allSubZones.Count; y++)
                {
                    if (allSubZones[y].sliceIndex == allSubZones[i].sliceIndex)
                    {
                        allSubZones[y].weight = -1000;
                        //sphereGizmos.Add(new SphereGizmo(allSubZones[y].zoneCenterPos, 0.4f, Color.black));
                    }

                    for (int s = 1; s < avoidEffectSliceReach; s++)
                    {
                        if ((allSubZones[i].sliceIndex + s) < subZone12Subdivision)
                        {
                            if (allSubZones[y].sliceIndex == (allSubZones[i].sliceIndex + s))
                            {
                                allSubZones[y].weight = -1000;
                                //sphereGizmos.Add(new SphereGizmo(allSubZones[y].zoneCenterPos, 0.4f, Color.black));
                            }
                        }
                        else
                        {
                            if (allSubZones[y].sliceIndex == s - (subZone12Subdivision - allSubZones[i].sliceIndex))
                            {
                                allSubZones[y].weight = -1000;
                                //sphereGizmos.Add(new SphereGizmo(allSubZones[y].zoneCenterPos, 0.4f, Color.black));
                            }
                        }


                        if ((allSubZones[i].sliceIndex - s) >= 0)
                        {
                            if (allSubZones[y].sliceIndex == (allSubZones[i].sliceIndex - s))
                            {
                                allSubZones[y].weight = -1000;
                                //sphereGizmos.Add(new SphereGizmo(allSubZones[y].zoneCenterPos, 0.4f, Color.black));
                            }
                        }
                        else
                        {
                            if (allSubZones[y].sliceIndex == (subZone12Subdivision - (s - allSubZones[i].sliceIndex)))
                            {
                                allSubZones[y].weight = -1000;
                                //sphereGizmos.Add(new SphereGizmo(allSubZones[y].zoneCenterPos, 0.4f, Color.black));
                            }
                        }
                    }
                }
            }
        }

        for (int i = 0; i < allSubZones.Count; i++)
        {
            //sphereGizmos.Add(new SphereGizmo(allSubZones[i].zoneCenterPos, 0.2f, Color.Lerp(Color.red, Color.yellow, (allSubZones[i].weight + 15) / 20)));

            if (bestSubZone == null || allSubZones[i].weight > bestSubZone.weight)
            {
                bestSubZone = allSubZones[i];
            }
        }

        return(bestSubZone.zoneCenterPos);
    }
Exemple #13
0
    public void HW2()
    {
        string dbgout = "";

        DebugLog.Log("HW2 - Sequence");
        InputMatrix  in1  = new InputMatrix(5);
        SubZone      sz1  = new SubZone(5);
        OutputMatrix out1 = new OutputMatrix(5);

        in1.setUpSubZone(sz1);
        sz1.setDownSubZones(in1);
        sz1.setUpSubZone(out1);
        out1.addInputs(sz1);
        DebugLog.Log("Learn");
        bool[][] in_p1 = new bool[][] {
            new bool[] { true, true, false, false, false },
            new bool[] { false, true, true, false, false },
        };
        for (int i = 0; i < in_p1.Length; i++)
        {
            in1.setBooleans(in_p1[i]);
            sz1.setColumnNeurons(0, in1.inputs);
        }
        bool[][] in_p2 = new bool[][] {
            new bool[] { false, false, true, true, false },
            new bool[] { false, false, false, true, true },
        };
        for (int i = 0; i < in_p2.Length; i++)
        {
            in1.setBooleans(in_p2[i]);
            sz1.setColumnNeurons(1, in1.inputs);
        }
        bool[][] in_p3 = new bool[][] {
            new bool[] { false, false, true, true, false },
            new bool[] { false, true, true, false, false },
            new bool[] { true, true, false, false, false },
        };
        for (int i = 0; i < in_p3.Length; i++)
        {
            in1.setBooleans(in_p3[i]);
            sz1.setColumnNeurons(2, in1.inputs);
        }
        bool[][] in_p4 = new bool[][] {
            new bool[] { true, false, false, false, true },
            new bool[] { false, true, false, true, false },
            new bool[] { false, false, true, false, false },
        };
        for (int i = 0; i < in_p4.Length; i++)
        {
            in1.setBooleans(in_p4[i]);
            sz1.setColumnNeurons(3, in1.inputs);
        }
        bool[][] in_p5 = new bool[][] {
            new bool[] { true, false, false, false, false },
            new bool[] { false, true, false, false, false },
            new bool[] { false, false, true, false, false },
            new bool[] { false, false, false, true, false },
            new bool[] { false, false, false, false, true },
        };
        for (int i = 0; i < in_p5.Length; i++)
        {
            in1.setBooleans(in_p5[i]);
            sz1.setColumnNeurons(4, in1.inputs);
        }
        bool[][] in_p = new bool[][] {
            new bool[] { true, false, false, false, false }, // 5
            new bool[] { false, true, false, false, false }, // 5
            new bool[] { false, false, true, false, false }, // 5
            new bool[] { false, false, false, true, false }, // 5
            new bool[] { false, false, false, false, true }, // 5
            new bool[] { false, false, false, true, true },  // _
            new bool[] { false, false, true, true, false },  // 2, 3
            new bool[] { false, true, true, false, false },  // 3
            new bool[] { true, true, false, false, false },  // 3, 1
            new bool[] { false, true, true, false, false },  // 1
            new bool[] { false, false, true, true, false },  // 2
            new bool[] { false, false, false, true, true },  // 2
            new bool[] { true, false, false, false, true },  // 4
            new bool[] { false, true, false, true, false },  // 4
            new bool[] { false, false, true, false, false }, // 4
            new bool[] { false, false, false, true, false }, // _
            new bool[] { false, false, false, false, true }, // _
            new bool[] { true, false, false, false, false }, // 5
            new bool[] { false, true, false, false, false }, // 5
            new bool[] { false, false, true, false, false }, // 5
            new bool[] { true, false, false, false, true },  // 4
            new bool[] { false, true, false, true, false },  // 4
            new bool[] { false, false, true, true, false },  // 3
            new bool[] { false, true, true, false, false },  // 3
            new bool[] { true, true, false, false, false },  // 3
            new bool[] { true, false, false, false, true },  // 4
            new bool[] { true, true, false, false, false },  // 1
            new bool[] { false, true, true, false, false },  // 1
            new bool[] { false, false, true, true, false },  // 3
            new bool[] { false, false, false, true, true },  // _
        };
        bool[][] in_e = new bool[][] {
            new bool[] { false, false, false, false, true },  // 5
            new bool[] { false, false, false, false, true },  // 5
            new bool[] { false, false, false, false, true },  // 5
            new bool[] { false, false, false, false, true },  // 5
            new bool[] { false, false, false, false, true },  // 5
            new bool[] { false, false, false, false, false }, // _
            new bool[] { false, true, true, false, false },   // 2, 3
            new bool[] { false, false, true, false, false },  // 3
            new bool[] { true, false, true, false, false },   // 3, 1
            new bool[] { true, false, false, false, false },  // 1
            new bool[] { false, true, false, false, true },   // 2, 5
            new bool[] { false, true, false, false, false },  // 2
            new bool[] { false, false, false, true, false },  // 4
            new bool[] { false, false, false, true, false },  // 4
            new bool[] { false, false, false, true, false },  // 4
            new bool[] { false, false, false, false, false }, // _
            new bool[] { false, false, false, false, false }, // _
            new bool[] { false, false, false, false, true },  // 5
            new bool[] { false, false, false, false, true },  // 5
            new bool[] { false, false, false, false, true },  // 5
            new bool[] { false, false, false, true, false },  // 4
            new bool[] { false, false, false, true, false },  // 4
            new bool[] { false, true, true, false, false },   // 3, 2
            new bool[] { false, false, true, false, false },  // 3
            new bool[] { false, false, true, false, false },  // 3
            new bool[] { false, false, false, true, false },  // 4
            new bool[] { true, false, false, false, false },  // 1
            new bool[] { true, false, false, false, false },  // 1
            new bool[] { false, true, false, false, false },  // 2
            new bool[] { false, true, false, false, false },  // 2
        };
        for (int n = 0; n < in_p.Length; n++)
        {
            DebugLog.Log("Analyse " + n + " pattern");
            in1.setBooleans(in_p[n]);
            dbgout = "";
            for (int i = 0; i < in1.inputs.Length; i++)
            {
                dbgout += (in1.inputs[i].active > 0.8f ? "A" : "_") + " ";
            }
            DebugLog.Log("Pattern : " + dbgout);
            dbgout = "";
            for (int i = 0; i < in1.inputs.Length; i++)
            {
                dbgout += (in_e[n][i] ? "A" : "_") + " ";
            }
            DebugLog.Log("Etalon : " + dbgout);
            in1.sendSignals();
            sz1.analyze();
            dbgout = "";
            for (int i = 0; i < out1.inputs.Length; i++)
            {
                dbgout += (out1.inputsActives[i] > 0.8f ? "A" : "_") + " ";
            }
            DebugLog.Log("Columns : " + dbgout);
            dbgout = "";
            for (int i = 0; i < out1.inputs.Length; i++)
            {
                dbgout += (in1.inputs[i].prediction >= 0.5f ? "A" : "_") + " ";
            }
            DebugLog.Log("Prediction : " + dbgout);
            out1.reset();
        }
        //sz1.teach();
    }
Exemple #14
0
    public void HW4()
    {
        string dbgout = "";

        DebugLog.Log("HW4 - Motor");
        InputMatrix  in1  = new InputMatrix(5);
        SubZone      sz1  = new SubZone(5);
        OutputMatrix out1 = new OutputMatrix(5);

        in1.setUpSubZone(sz1);
        sz1.setDownSubZones(in1);
        sz1.setUpSubZone(out1);
        out1.setDownSubZones(sz1);
        out1.addInputs(sz1);
        DebugLog.Log("Learn");

        bool[][] in_p2 = new bool[][] {
            new bool[] { false, false, true, true, false },
            new bool[] { false, false, false, true, true },
        };
        for (int i = 0; i < in_p2.Length; i++)
        {
            in1.setBooleans(in_p2[i]);
            sz1.setColumnNeurons(1, in1.inputs);
        }
        bool[][] in_p3 = new bool[][] {
            new bool[] { false, false, true, true, false },
            new bool[] { false, true, true, false, false },
            new bool[] { true, true, false, false, false },
        };
        for (int i = 0; i < in_p3.Length; i++)
        {
            in1.setBooleans(in_p3[i]);
            sz1.setColumnNeurons(2, in1.inputs);
        }

        bool[][] in_p = new bool[][] {
            new bool[] { false, false, false, true, false }, // _
            new bool[] { false, false, true, true, false },  // 2,3
        };

        for (int n = 0; n < in_p.Length; n++)
        {
            DebugLog.Log("Analyse " + n + " pattern");
            in1.setBooleans(in_p[n]);
            dbgout = "";
            for (int i = 0; i < in1.inputs.Length; i++)
            {
                dbgout += (in1.inputs[i].active > 0.8f ? "A" : "_") + " ";
            }
            DebugLog.Log("Pattern : " + dbgout);
            in1.sendSignals();
            sz1.analyze();
            dbgout = "";
            for (int i = 0; i < out1.inputs.Length; i++)
            {
                dbgout += (out1.inputsActives[i] > 0.8f ? "A" : "_") + " ";
            }
            DebugLog.Log("Columns : " + dbgout);
            dbgout = "";
            for (int i = 0; i < out1.inputs.Length; i++)
            {
                dbgout += (in1.inputs[i].prediction >= 0.5f ? "A" : "_") + " ";
            }
            DebugLog.Log("Prediction : " + dbgout);
            for (int p = 0; p < 5; p++)
            {
                DebugLog.Log("Motor " + p + " pattern");
                out1.outSignalMotor(p);
                dbgout = "";
                for (int i = 0; i < in1.inputs.Length; i++)
                {
                    dbgout += (in1.getMotorValues()[i] >= 0.5f ? "A" : "_") + " ";
                }
                DebugLog.Log("Motor : " + dbgout);
                in1.reset();
            }
            out1.reset();
        }
        sz1.onDeactive();
    }