-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
264 lines (247 loc) · 7.22 KB
/
index.html
File metadata and controls
264 lines (247 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- P5js library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<!-- Tensorflow JS -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.4/dist/tf.min.js"></script>
<!-- Bootstrap -->
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous"
/>
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"
></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"
></script>
<!-- Font Awesome -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
<!-- Imports -->
<script src="src/Environment.js"></script>
<script src="src/Pipe.js"></script>
<script src="src/Ground.js"></script>
<script src="src/Population.js"></script>
<script src="src/Bird.js"></script>
<script src="src/Brain.js"></script>
<script src="src/Neuroevolution.js"></script>
<script src="src/main.js"></script>
<!-- Custom CSS -->
<style>
#canvas_card {
margin: 50px auto;
width: 704px;
}
#about_card {
width: 80%;
min-width: 704px;
margin: auto;
margin-bottom: 50px;
}
</style>
<title>Flappy Bird AI</title>
</head>
<body>
<div class="container-fullwidth">
<!-- Header -->
<header>
<div class="navbar navbar-dark bg-dark box-shadow">
<div class="container d-flex justify-content-around">
<!-- Title -->
<p class="navbar-brand d-flex align-items-center">
<img
src="images/bird.png"
alt="Flappy Bird"
width="30px"
height="30px"
/>
<strong>Flappy Bird AI</strong>
</p>
<!-- State Buttons -->
<div>
<button
id="trained_bird_button"
class="btn btn-primary btn-lg"
>
Trained Bird
</button>
<button
id="view_training_button"
class="btn btn-secondary btn-lg"
>
View Training
</button>
</div>
</div>
</div>
</header>
<!-- Game Card -->
<div id="canvas_card" class="card">
<!-- Game -->
<div
id="canvas_container"
class="d-flex justify-content-center"
>
<!-- P5 canvas injected here -->
</div>
<div class="d-flex justify-content-end">
<div class="mt-3 mr-3">
<h6>Game Speed</h6>
<div id="speed_slider_container">
<!-- P5 game speed slider injected here -->
</div>
</div>
</div>
<!-- Description -->
<div class="card-body">
<h5 id="game_title" class="card-title">
<!-- Game title injected here -->
</h5>
<p id="game_description" class="card-text">
<!-- Game description injected here -->
</p>
<p>
See the <b><a href="#about_card">about</a></b> section
for more details.
</p>
<hr />
<!-- Game interactions -->
<p>
Press <kbd>S</kbd> to download the AI's Tensorflow model
</p>
<p>Move the slider to adjust the game speed</p>
</div>
</div>
<!-- About Card -->
<div id="about_card" class="card">
<div class="card-header">
<h5>About</h5>
</div>
<div class="card-body">
<p class="card-text">
This AI was trained using
<b>N.E.A.T</b>. This is a genetic algorithm that trains
the AI by creating generations of agents and simulating
them in a environment. Each bird has a Neural Network
that will decide to make the bird flap based on its
inputs. The birds with the best Neural Networks are
selected for the next generation and slightly mutated to
create new behavior.
</p>
<p class="card-text">
This project was made using
<a href="https://p5js.org/"><b>P5js</b></a> to render
the game and
<a href="https://www.tensorflow.org/js"
><b>TensorFlow js</b></a
>
to create the Neural Networks.
</p>
<div>
<img
src="images/p5js_logo.png"
alt="p5js logo"
width="100px"
/>
<img
src="images/tensorflow_logo.png"
alt="tensorflow logo"
width="100px"
/>
</div>
<div class="mt-4 mb-4">
<p class="card-text">
The code for this project can be found
<a
href="https://github.com/SeanFitz1997/FlappyBird_AI"
><b>Here</b>.
<i
class="fa fa-github"
style="font-size:48px;"
></i
></a>
</p>
</div>
<h6 class="card-title">Neural Network</h6>
<p class="card-text">
Each bird has a Neural network that determines whether
to flap or not. This network is a sequential model made
up of three <b>dense layers</b>. An input layer with 5
neurons, a hidden layer with 8 neurons and a output
layer with 2 neurons.
</p>
<p class="card-text">
The five inputs the bird receives are:
</p>
<ol>
<li>The Birds Y position</li>
<li>The Birds velocity</li>
<li>The Birds distance from the pipe</li>
<li>The Y position of the top pipe</li>
<li>The Y position of the bottom pipe</li>
</ol>
<p class="card-text">
The output layer has a <b>softmax activation</b> and
will return two values that will add up to one. The bird
will flap if the first value is greater than the second
and will not if the opposite is true.
</p>
<div class="d-flex justify-content-around mt-4 mb-4">
<img src="images/inputs_diagram.png" width="45%" />
<img
src="images/neural_network_diagram.png"
width="45%"
/>
</div>
<h6 class="card-title">Training Process</h6>
<p class="card-text">
The training process for this AI involves:
</p>
<ol>
<li>
Create an initial population of <b>N</b> Birds with
neural networks containing random weights
</li>
<li>
Simulate the population in the environment until all
birds have died.
</li>
<li>
Create the next generation with the best preforming
bird's Neural networks.
</li>
<li>
Mutate a small portion of weights in each birds
Neural network <small>(E.g. 10%)</small>with random
values to create new behaviors.
</li>
<li>
Repeat steps 2 - 4 until birds can successfully
navigate the environment.
</li>
</ol>
</div>
</div>
</div>
</body>
<!-- Page Interaction -->
<script src="index.js"></script>
</html>