Skip to content

Commit b85ad77

Browse files
committed
Add stuff
1 parent ac3aba8 commit b85ad77

File tree

17 files changed

+124
-249
lines changed

17 files changed

+124
-249
lines changed

DashAI.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30001.183
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DashAI", "DashAI\DashAI.csproj", "{43912928-DE13-4812-B02E-77AEAF988622}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DashAI", "DashAI\DashAI.csproj", "{43912928-DE13-4812-B02E-77AEAF988622}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

DashAI/BlackBoxBrain.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using SharpNeat.Phenomes;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
25

36
namespace DashAI
47
{
@@ -25,13 +28,24 @@ public void Step()
2528
{
2629
phenome.ResetState();
2730

28-
for (int y = 0; y < NeatConsts.ViewY; y++)
31+
foreach (int typeID in NeatConsts.typeIds)
2932
{
30-
for (int x = 0; x < NeatConsts.ViewX; x++)
33+
for (int y = 0; y < NeatConsts.ViewY; y++)
3134
{
32-
phenome.InputSignalArray[y * NeatConsts.ViewX + x] = game.map.map[game.player.position.y + 3 - y, game.player.position.x + x];
35+
for (int x = 0; x < NeatConsts.ViewX; x++)
36+
{
37+
var xpos = game.player.position.x + x;
38+
var ypos = game.player.position.y + (NeatConsts.ViewY/2) - y;
39+
var index = typeID * (y * NeatConsts.ViewX + x);
40+
if (ypos < 0 || xpos < 0 || ypos >= game.map.map.GetLength(0) || xpos >= game.map.map.GetLength(1))
41+
phenome.InputSignalArray[index] = 0;
42+
else
43+
phenome.InputSignalArray[index] = (game.map.map[ypos, xpos]) == typeID ? 1 : 0;
44+
}
3345
}
3446
}
47+
48+
3549
phenome.Activate();
3650
game.Step(phenome.OutputSignalArray[0] > 0.5);
3751
}

DashAI/BmpMap.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ public BmpMap(string path)
1414
var bmp = new Bitmap(path);
1515
var groundColor = Color.FromArgb(0, 0, 0);
1616
var spikesColor = Color.FromArgb(255, 0, 0);
17+
var jumpOrb = Color.FromArgb(0, 255, 0);
1718
map = new int[bmp.Height, bmp.Width];
1819

1920

2021
for (int y = 0; y < bmp.Height; y++)
2122
{
2223
for (int x = 0; x < bmp.Width; x++)
2324
{
24-
map[y, x] = (bmp.GetPixel(x, y) == groundColor) ? 1 : (bmp.GetPixel(x, y) == spikesColor) ? 2 : 0;
25+
map[y, x] =
26+
(bmp.GetPixel(x, y) == groundColor) ? 1
27+
: (bmp.GetPixel(x, y) == spikesColor) ? 2
28+
: (bmp.GetPixel(x,y) == jumpOrb) ? 3
29+
:0;
2530
}
2631
}
2732
}

DashAI/DashAI.csproj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,31 @@
66
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
77
</PropertyGroup>
88

9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<WarningsAsErrors>NU1605</WarningsAsErrors>
11+
</PropertyGroup>
12+
913
<ItemGroup>
10-
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
1114
<PackageReference Include="SFML.Net" Version="2.5.0" />
1215
<PackageReference Include="SharpNeatLib" Version="2.4.1.5" />
16+
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
1317
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
18+
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
19+
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
20+
<PackageReference Include="System.Net.Primitives" Version="4.3.1" />
21+
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
22+
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
23+
<PackageReference Include="System.Threading" Version="4.3.0" />
1424
</ItemGroup>
1525

1626
<ItemGroup>
17-
<None Update="MapA.bmp">
27+
<None Update="MapB.bmp">
28+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29+
</None>
30+
<None Update="MapC.bmp">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
33+
<None Update="Map.bmp">
1834
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1935
</None>
2036
</ItemGroup>

DashAI/Game.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace DashAI
77
{
88
public class Game : IDisposable
99
{
10-
public IMap map = new BmpMap("MapA.bmp");
10+
public IMap map = new BmpMap(NeatConsts.MapName);
1111
public Player player;
1212
public bool hasEnded = false;
1313
public bool hasWon = false;
@@ -39,7 +39,7 @@ private void HandleJump(bool jump)
3939
switch (player.jumpPhase)
4040
{
4141
case 0:
42-
if (jump && map.map[player.position.y + 1, player.position.x] == 1)
42+
if (jump && (map.map[player.position.y + 1, player.position.x] == 1 || map.map[player.position.y, player.position.x] == 3))
4343
{
4444
player.jumpPhase = 1;
4545
player.position.y--;
@@ -99,31 +99,37 @@ private void DrawInSFML()
9999
for (int x = 0; x < map.map.GetLength(1); x++)
100100
{
101101
var rect = new RectangleShape(new Vector2f(NeatConsts.TileSize, NeatConsts.TileSize));
102-
rect.FillColor = new Color(0, 0, 0);
102+
rect.FillColor = new Color(255, 255, 255);
103103
rect.Position = new Vector2f(NeatConsts.TileSize * x, NeatConsts.TileSize * y);
104104
if (player.position.x == x && player.position.y == y)
105105
{
106-
rect.FillColor = new Color(0, 255, 0);
106+
rect.FillColor = new Color(255, 175, 0);
107107
window.Draw(rect);
108108
continue;
109109
}
110110

111111
switch (map.map[y, x])
112112
{
113113
case 0:
114-
rect.FillColor = new Color(0, 0, 0);
114+
rect.FillColor = new Color(255, 255, 255);
115115
break;
116116
case 1:
117-
rect.FillColor = new Color(255, 255, 255);
117+
rect.FillColor = new Color(0, 0, 0);
118118
break;
119119
case 2:
120120
rect.FillColor = new Color(255, 0, 0);
121121
break;
122+
case 3:
123+
rect.FillColor = new Color(0, 255, 0);
124+
break;
122125
}
123126
window.Draw(rect);
124127
}
125128
}
129+
window.DispatchEvents();
126130
window.Display();
131+
if(NeatConsts.RecordPlay)
132+
window.Capture().SaveToFile($"{NeatConsts.experimentName}/step{player.position.x}.png");
127133
}
128134
private void HandleDeath()
129135
{

DashAI/GameEvaluator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public FitnessInfo Evaluate(IBlackBox phenome)
1717
if (game.hasWon)
1818
{
1919
shouldEnd = true;
20-
fitness *= 2;
2120
}
2221
return new FitnessInfo(fitness, fitness);
2322
}

DashAI/IMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
public interface IMap
44
{
5-
public int[,] map { get;}
5+
public int[,] map { get; }
66
}
77
}

DashAI/Map.bmp

2.46 KB
Binary file not shown.

DashAI/Map1.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

DashAI/MapA - Copy.bmp

-2.87 KB
Binary file not shown.

0 commit comments

Comments
 (0)