Skip to content

Commit

Permalink
Refactor: Improve code readability in various scripts
Browse files Browse the repository at this point in the history
Some scripts had inconsistencies and lacked sufficient code segregation which made the readability less intuitive. The changes involve:

1. Addition of a #region directive to encapsulate the specific namespaces for clarity.
2. Breaking down and reformatting complex lines of codes into simpler and more intuitive formats.
3. Improved the arrangement of the uniform variables for better readability.
4. Applied better spacing throughout the program to ensure consistency.
5. Included some small refactoring changes in the scripts to improve the overall code quality.

Importantly, no functional changes have been made to the original design.
Pristar4 committed Jul 12, 2023
1 parent eae6e34 commit c8c02b6
Showing 61 changed files with 1,290 additions and 342 deletions.
68 changes: 67 additions & 1 deletion Assets/ML-Agents/Timers/AI_timers.json
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
{"count":1,"self":1070.6020352,"total":3714.9059334,"children":{"InitializeActuators":{"count":24,"self":0.0015083,"total":0.0015083,"children":null},"InitializeSensors":{"count":24,"self":0.0015055,"total":0.0015055,"children":null},"AgentSendState":{"count":461466,"self":7.9821912,"total":43.912659399999995,"children":{"CollectObservations":{"count":3691728,"self":11.673304,"total":11.6733041,"children":null},"WriteActionMask":{"count":3691728,"self":1.7134748,"total":1.7134748,"children":null},"RequestDecision":{"count":3691728,"self":5.8726204,"total":22.5436892,"children":{"AgentInfo.ToProto":{"count":3691728,"self":5.2082856,"total":16.671068899999998,"children":{"GenerateSensorData":{"count":3691728,"self":11.462783199999999,"total":11.4627831,"children":null}}}}}}},"DecideAction":{"count":461466,"self":2493.6136704,"total":2493.6136833,"children":null},"AgentAct":{"count":461466,"self":106.6151168,"total":106.77455959999999,"children":{"AgentInfo.ToProto":{"count":20861,"self":0.0722235,"total":0.1594411,"children":{"GenerateSensorData":{"count":20861,"self":0.087217599999999992,"total":0.087217599999999992,"children":null}}}}}},"gauges":{"SnakeAi.CumulativeReward":{"count":20861,"max":281.898163,"min":-137.800354,"runningAverage":50.4565544,"value":35.8000336,"weightedAverage":68.77597}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1689110079","unity_version":"2023.1.3f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.3.0-exp.3","scene_name":"AI","end_time_seconds":"1689113793"}}
{
"count": 1,
"self": 9.3403792,
"total": 9.3681278,
"children": {
"InitializeActuators": {
"count": 8,
"self": 0.0010034,
"total": 0.0010034,
"children": null
},
"InitializeSensors": {
"count": 8,
"self": 0.0009994,
"total": 0.0009994,
"children": null
},
"AgentSendState": {
"count": 1,
"self": 0.0010061,
"total": 0.010084899999999999,
"children": {
"CollectObservations": {
"count": 8,
"self": 0.0080716,
"total": 0.0080716,
"children": null
},
"WriteActionMask": {
"count": 8,
"self": 0,
"total": 0,
"children": null
},
"RequestDecision": {
"count": 8,
"self": 0.0010072,
"total": 0.0010072,
"children": null
}
}
},
"DecideAction": {
"count": 1,
"self": 0.0015562999999999998,
"total": 0.0015562999999999998,
"children": null
},
"AgentAct": {
"count": 1,
"self": 0.014104799999999999,
"total": 0.014104799999999999,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689167416",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "AI",
"end_time_seconds": "1689167425"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"count": 1,
"self": 4.2739704,
"total": 4.276006,
"children": {
"InitializeActuators": {
"count": 1,
"self": 0.00050389999999999994,
"total": 0.00050389999999999994,
"children": null
},
"InitializeSensors": {
"count": 1,
"self": 0.0010049,
"total": 0.0010049,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689122640",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "InitTestScene638247266395951172",
"end_time_seconds": "1689122645"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"count": 1,
"self": 89.8113408,
"total": 89.812848699999989,
"children": {
"InitializeActuators": {
"count": 2,
"self": 0.00050389999999999994,
"total": 0.00050389999999999994,
"children": null
},
"InitializeSensors": {
"count": 2,
"self": 0.0010049,
"total": 0.0010049,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689122640",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "InitTestScene638247267290958812",
"end_time_seconds": "1689122730"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"count": 1,
"self": 0.15764409999999998,
"total": 0.1611676,
"children": {
"InitializeActuators": {
"count": 1,
"self": 0.0010065999999999999,
"total": 0.0010065999999999999,
"children": null
},
"InitializeSensors": {
"count": 1,
"self": 0.0010134,
"total": 0.0010134,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689122862",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "InitTestScene638247268610573678",
"end_time_seconds": "1689122862"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"count": 1,
"self": 5.3269,
"total": 5.3289199,
"children": {
"InitializeActuators": {
"count": 2,
"self": 0.0010065999999999999,
"total": 0.0010065999999999999,
"children": null
},
"InitializeSensors": {
"count": 2,
"self": 0.0010134,
"total": 0.0010134,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689122862",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "InitTestScene638247268662157737",
"end_time_seconds": "1689122867"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"count": 1,
"self": 29.1070912,
"total": 29.109111199999997,
"children": {
"InitializeActuators": {
"count": 3,
"self": 0.0010065999999999999,
"total": 0.0010065999999999999,
"children": null
},
"InitializeSensors": {
"count": 3,
"self": 0.0010134,
"total": 0.0010134,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689122862",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "InitTestScene638247268719317398",
"end_time_seconds": "1689122891"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"count": 1,
"self": 0.1554462,
"total": 0.157462,
"children": {
"InitializeActuators": {
"count": 1,
"self": 0,
"total": 0,
"children": null
},
"InitializeSensors": {
"count": 1,
"self": 0.0010096,
"total": 0.0010096,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689122994",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "InitTestScene638247269934663094",
"end_time_seconds": "1689122994"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"count": 1,
"self": 0.19104,
"total": 0.19357549999999998,
"children": {
"InitializeActuators": {
"count": 1,
"self": 0.0005186,
"total": 0.0005186,
"children": null
},
"InitializeSensors": {
"count": 1,
"self": 0.0005045,
"total": 0.0005045,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689123118",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "InitTestScene638247271174642528",
"end_time_seconds": "1689123119"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"count": 1,
"self": 127.58368,
"total": 127.58469849999999,
"children": {
"InitializeActuators": {
"count": 2,
"self": 0.0005186,
"total": 0.0005186,
"children": null
},
"InitializeSensors": {
"count": 2,
"self": 0.0005045,
"total": 0.0005045,
"children": null
}
},
"gauges": {},
"metadata": {
"timer_format_version": "0.1.0",
"start_time_seconds": "1689123118",
"unity_version": "2023.1.3f1",
"command_line_arguments": "C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.3f1\\Editor\\Unity.exe -projectpath C:\\Users\\felix\\SnakeGame -useHub -hubIPC -cloudEnvironment production",
"communication_protocol_version": "1.5.0",
"com.unity.ml-agents_version": "2.3.0-exp.3",
"scene_name": "InitTestScene638247272406491140",
"end_time_seconds": "1689123246"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c8c02b6

Please sign in to comment.