Skip to content

Commit

Permalink
added WIP AI scene for using ml agents to train the snakes
Browse files Browse the repository at this point in the history
This commit includes various changes to improve and add functionality to the Snake game. The specific changes include:

- Addition of the ml-agents package for establishing a Machine Learning environment.
- Modification of tile prefab to adjust sprite and size.
- Added a wrap feature in the GameManager, allowing the snake to wrap around the board.
- Changes in SnakeController allowing the control of snake's movement with the newly added wrap feature.
- Changes made to various materials like Food, None and Snake to change their respective shaders.
- Modified the GameManager script in the Main Unity scene and made changes to the board's settings.
- The width, height and snake movement settings of the GameManager script have been adjusted.
- Update in Scene objects’ rotation and position.
- Changes to BoardDisplay, TileDisplay and SpriteBoardDisplay to assist in visual updates of the game state.
  • Loading branch information
Pristar4 committed Jul 4, 2023
1 parent 9cbfcf8 commit 2ab9926
Show file tree
Hide file tree
Showing 23 changed files with 1,593 additions and 73 deletions.
8 changes: 8 additions & 0 deletions Assets/ML-Agents.meta

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

8 changes: 8 additions & 0 deletions Assets/ML-Agents/Timers.meta

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

1 change: 1 addition & 0 deletions Assets/ML-Agents/Timers/AI_timers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"count":1,"self":146.5437824,"total":146.5523294,"children":{"InitializeActuators":{"count":12,"self":0.0010006,"total":0.0010006,"children":null},"InitializeSensors":{"count":12,"self":0.0015075,"total":0.0015075,"children":null},"AgentSendState":{"count":395,"self":0.0015107999999999999,"total":0.0015107999999999999,"children":null},"DecideAction":{"count":395,"self":0.0040206999999999994,"total":0.0040206999999999994,"children":null},"AgentAct":{"count":395,"self":0.0005068,"total":0.0005068,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1688511292","unity_version":"2023.1.2f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.2f1\\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":"1688511438"}}
7 changes: 7 additions & 0 deletions Assets/ML-Agents/Timers/AI_timers.json.meta

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

1 change: 1 addition & 0 deletions Assets/ML-Agents/Timers/Main_timers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"count":1,"self":38.4066496,"total":38.4183148,"children":{"InitializeActuators":{"count":1,"self":0.0009992,"total":0.0009992,"children":null},"InitializeSensors":{"count":1,"self":0.0015080999999999998,"total":0.0015080999999999998,"children":null},"AgentSendState":{"count":332,"self":0.0055420999999999995,"total":0.0055420999999999995,"children":null},"DecideAction":{"count":332,"self":0.0025223999999999997,"total":0.0025223999999999997,"children":null},"AgentAct":{"count":332,"self":0.0010927999999999999,"total":0.0010927999999999999,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1688511153","unity_version":"2023.1.2f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2023.1.2f1\\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":"Main","end_time_seconds":"1688511192"}}
7 changes: 7 additions & 0 deletions Assets/ML-Agents/Timers/Main_timers.json.meta

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

17 changes: 16 additions & 1 deletion Assets/SnakeGame/MaterialLibary/Food.mat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Food
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
Expand All @@ -23,6 +23,10 @@ Material:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
Expand Down Expand Up @@ -61,10 +65,13 @@ Material:
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- PixelSnap: 0
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnableExternalAlpha: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
Expand All @@ -75,9 +82,17 @@ Material:
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 0.9598555, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
21 changes: 19 additions & 2 deletions Assets/SnakeGame/MaterialLibary/NoneMaterial.mat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: NoneMaterial
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
Expand All @@ -23,6 +23,10 @@ Material:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
Expand Down Expand Up @@ -61,10 +65,14 @@ Material:
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- PixelSnap: 0
- _BumpScale: 1
- _ColorMask: 15
- _CullMode: 0
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnableExternalAlpha: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
Expand All @@ -75,9 +83,18 @@ Material:
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.46226418, g: 0.45572272, b: 0.45572272, a: 1}
- _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
- _Color: {r: 0.33962262, g: 0.33962262, b: 0.33962262, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
19 changes: 18 additions & 1 deletion Assets/SnakeGame/MaterialLibary/Snake.mat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Snake
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
Expand All @@ -23,6 +23,10 @@ Material:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
Expand Down Expand Up @@ -61,10 +65,14 @@ Material:
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- PixelSnap: 0
- _BumpScale: 1
- _ColorMask: 15
- _CullMode: 0
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnableExternalAlpha: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
Expand All @@ -75,9 +83,18 @@ Material:
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
- _Color: {r: 0.0048570633, g: 1, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
Binary file added Assets/SnakeGame/Prefabs/New Piskel-1.png (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions Assets/SnakeGame/Prefabs/New Piskel-1.png (1).png.meta

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

6 changes: 3 additions & 3 deletions Assets/SnakeGame/Prefabs/Tile.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ SpriteRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
m_Sprite: {fileID: 21300000, guid: bd8107b330614b94c9acdf1740481e07, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_Size: {x: 2.56, y: 2.56}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
Expand All @@ -97,4 +97,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6049704594574d8fad8b56fae45b427a, type: 3}
m_Name:
m_EditorClassIdentifier:
spriteRenderer: {fileID: 0}
spriteRenderer: {fileID: 3081469578364191227}
Loading

0 comments on commit 2ab9926

Please sign in to comment.