{"id":22426654,"url":"https://github.com/theypsilon/evolearning","last_synced_at":"2025-06-18T13:35:39.005Z","repository":{"id":152994262,"uuid":"216693612","full_name":"theypsilon/EvoLearning","owner":"theypsilon","description":"Simple Tensor, Neural Network and Evolutionary Reinforcement Learning libraries","archived":false,"fork":false,"pushed_at":"2019-10-22T01:32:51.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T11:30:23.029Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theypsilon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-22T00:59:38.000Z","updated_at":"2019-10-22T01:32:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6217069-f824-4887-9535-6b0cc421a521","html_url":"https://github.com/theypsilon/EvoLearning","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2FEvoLearning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2FEvoLearning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2FEvoLearning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2FEvoLearning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theypsilon","download_url":"https://codeload.github.com/theypsilon/EvoLearning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245792989,"owners_count":20672885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T19:22:54.328Z","updated_at":"2025-03-27T06:22:44.034Z","avatar_url":"https://github.com/theypsilon.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EvoLearning\nSimple Tensor, Neural Network and Evolutionary Reinforcement Learning libraries\n\n## Bot Example\n\n```csharp\npublic sealed class NeuralNetworkBot : IInputWriter {\n    private NeuralNetwork _nn = null;\n\n    private Context _ctx; // This is a struct containing the simulation state, defined elsewhere.\n    double _fitness = 0;\n    const int InputRaysSize = 30;\n    float[] _inputRays = new float[InputRaysSize];\n\n    public NeuralNetworkBot(Context ctx) {\n        _ctx = ctx;\n        _nn = NeuralNetwork.FromFileOrScratch(new int[] {InputRaysSize, 500, 2});\n        Pre.Assert(ctx.State.Config.DLRays \u003e 0, ctx.State.Config.DLRays);\n    }\n\n    public void WriteInput(ref Input input) {\n\n        if (_ctx.State.Player.HasJustDied) {\n            _nn.FinishLife((int) _fitness, (int) _ctx.State.Stage.StageNumber);\n        } else if (_ctx.State.Player.HasJustReborn) {\n            _nn.NextLife();\n            _fitness = 0;\n        }\n\n        if (_ctx.State.Player.IsDead) {\n            return;\n        }\n\n        // These components are using the following library: https://github.com/theypsilon/MiniECS\n        var playerPosition = _ctx.Pools.PositionComponents.Get(_ctx.State.Player.Entity);\n\n        var fitnessChange = 0.0;\n        float[] inputNeurons = null;\n\n        // The input neurons are values between [0.0, 1.0] indicating the proximity of an enemy\n        // 0 indicates undetected enemy\n        // 0.5 indicates enemy detected at intermediate distance\n        // 1.0 indicates enemy at collision distance\n        // It basically works like a sonar, with rays pointing all coordinates around\n        \n        var neurons = _ctx.State.DeepLearning.Rays; \n        if (neurons == null) return;\n\n        for (var i = 0; i \u003c neurons.Length; i++) {\n            _inputRays[i] = neurons[i];\n            if (neurons[i] \u003e= 0.85) { // indicates an enemy is very close, I'd like to punish that.\n                fitnessChange = -1.5;\n            }\n        }\n        for (var i = 0; i \u003c neurons.Length; i++) {\n            _inputRays[15 + i] = playerPosition.Point.X / 1080; // Player position is between [0.0, 1080.0]\n        }\n        inputNeurons = _inputRays;\n        \n        _nn.Predict(inputNeurons, ref input.Control.Left, ref input.Control.Right);\n\n        // rewarding survivavility\n        fitnessChange += 1.0;\n        \n        // rewarding not moving\n        if (input.Control.Left == false) {\n            fitnessChange += 0.1;\n        }\n        if (input.Control.Right == false) {\n            fitnessChange += 0.1;\n        }\n        \n        // rewarding staying in the center of the screen\n        if (playerPosition.Point.X \u003c 100) {\n            fitnessChange -= 0.25;\n        }\n        if (playerPosition.Point.X \u003e 980) {\n            fitnessChange -= 0.25;\n        }\n\n        _fitness += fitnessChange;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheypsilon%2Fevolearning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheypsilon%2Fevolearning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheypsilon%2Fevolearning/lists"}