Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
3819ce72c0 | |||
|
aaf66fe349 | ||
|
47bdebc455 | ||
|
62f30a6522 | ||
|
30da2cf8cd | ||
|
78e9fd77bf |
11
README.md
@ -10,13 +10,20 @@ Here is a demonstration of the model after 3000 epochs (~5 minutes on an Intel(R
|
||||
|
||||
![after training](/demo/flappy-success.gif)
|
||||
|
||||
also see: [Before training](/demo/flappy-lose.gif)
|
||||
Before training:
|
||||
|
||||
![Before training](/demo/flappy-lose.gif)
|
||||
|
||||
There is also a [a web version](https://lab.mahdi.blog/flappy-bird/) available for ease of access.
|
||||
|
||||
For each frame the bird stays alive, +0.1 score is given to him. For each wall he passes, +10 score is given.
|
||||
|
||||
Demonstration of rewards for individuals and the mean reward over time (y axis is logarithmic):
|
||||
![reward chart](fig-log.jpg)
|
||||
|
||||
Try it yourself
|
||||
---------------
|
||||
You need python3 and pip for installing and running the code.
|
||||
You need python3.5 and pip for installing and running the code.
|
||||
|
||||
First, install dependencies (you might want to create a [virtualenv](https://virtualenv.pypa.io)):
|
||||
|
||||
|
39
draw_chart.py
Normal file
@ -0,0 +1,39 @@
|
||||
import os
|
||||
import plotly.plotly as py
|
||||
import plotly.graph_objs as go
|
||||
import plotly.io as pio
|
||||
|
||||
def draw_chart(scatter_x, scatter_y, line_x, line_y):
|
||||
marker_opts = dict(
|
||||
name = 'Individual Reward',
|
||||
x = scatter_x,
|
||||
y = scatter_y,
|
||||
mode = 'markers',
|
||||
marker = {
|
||||
'size': 2
|
||||
}
|
||||
)
|
||||
marker_trace = go.Scatter(**marker_opts)
|
||||
line_opts = dict(
|
||||
name = 'Mean Reward',
|
||||
x = line_x,
|
||||
y = line_y,
|
||||
mode = 'lines'
|
||||
)
|
||||
line_trace = go.Scatter(**line_opts)
|
||||
|
||||
data = [marker_trace, line_trace]
|
||||
|
||||
fig = go.Figure(data=data)
|
||||
|
||||
log_layout = go.Layout(
|
||||
yaxis = {
|
||||
'type': 'log',
|
||||
'autorange': True
|
||||
}
|
||||
)
|
||||
fig_log = go.Figure(data=data, layout=log_layout)
|
||||
|
||||
pio.orca.config.executable = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'node_modules', 'orca', 'bin', 'orca.js')
|
||||
pio.write_image(fig, 'fig.svg', width=1600, height=800)
|
||||
pio.write_image(fig_log, 'fig-log.svg', width=1600, height=800)
|
2
es.py
@ -70,4 +70,4 @@ class EvolutionStrategy():
|
||||
update = self.alpha / (self.noisep * self.sigma) * np.dot(n.T, A).T
|
||||
self.layers[i] = self.layers[i] + update
|
||||
|
||||
|
||||
return R
|
||||
|
BIN
fig-log.jpg
Normal file
After Width: | Height: | Size: 350 KiB |
713
package-lock.json
generated
Normal file
@ -0,0 +1,713 @@
|
||||
{
|
||||
"name": "flappy-es",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"ajv": {
|
||||
"version": "6.6.1",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.6.1.tgz",
|
||||
"integrity": "sha512-ZoJjft5B+EJBjUyu9C9Hc0OZyPZSSlOF+plzouTrg6UlA8f+e/n8NIgBFG/9tppJtpPWfthHakK7juJdNDODww==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fast-deep-equal": "^2.0.1",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
"json-schema-traverse": "^0.4.1",
|
||||
"uri-js": "^4.2.2"
|
||||
}
|
||||
},
|
||||
"asn1": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
|
||||
"integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"safer-buffer": "~2.1.0"
|
||||
}
|
||||
},
|
||||
"assert-plus": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
|
||||
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=",
|
||||
"dev": true
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
|
||||
"dev": true
|
||||
},
|
||||
"aws-sign2": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
|
||||
"integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=",
|
||||
"dev": true
|
||||
},
|
||||
"aws4": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
|
||||
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==",
|
||||
"dev": true
|
||||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
||||
"dev": true
|
||||
},
|
||||
"bcrypt-pbkdf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||
"integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tweetnacl": "^0.14.3"
|
||||
}
|
||||
},
|
||||
"body": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/body/-/body-5.1.0.tgz",
|
||||
"integrity": "sha1-5LoM5BCkaTYyM2dgnstOZVMSUGk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"continuable-cache": "^0.3.1",
|
||||
"error": "^7.0.0",
|
||||
"raw-body": "~1.1.0",
|
||||
"safe-json-parse": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
}
|
||||
},
|
||||
"bytes": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-1.0.0.tgz",
|
||||
"integrity": "sha1-NWnt6Lo0MV+rmcPpLLBMciDeH6g=",
|
||||
"dev": true
|
||||
},
|
||||
"caseless": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
|
||||
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=",
|
||||
"dev": true
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz",
|
||||
"integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
|
||||
"dev": true
|
||||
},
|
||||
"continuable-cache": {
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/continuable-cache/-/continuable-cache-0.3.1.tgz",
|
||||
"integrity": "sha1-vXJ6f67XfnH/OYWskzUakSczrQ8=",
|
||||
"dev": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
|
||||
"dev": true
|
||||
},
|
||||
"dashdash": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
||||
"integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"assert-plus": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
|
||||
"dev": true
|
||||
},
|
||||
"ecc-jsbn": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||
"integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"jsbn": "~0.1.0",
|
||||
"safer-buffer": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"version": "7.0.2",
|
||||
"resolved": "https://registry.npmjs.org/error/-/error-7.0.2.tgz",
|
||||
"integrity": "sha1-pfdf/02ZJhJt2sDqXcOOaJFTywI=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"string-template": "~0.2.1",
|
||||
"xtend": "~4.0.0"
|
||||
}
|
||||
},
|
||||
"extend": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
|
||||
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==",
|
||||
"dev": true
|
||||
},
|
||||
"extsprintf": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
||||
"integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=",
|
||||
"dev": true
|
||||
},
|
||||
"fast-deep-equal": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz",
|
||||
"integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=",
|
||||
"dev": true
|
||||
},
|
||||
"fast-isnumeric": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/fast-isnumeric/-/fast-isnumeric-1.1.2.tgz",
|
||||
"integrity": "sha512-D7zJht1+NZBBv4759yXn/CJFUNJpILdgdosPFN1AjqQn9TfQJqSeCZfu0SY4bwIlXuDhzkxKoQ8BOqdiXpVzvA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-string-blank": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"fast-json-stable-stringify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
|
||||
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=",
|
||||
"dev": true
|
||||
},
|
||||
"file-type": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-9.0.0.tgz",
|
||||
"integrity": "sha512-Qe/5NJrgIOlwijpq3B7BEpzPFcgzggOTagZmkXQY4LA6bsXKTUstK7Wp12lEJ/mLKTpvIZxmIuRcLYWT6ov9lw==",
|
||||
"dev": true
|
||||
},
|
||||
"forever-agent": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
|
||||
"integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=",
|
||||
"dev": true
|
||||
},
|
||||
"form-data": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
|
||||
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.6",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
||||
"dev": true
|
||||
},
|
||||
"get-stdin": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.1.tgz",
|
||||
"integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=",
|
||||
"dev": true
|
||||
},
|
||||
"getpass": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
|
||||
"integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"assert-plus": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.3",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
|
||||
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
"inherits": "2",
|
||||
"minimatch": "^3.0.4",
|
||||
"once": "^1.3.0",
|
||||
"path-is-absolute": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"har-schema": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
||||
"integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=",
|
||||
"dev": true
|
||||
},
|
||||
"har-validator": {
|
||||
"version": "5.1.3",
|
||||
"resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz",
|
||||
"integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ajv": "^6.5.5",
|
||||
"har-schema": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"http-signature": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
|
||||
"integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"assert-plus": "^1.0.0",
|
||||
"jsprim": "^1.2.2",
|
||||
"sshpk": "^1.7.0"
|
||||
}
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"once": "^1.3.0",
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
|
||||
"dev": true
|
||||
},
|
||||
"is-plain-obj": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
|
||||
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=",
|
||||
"dev": true
|
||||
},
|
||||
"is-string-blank": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-string-blank/-/is-string-blank-1.0.1.tgz",
|
||||
"integrity": "sha512-9H+ZBCVs3L9OYqv8nuUAzpcT9OTgMD1yAWrG7ihlnibdkbtB850heAmYWxHuXc4CHy4lKeK69tN+ny1K7gBIrw==",
|
||||
"dev": true
|
||||
},
|
||||
"is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=",
|
||||
"dev": true
|
||||
},
|
||||
"is-url": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz",
|
||||
"integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==",
|
||||
"dev": true
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
|
||||
"dev": true
|
||||
},
|
||||
"isstream": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
|
||||
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=",
|
||||
"dev": true
|
||||
},
|
||||
"jsbn": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
|
||||
"integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=",
|
||||
"dev": true
|
||||
},
|
||||
"json-schema": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
|
||||
"integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=",
|
||||
"dev": true
|
||||
},
|
||||
"json-schema-traverse": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
||||
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
|
||||
"dev": true
|
||||
},
|
||||
"json-stringify-safe": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
|
||||
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=",
|
||||
"dev": true
|
||||
},
|
||||
"jsprim": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
|
||||
"integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"assert-plus": "1.0.0",
|
||||
"extsprintf": "1.3.0",
|
||||
"json-schema": "0.2.3",
|
||||
"verror": "1.10.0"
|
||||
}
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.37.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz",
|
||||
"integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg==",
|
||||
"dev": true
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.21",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz",
|
||||
"integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"mime-db": "~1.37.0"
|
||||
}
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||
"dev": true
|
||||
},
|
||||
"oauth-sign": {
|
||||
"version": "0.9.0",
|
||||
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
||||
"integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==",
|
||||
"dev": true
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"orca": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/orca/-/orca-1.1.1.tgz",
|
||||
"integrity": "sha512-5rqQJpxpNOWdk/Z0FCbK9xEOfHfv120+xxW0niGFBk7FrmVlE8/D1tYYRCAZrRKIkgWxNOWzVUpySzvmM2SGqw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"body": "^5.1.0",
|
||||
"fast-isnumeric": "^1.1.1",
|
||||
"file-type": "^9.0.0",
|
||||
"get-stdin": "^5.0.1",
|
||||
"glob": "^7.1.2",
|
||||
"is-plain-obj": "^1.1.0",
|
||||
"is-url": "^1.2.4",
|
||||
"minimist": "^1.2.0",
|
||||
"read-chunk": "^2.1.0",
|
||||
"request": "^2.88.0",
|
||||
"run-parallel": "^1.1.9",
|
||||
"run-parallel-limit": "^1.0.5",
|
||||
"run-series": "^1.1.8",
|
||||
"semver": "^5.4.1",
|
||||
"string-to-stream": "^1.1.1",
|
||||
"uuid": "^3.3.2"
|
||||
}
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
||||
"dev": true
|
||||
},
|
||||
"performance-now": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=",
|
||||
"dev": true
|
||||
},
|
||||
"pify": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
||||
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=",
|
||||
"dev": true
|
||||
},
|
||||
"process-nextick-args": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
|
||||
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==",
|
||||
"dev": true
|
||||
},
|
||||
"psl": {
|
||||
"version": "1.1.29",
|
||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.1.29.tgz",
|
||||
"integrity": "sha512-AeUmQ0oLN02flVHXWh9sSJF7mcdFq0ppid/JkErufc3hGIV/AMa8Fo9VgDo/cT2jFdOWoFvHp90qqBH54W+gjQ==",
|
||||
"dev": true
|
||||
},
|
||||
"punycode": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
|
||||
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
|
||||
"dev": true
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.5.2",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
|
||||
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==",
|
||||
"dev": true
|
||||
},
|
||||
"raw-body": {
|
||||
"version": "1.1.7",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-1.1.7.tgz",
|
||||
"integrity": "sha1-HQJ8K/oRasxmI7yo8AAWVyqH1CU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bytes": "1",
|
||||
"string_decoder": "0.10"
|
||||
}
|
||||
},
|
||||
"read-chunk": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/read-chunk/-/read-chunk-2.1.0.tgz",
|
||||
"integrity": "sha1-agTAkoAF7Z1C4aasVgDhnLx/9lU=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"pify": "^3.0.0",
|
||||
"safe-buffer": "^5.1.1"
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.3.6",
|
||||
"resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
|
||||
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"string_decoder": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"request": {
|
||||
"version": "2.88.0",
|
||||
"resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz",
|
||||
"integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"aws-sign2": "~0.7.0",
|
||||
"aws4": "^1.8.0",
|
||||
"caseless": "~0.12.0",
|
||||
"combined-stream": "~1.0.6",
|
||||
"extend": "~3.0.2",
|
||||
"forever-agent": "~0.6.1",
|
||||
"form-data": "~2.3.2",
|
||||
"har-validator": "~5.1.0",
|
||||
"http-signature": "~1.2.0",
|
||||
"is-typedarray": "~1.0.0",
|
||||
"isstream": "~0.1.2",
|
||||
"json-stringify-safe": "~5.0.1",
|
||||
"mime-types": "~2.1.19",
|
||||
"oauth-sign": "~0.9.0",
|
||||
"performance-now": "^2.1.0",
|
||||
"qs": "~6.5.2",
|
||||
"safe-buffer": "^5.1.2",
|
||||
"tough-cookie": "~2.4.3",
|
||||
"tunnel-agent": "^0.6.0",
|
||||
"uuid": "^3.3.2"
|
||||
}
|
||||
},
|
||||
"run-parallel": {
|
||||
"version": "1.1.9",
|
||||
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz",
|
||||
"integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==",
|
||||
"dev": true
|
||||
},
|
||||
"run-parallel-limit": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/run-parallel-limit/-/run-parallel-limit-1.0.5.tgz",
|
||||
"integrity": "sha512-NsY+oDngvrvMxKB3G8ijBzIema6aYbQMD2bHOamvN52BysbIGTnEY2xsNyfrcr9GhY995/t/0nQN3R3oZvaDlg==",
|
||||
"dev": true
|
||||
},
|
||||
"run-series": {
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/run-series/-/run-series-1.1.8.tgz",
|
||||
"integrity": "sha512-+GztYEPRpIsQoCSraWHDBs9WVy4eVME16zhOtDB4H9J4xN0XRhknnmLOl+4gRgZtu8dpp9N/utSPjKH/xmDzXg==",
|
||||
"dev": true
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"dev": true
|
||||
},
|
||||
"safe-json-parse": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-json-parse/-/safe-json-parse-1.0.1.tgz",
|
||||
"integrity": "sha1-PnZyPjjf3aE8mx0poeB//uSzC1c=",
|
||||
"dev": true
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
||||
"dev": true
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.6.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
|
||||
"integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==",
|
||||
"dev": true
|
||||
},
|
||||
"sshpk": {
|
||||
"version": "1.15.2",
|
||||
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.15.2.tgz",
|
||||
"integrity": "sha512-Ra/OXQtuh0/enyl4ETZAfTaeksa6BXks5ZcjpSUNrjBr0DvrJKX+1fsKDPpT9TBXgHAFsa4510aNVgI8g/+SzA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"asn1": "~0.2.3",
|
||||
"assert-plus": "^1.0.0",
|
||||
"bcrypt-pbkdf": "^1.0.0",
|
||||
"dashdash": "^1.12.0",
|
||||
"ecc-jsbn": "~0.1.1",
|
||||
"getpass": "^0.1.1",
|
||||
"jsbn": "~0.1.0",
|
||||
"safer-buffer": "^2.0.2",
|
||||
"tweetnacl": "~0.14.0"
|
||||
}
|
||||
},
|
||||
"string-template": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/string-template/-/string-template-0.2.1.tgz",
|
||||
"integrity": "sha1-QpMuWYo1LQH8IuwzZ9nYTuxsmt0=",
|
||||
"dev": true
|
||||
},
|
||||
"string-to-stream": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string-to-stream/-/string-to-stream-1.1.1.tgz",
|
||||
"integrity": "sha512-QySF2+3Rwq0SdO3s7BAp4x+c3qsClpPQ6abAmb0DGViiSBAkT5kL6JT2iyzEVP+T1SmzHrQD1TwlP9QAHCc+Sw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"inherits": "^2.0.1",
|
||||
"readable-stream": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
|
||||
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
|
||||
"dev": true
|
||||
},
|
||||
"tough-cookie": {
|
||||
"version": "2.4.3",
|
||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz",
|
||||
"integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"psl": "^1.1.24",
|
||||
"punycode": "^1.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"punycode": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
|
||||
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"tunnel-agent": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
|
||||
"integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"tweetnacl": {
|
||||
"version": "0.14.5",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
||||
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
|
||||
"dev": true
|
||||
},
|
||||
"uri-js": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz",
|
||||
"integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
|
||||
"dev": true
|
||||
},
|
||||
"uuid": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
|
||||
"integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==",
|
||||
"dev": true
|
||||
},
|
||||
"verror": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
|
||||
"integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"assert-plus": "^1.0.0",
|
||||
"core-util-is": "1.0.2",
|
||||
"extsprintf": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"dev": true
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
|
||||
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
22
package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "flappy-es",
|
||||
"version": "1.0.0",
|
||||
"description": "Playing Flappy Bird using Evolution Strategies ==============================================",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mdibaiee/flappy-es.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mdibaiee/flappy-es/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mdibaiee/flappy-es#readme",
|
||||
"devDependencies": {
|
||||
"orca": "^1.1.1"
|
||||
}
|
||||
}
|
33
requirements
@ -1,31 +1,4 @@
|
||||
blinker==1.3
|
||||
chardet==2.3.0
|
||||
cloud-init==0.7.9
|
||||
command-not-found==0.3
|
||||
configobj==5.0.6
|
||||
cryptography==1.2.3
|
||||
idna==2.0
|
||||
Jinja2==2.8
|
||||
jsonpatch==1.10
|
||||
jsonpointer==1.9
|
||||
language-selector==0.1
|
||||
MarkupSafe==0.23
|
||||
numpy==1.12.1
|
||||
oauthlib==1.0.3
|
||||
prettytable==0.7.2
|
||||
pyasn1==0.1.9
|
||||
pycurl==7.43.0
|
||||
pygobject==3.20.0
|
||||
PyJWT==1.3.0
|
||||
pyserial==3.0.1
|
||||
python-apt==1.1.0b1
|
||||
python-debian==0.1.27
|
||||
python-systemd==231
|
||||
PyYAML==3.11
|
||||
requests==2.9.1
|
||||
six==1.10.0
|
||||
ssh-import-id==5.5
|
||||
ufw==0.35
|
||||
unattended-upgrades==0.1
|
||||
urllib3==1.13.1
|
||||
virtualenv==15.0.1
|
||||
plotly==3.4.0
|
||||
psutil==5.4.6
|
||||
PyGObject==3.30.4
|
||||
|
28
train.py
@ -7,6 +7,7 @@ from gi.repository import Gtk, GLib, Gdk
|
||||
from datetime import datetime
|
||||
from os import path
|
||||
import os
|
||||
from draw_chart import draw_chart
|
||||
|
||||
es = EvolutionStrategy(fn=play, noisep=50, sigma=0.1, alpha=0.001, layer_sizes=[[4, 500], [500, 1]], input_size=4)
|
||||
load = path.join(path.dirname(__file__), 'load.npy')
|
||||
@ -14,13 +15,15 @@ load = path.join(path.dirname(__file__), 'load.npy')
|
||||
np.random.seed(0)
|
||||
|
||||
# if load.npy exists, load the parameters from it
|
||||
if path.exists(load):
|
||||
if path.exists(load) and not os.environ.get('SKIP_LOAD'):
|
||||
es.layers = np.load(load)
|
||||
|
||||
# show the game every n iterations
|
||||
SHOW_EVERY = 100
|
||||
SHOW_EVERY = int(os.environ.get('SHOW_EVERY', 100))
|
||||
# save the parameters every n iterations
|
||||
SAVE_EVERY = 100
|
||||
SAVE_EVERY = int(os.environ.get('SAVE_EVERY', 100))
|
||||
# number of steps
|
||||
STEPS = int(os.environ.get('STEPS', 10000))
|
||||
|
||||
# an id for saving the parameters in a folder
|
||||
run_id = str(datetime.now())
|
||||
@ -45,9 +48,22 @@ def timeout_kill(win, game):
|
||||
|
||||
return True
|
||||
|
||||
for i in range(10000):
|
||||
reward_scatter_x = []
|
||||
reward_scatter_y = []
|
||||
|
||||
reward_line_x = list(range(STEPS))
|
||||
reward_line_y = []
|
||||
|
||||
for i in range(STEPS):
|
||||
print("{}: ".format(i), end='')
|
||||
es.train()
|
||||
rewards = es.train()
|
||||
m = np.mean(rewards)
|
||||
|
||||
reward_line_y.append(m)
|
||||
|
||||
for r in rewards:
|
||||
reward_scatter_x.append(i)
|
||||
reward_scatter_y.append(r)
|
||||
|
||||
if SHOW_EVERY and i % SHOW_EVERY == 0:
|
||||
play(es.forward, step=step)
|
||||
@ -60,4 +76,4 @@ for i in range(10000):
|
||||
if i % SAVE_EVERY == 0:
|
||||
p = path.join(path.dirname(__file__), 'saves', run_id, 'save-{}'.format(i))
|
||||
np.save(p, es.layers)
|
||||
|
||||
draw_chart(reward_scatter_x, reward_scatter_y, reward_line_x, reward_line_y)
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit c5bffc45e7baeced4b9a660325c624c81e11dbe7
|
@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "web",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"compression": "^1.6.2",
|
||||
"express": "^4.15.2",
|
||||
"socket.io": "^1.7.3"
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
var express = require('express'),
|
||||
app = express(),
|
||||
server = require('http').Server(app),
|
||||
io = require('socket.io')(server)
|
||||
exec = require('child_process').exec
|
||||
compression = require('compression')
|
||||
path = require('path');
|
||||
|
||||
|
||||
server.listen(8088);
|
||||
app.use(express.static(__dirname + '/static'))
|
||||
app.use(compression())
|
||||
app.use('/assets/', express.static(__dirname + '/../assets/'))
|
||||
|
||||
|
||||
var record = path.resolve(__dirname, '../record.py');
|
||||
app.get('/play', function(request, response) {
|
||||
var child = exec('python3 ' + record, { maxBuffer: 1024 * 5000 }, function(err, out, stderr) {
|
||||
if (err || stderr) {
|
||||
console.log(err || stderr)
|
||||
response.send(err || stderr);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
child.stdout.pipe(response);
|
||||
});
|
||||
|
@ -1,176 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
@ -1,51 +0,0 @@
|
||||
Floppy Bird
|
||||
=========
|
||||
Initially, I wanted to try recreating Flappy Bird in HTML5, using a canvas and recycling the assets from the old game.
|
||||
|
||||
What I did instead is something way more primitive. This project uses nothing but good ol' div's for all the objects and graphics, will scale perfectly on almost any screen (mobile and desktop), is terribly unoptimized, laggy, and isn't nearly as fast as it would've been if I had just used a canvas instead. But here it is!
|
||||
|
||||
Live App
|
||||
------------
|
||||
Check out a live preview of it over here:
|
||||
http://nebez.github.io/floppybird/
|
||||
|
||||
Cool Stuff
|
||||
---------
|
||||
*Some cool things other people have done with the code. Let me know about your projects and I'll link it here*
|
||||
https://wanderingstan.github.io/handybird/ - **[@wanderinstan](https://github.com/wanderingstan)** - Real hand gestures to play Flappy Bird, using doppler effect and microphone.
|
||||
http://www.hhcc.com/404 - **[Hill Holiday](http://www.hhcc.com/)** using it for their 404
|
||||
http://heart-work.se/duvchi - Floppy bird, modified, and used as a promotional campaign for an album release
|
||||
https://www.progressivewebflap.com/ - **[@jsonthor](https://twitter.com/jsonthor)** turned Floppy Bird into a PWA!
|
||||
https://github.com/rukmal/FlappyLeapBird - **[Rukmal](http://rukmal.me/)** integrated LeapMotion Controller functionality! Check out his website, he's done some cool stuff.
|
||||
http://chrisbeaumont.github.io/floppybird/ - **[@chrisbeaumont](https://github.com/chrisbeaumont)** made an awesome auto-pilot, check it out
|
||||
http://www.lobe.io/flappy-math-saga/- **[@tikwid](https://github.com/tikwid)** made a really cool version designed to teach you times tables. really cool.
|
||||
http://dota2.cyborgmatt.com/flappydota/ - flappy dota, this one is really cool.
|
||||
http://tippy.gochiusa.net/ - Japanese anime inspired floppybird.
|
||||
http://emdigital.ru/wiki — floppybird on **[EyeMedia Instagram Marketing Agency](http://emdigital.ru/)** website.
|
||||
|
||||
Credits
|
||||
------
|
||||
**[@aregowe](https://github.com/aregowe)** for optimizing all the assets
|
||||
|
||||
Notice
|
||||
=====
|
||||
The assets powering the visual element of the game have all been extracted directly from the Flappy Bird android game. I have only done the coding, not designed the visual elements.
|
||||
I do not own the assets, nor do I have explicit permission to use them from their creator. They are the work and copyright of original creator Dong Nguyen and .GEARS games (http://www.dotgears.com/).
|
||||
I took this Tweet (https://twitter.com/dongatory/status/431060041009856512 / http://i.imgur.com/AcyWyqf.png) by Dong Nguyen, the creator of the game, as an open invitation to reuse the game concept and assets in an open source project. There is no ill intention to steal the game, or claim it as my own. This is merely a recreation for fun.
|
||||
If the copyright holder would like for the assets to be removed, let me know!
|
||||
|
||||
|
||||
License
|
||||
=====
|
||||
Copyright 2014 Nebez Briefkani
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
Before Width: | Height: | Size: 282 B |
Before Width: | Height: | Size: 110 B |
Before Width: | Height: | Size: 121 B |
Before Width: | Height: | Size: 130 B |
Before Width: | Height: | Size: 126 B |
Before Width: | Height: | Size: 125 B |
Before Width: | Height: | Size: 133 B |
Before Width: | Height: | Size: 126 B |
Before Width: | Height: | Size: 126 B |
Before Width: | Height: | Size: 131 B |
Before Width: | Height: | Size: 125 B |
Before Width: | Height: | Size: 125 B |
Before Width: | Height: | Size: 99 B |
Before Width: | Height: | Size: 110 B |
Before Width: | Height: | Size: 96 B |
Before Width: | Height: | Size: 90 B |
Before Width: | Height: | Size: 112 B |
Before Width: | Height: | Size: 94 B |
Before Width: | Height: | Size: 92 B |
Before Width: | Height: | Size: 94 B |
Before Width: | Height: | Size: 101 B |
Before Width: | Height: | Size: 100 B |
Before Width: | Height: | Size: 278 B |
Before Width: | Height: | Size: 354 B |
Before Width: | Height: | Size: 284 B |
Before Width: | Height: | Size: 337 B |
Before Width: | Height: | Size: 340 B |
Before Width: | Height: | Size: 456 B |
Before Width: | Height: | Size: 421 B |
Before Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 596 B |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 3.9 KiB |
@ -1,399 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Nebez Briefkani
|
||||
floppybird - main.css
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
@-webkit-keyframes animLand {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -335px 0px; }
|
||||
}
|
||||
@-moz-keyframes animLand {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -335px 0px; }
|
||||
}
|
||||
@-o-keyframes animLand {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -335px 0px; }
|
||||
}
|
||||
@keyframes animLand {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -335px 0px; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes animSky {
|
||||
0% { background-position: 0px 100%; }
|
||||
100% { background-position: -275px 100%; }
|
||||
}
|
||||
@-moz-keyframes animSky {
|
||||
0% { background-position: 0px 100%; }
|
||||
100% { background-position: -275px 100%; }
|
||||
}
|
||||
@-o-keyframes animSky {
|
||||
0% { background-position: 0px 100%; }
|
||||
100% { background-position: -275px 100%; }
|
||||
}
|
||||
@keyframes animSky {
|
||||
0% { background-position: 0px 100%; }
|
||||
100% { background-position: -275px 100%; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes animBird {
|
||||
from { background-position: 0px 0px; }
|
||||
to { background-position: 0px -96px; }
|
||||
}
|
||||
@-moz-keyframes animBird {
|
||||
from { background-position: 0px 0px; }
|
||||
to { background-position: 0px -96px; }
|
||||
}
|
||||
@-o-keyframes animBird {
|
||||
from { background-position: 0px 0px; }
|
||||
to { background-position: 0px -96px; }
|
||||
}
|
||||
@keyframes animBird {
|
||||
from { background-position: 0px 0px; }
|
||||
to { background-position: 0px -96px; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes animPipe {
|
||||
0% { left: 900px; }
|
||||
100% { left: -100px; }
|
||||
}
|
||||
@-moz-keyframes animPipe {
|
||||
0% { left: 900px; }
|
||||
100% { left: -100px; }
|
||||
}
|
||||
@-o-keyframes animPipe {
|
||||
0% { left: 900px; }
|
||||
100% { left: -100px; }
|
||||
}
|
||||
@keyframes animPipe {
|
||||
0% { left: 900px; }
|
||||
100% { left: -100px; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes animCeiling {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -63px 0px; }
|
||||
}
|
||||
@-moz-keyframes animCeiling {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -63px 0px; }
|
||||
}
|
||||
@-o-keyframes animCeiling {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -63px 0px; }
|
||||
}
|
||||
@keyframes animCeiling {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -63px 0px; }
|
||||
}
|
||||
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
/* border box */
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
/* gpu acceleration */
|
||||
-webkit-transition: translate3d(0,0,0);
|
||||
/* select disable */
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
-khtml-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#gamecontainer
|
||||
{
|
||||
position: relative;
|
||||
width: 300px;
|
||||
height: 250px;
|
||||
|
||||
margin: 3rem auto;
|
||||
}
|
||||
|
||||
/*
|
||||
Screen - Game
|
||||
*/
|
||||
#gamescreen
|
||||
{
|
||||
position: absolute;
|
||||
width: 300px;
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
#sky
|
||||
{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 300px;
|
||||
height: 200px;
|
||||
background-image: url('../assets/sky.png');
|
||||
background-repeat: repeat-x;
|
||||
background-position: 0px 100%;
|
||||
background-color: #4ec0ca;
|
||||
|
||||
-webkit-animation: animSky 7s linear infinite;
|
||||
animation: animSky 7s linear infinite;
|
||||
}
|
||||
|
||||
#flyarea
|
||||
{
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
height: 200px;
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
#ceiling
|
||||
{
|
||||
position: absolute;
|
||||
top: -16px;
|
||||
height: 16px;
|
||||
width: 300px;
|
||||
background-image: url('../assets/ceiling.png');
|
||||
background-repeat: repeat-x;
|
||||
|
||||
-webkit-animation: animCeiling 481ms linear infinite;
|
||||
animation: animCeiling 481ms linear infinite;
|
||||
}
|
||||
|
||||
#land
|
||||
{
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 20%;
|
||||
background-image: url('../assets/land.png');
|
||||
background-repeat: repeat-x;
|
||||
background-position: 0px 0px;
|
||||
background-color: #ded895;
|
||||
|
||||
-webkit-animation: animLand 2516ms linear infinite;
|
||||
animation: animLand 2516ms linear infinite;
|
||||
}
|
||||
|
||||
#bigscore
|
||||
{
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 10px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#bigscore img
|
||||
{
|
||||
display: inline-block;
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
#splash
|
||||
{
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
top: 75px;
|
||||
left: 65px;
|
||||
width: 188px;
|
||||
height: 170px;
|
||||
background-image: url('../assets/splash.png');
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
#scoreboard
|
||||
{
|
||||
position: absolute;
|
||||
display: none;
|
||||
opacity: 0;
|
||||
top: 64px;
|
||||
left: 43px;
|
||||
width: 236px;
|
||||
height: 280px;
|
||||
background-image: url('../assets/scoreboard.png');
|
||||
background-repeat: no-repeat;
|
||||
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
#medal
|
||||
{
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
top: 114px;
|
||||
left: 32px;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
}
|
||||
|
||||
#currentscore
|
||||
{
|
||||
position: absolute;
|
||||
top: 105px;
|
||||
left: 107px;
|
||||
width: 104px;
|
||||
height: 14px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#currentscore img
|
||||
{
|
||||
padding-left: 2px;
|
||||
}
|
||||
|
||||
#highscore
|
||||
{
|
||||
position: absolute;
|
||||
top: 147px;
|
||||
left: 107px;
|
||||
width: 104px;
|
||||
height: 14px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#highscore img
|
||||
{
|
||||
padding-left: 2px;
|
||||
}
|
||||
|
||||
#replay
|
||||
{
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
top: 205px;
|
||||
left: 61px;
|
||||
height: 115px;
|
||||
width: 70px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.boundingbox
|
||||
{
|
||||
position: absolute;
|
||||
display: none;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 1px solid red;
|
||||
}
|
||||
|
||||
#player
|
||||
{
|
||||
left: 60px;
|
||||
top: 200px;
|
||||
}
|
||||
|
||||
.bird
|
||||
{
|
||||
position: absolute;
|
||||
width: 34px;
|
||||
height: 24px;
|
||||
background-image: url('../assets/bird.png');
|
||||
|
||||
-webkit-animation: animBird 300ms steps(4) infinite;
|
||||
animation: animBird 300ms steps(4) infinite;
|
||||
}
|
||||
|
||||
.pipe
|
||||
{
|
||||
position: absolute;
|
||||
left: -100px;
|
||||
width: 52px;
|
||||
height: 100%;
|
||||
z-index: 10;
|
||||
text-align: left;
|
||||
|
||||
/*-webkit-animation: animPipe 7500ms linear;*/
|
||||
/*animation: animPipe 7500ms linear;*/
|
||||
}
|
||||
|
||||
.pipe_upper
|
||||
{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 52px;
|
||||
background-image: url('../assets/pipe.png');
|
||||
background-repeat: repeat-y;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.pipe_upper:after
|
||||
{
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 52px;
|
||||
height: 26px;
|
||||
background-image: url('../assets/pipe-down.png');
|
||||
}
|
||||
|
||||
.pipe_lower
|
||||
{
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 52px;
|
||||
background-image: url('../assets/pipe.png');
|
||||
background-repeat: repeat-y;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.pipe_lower:after
|
||||
{
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 52px;
|
||||
height: 26px;
|
||||
background-image: url('../assets/pipe-up.png');
|
||||
}
|
||||
|
||||
#footer
|
||||
{
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
bottom: 3px;
|
||||
left: 3px;
|
||||
}
|
||||
|
||||
#footer a,
|
||||
#footer a:link,
|
||||
#footer a:visited,
|
||||
#footer a:hover,
|
||||
#footer a:active
|
||||
{
|
||||
padding: 2px;
|
||||
text-decoration: none;
|
||||
color: #fff;
|
||||
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.links {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: middle;
|
||||
}
|
||||
|
||||
.github {
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.github .fa {
|
||||
font-size: 20px;
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
/* html5doctor.com Reset v1.6.1 - http://cssreset.com */
|
||||
html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,abbr,address,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,var,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}nav ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}a{margin:0;padding:0;font-size:100%;vertical-align:baseline;background:transparent}ins{background-color:#ff9;color:#000;text-decoration:none}mark{background-color:#ff9;color:#000;font-style:italic;font-weight:bold}del{text-decoration:line-through}abbr[title],dfn[title]{border-bottom:1px dotted;cursor:help}table{border-collapse:collapse;border-spacing:0}hr{display:block;height:1px;border:0;border-top:1px solid #ccc;margin:1em 0;padding:0}input,select{vertical-align:middle}
|
4
web/static/font-awesome.min.css
vendored
@ -1,46 +0,0 @@
|
||||
var canvas = document.getElementById('canvas'),
|
||||
c = canvas.getContext('2d'),
|
||||
birdie = document.getElementById('birdie'),
|
||||
socket = io();
|
||||
|
||||
var JUMP_SPEED = 7
|
||||
var bird = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
}
|
||||
|
||||
WALL_WIDTH = 30
|
||||
GATE_HEIGHT = 60
|
||||
var wall = {
|
||||
x: 0,
|
||||
gate: {
|
||||
y: 0,
|
||||
height: GATE_HEIGHT
|
||||
},
|
||||
width: WALL_WIDTH,
|
||||
}
|
||||
|
||||
var game = {
|
||||
width: 250,
|
||||
height: 200,
|
||||
lost: false,
|
||||
score: 0,
|
||||
}
|
||||
|
||||
socket.on('game', function() {
|
||||
|
||||
});
|
||||
|
||||
(function loop() {
|
||||
requestAnimationFrame(function() {
|
||||
|
||||
loop();
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
function draw() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.draw
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
<html class="fa-events-icons-ready"><head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>Playing Flappy Bird using Evolution Strategies</title>
|
||||
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<meta name="author" content="Nebez Briefkani" />
|
||||
<meta name="description" content="play floppy bird. a remake of popular game flappy bird using just html/css/js" />
|
||||
<meta name="keywords" content="flappybird,flappy,bird,floppybird,floppy,html,html5,css,css3,js,javascript,jquery,github,nebez,briefkani,nebezb,open,source,opensource" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
||||
|
||||
<!-- Open Graph tags -->
|
||||
<meta property="og:title" content="Floppy Bird" />
|
||||
<meta property="og:description" content="play floppy bird. a remake of popular game flappy bird using just html/css/js" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:image" content="http://nebez.github.io/floppybird/assets/thumb.png" />
|
||||
<meta property="og:url" content="http://nebez.github.io/floppybird/" />
|
||||
<meta property="og:site_name" content="Floppy Bird" />
|
||||
|
||||
<!-- Style sheets -->
|
||||
<link href="css/reset.css" rel="stylesheet">
|
||||
<link href="css/main.css" rel="stylesheet">
|
||||
<link href="style.css" rel="stylesheet">
|
||||
<script src="main_files/befea5cf35.js"></script><link href="main_files/befea5cf35.css" media="all" rel="stylesheet">
|
||||
<script src="main_files/socket.js"></script>
|
||||
</head>
|
||||
|
||||
<body><header>
|
||||
<h1>Playing Flappy Bird using Evolution Strategies</h1>
|
||||
</header>
|
||||
|
||||
<div id="gamecontainer">
|
||||
<div id="gamescreen">
|
||||
<div id="sky" class="animated">
|
||||
<div id="flyarea">
|
||||
<div id="ceiling" class="animated"></div>
|
||||
<!-- This is the flying and pipe area container -->
|
||||
<div id="player" class="bird animated"></div>
|
||||
|
||||
<div id="bigscore"></div>
|
||||
|
||||
<div id="splash"></div>
|
||||
|
||||
<div id="scoreboard">
|
||||
<div id="medal"></div>
|
||||
<div id="currentscore"></div>
|
||||
<div id="highscore"></div>
|
||||
<div id="replay"><img src="assets/replay.png" alt="replay"></div>
|
||||
</div>
|
||||
|
||||
<!-- Pipes go here! -->
|
||||
</div>
|
||||
</div>
|
||||
<div id="land" class="animated"><div id="debug"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="boundingbox" id="playerbox"></div>
|
||||
<div class="boundingbox" id="pipebox"></div>
|
||||
|
||||
<div class='overlay' id='loading'>
|
||||
Fetching a new game from the server...
|
||||
</div>
|
||||
|
||||
<div class='controls'>
|
||||
<a id='new' class='btn' title='Fetch a new game'><i class='fa fa-refresh'></i></a>
|
||||
<a id='faster' class='btn' title='Faster'><i class='fa fa-plus-square'></i></a>
|
||||
<a id='slower' class='btn' title='Slower'><i class='fa fa-minus-square'></i></a>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<p>Inspired by <a href="https://blog.openai.com/evolution-strategies/">Evolution Strategies as a Scalable Alternative to Reinforcement Learning</a> by <a href="https://openai.com/">OpenAI</a></p><a href="https://openai.com/">
|
||||
|
||||
<a class='small' href="http://github.com/nebez/floppybird/">HTML5 game by nebez/floppybird</a>
|
||||
|
||||
</a><div class="links"><a href="https://openai.com/">
|
||||
</a><a class="github" href="https://github.com/mdibaiee/flappy-es" alt="GitHub">GitHub <i class="fa fa-github"></i></a>
|
||||
<a class="aylien" href="https://aylien.com/"><img src="main_files/aylien.png" alt="Aylien" width="32"></a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<div style='display: none;'>
|
||||
<img src='assets/font_big_0.png'>
|
||||
<img src='assets/font_big_1.png'>
|
||||
<img src='assets/font_big_2.png'>
|
||||
<img src='assets/font_big_3.png'>
|
||||
<img src='assets/font_big_4.png'>
|
||||
<img src='assets/font_big_5.png'>
|
||||
<img src='assets/font_big_6.png'>
|
||||
<img src='assets/font_big_7.png'>
|
||||
<img src='assets/font_big_8.png'>
|
||||
<img src='assets/font_big_9.png'>
|
||||
</div>
|
||||
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="js/jquery.transit.min.js"></script>
|
||||
<script src="js/buzz.min.js"></script>
|
||||
<script src="js/main.js"></script>
|
11
web/static/js/buzz.min.js
vendored
6
web/static/js/jquery.min.js
vendored
9
web/static/js/jquery.transit.min.js
vendored
@ -1,584 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Nebez Briefkani
|
||||
floppybird - main.js
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
var debugmode = false;
|
||||
|
||||
var states = Object.freeze({
|
||||
SplashScreen: 0,
|
||||
GameScreen: 1,
|
||||
ScoreScreen: 2
|
||||
});
|
||||
|
||||
var currentstate;
|
||||
|
||||
var gravity = 0.25;
|
||||
var velocity = 0;
|
||||
var position = 180;
|
||||
var rotation = 0;
|
||||
var jump = -4.6;
|
||||
var flyArea = $("#flyarea").height();
|
||||
|
||||
var score = 0;
|
||||
var highscore = 0;
|
||||
|
||||
var pipeheight = 90;
|
||||
var pipewidth = 52;
|
||||
var pipes = new Array();
|
||||
|
||||
var replayclickable = false;
|
||||
|
||||
//sounds
|
||||
var volume = 30;
|
||||
var soundJump = new buzz.sound("assets/sounds/sfx_wing.ogg");
|
||||
var soundScore = new buzz.sound("assets/sounds/sfx_point.ogg");
|
||||
var soundHit = new buzz.sound("assets/sounds/sfx_hit.ogg");
|
||||
var soundDie = new buzz.sound("assets/sounds/sfx_die.ogg");
|
||||
var soundSwoosh = new buzz.sound("assets/sounds/sfx_swooshing.ogg");
|
||||
buzz.all().setVolume(volume);
|
||||
|
||||
//loops
|
||||
var loopGameloop;
|
||||
var loopPipeloop;
|
||||
|
||||
$(document).ready(function() {
|
||||
if(window.location.search == "?debug")
|
||||
debugmode = true;
|
||||
if(window.location.search == "?easy")
|
||||
pipeheight = 200;
|
||||
|
||||
//get the highscore
|
||||
var savedscore = getCookie("highscore");
|
||||
if(savedscore != "")
|
||||
highscore = parseInt(savedscore);
|
||||
|
||||
//start with the splash screen
|
||||
//showSplash();
|
||||
});
|
||||
|
||||
function getCookie(cname)
|
||||
{
|
||||
var name = cname + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0; i<ca.length; i++)
|
||||
{
|
||||
var c = ca[i].trim();
|
||||
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function setCookie(cname,cvalue,exdays)
|
||||
{
|
||||
var d = new Date();
|
||||
d.setTime(d.getTime()+(exdays*24*60*60*1000));
|
||||
var expires = "expires="+d.toGMTString();
|
||||
document.cookie = cname + "=" + cvalue + "; " + expires;
|
||||
}
|
||||
|
||||
function showSplash()
|
||||
{
|
||||
currentstate = states.SplashScreen;
|
||||
|
||||
//set the defaults (again)
|
||||
velocity = 0;
|
||||
position = 180;
|
||||
rotation = 0;
|
||||
score = 0;
|
||||
|
||||
//update the player in preparation for the next game
|
||||
$("#player").css({ y: 0, x: 0});
|
||||
updatePlayer($("#player"));
|
||||
|
||||
soundSwoosh.stop();
|
||||
soundSwoosh.play();
|
||||
|
||||
//clear out all the pipes if there are any
|
||||
$(".pipe").remove();
|
||||
pipes = new Array();
|
||||
|
||||
//make everything animated again
|
||||
$(".animated").css('animation-play-state', 'running');
|
||||
$(".animated").css('-webkit-animation-play-state', 'running');
|
||||
|
||||
//fade in the splash
|
||||
$("#splash").transition({ opacity: 1 }, 2000, 'ease');
|
||||
}
|
||||
|
||||
function startGame()
|
||||
{
|
||||
currentstate = states.GameScreen;
|
||||
|
||||
//fade out the splash
|
||||
$("#splash").stop();
|
||||
$("#splash").transition({ opacity: 0 }, 500, 'ease');
|
||||
|
||||
//update the big score
|
||||
setBigScore();
|
||||
|
||||
//debug mode?
|
||||
if(debugmode)
|
||||
{
|
||||
//show the bounding boxes
|
||||
$(".boundingbox").show();
|
||||
}
|
||||
|
||||
//start up our loops
|
||||
var updaterate = 1000.0 / 60.0 ; //60 times a second
|
||||
loopGameloop = setInterval(gameloop, updaterate);
|
||||
loopPipeloop = setInterval(updatePipes, 1400);
|
||||
|
||||
//jump from the start!
|
||||
playerJump();
|
||||
}
|
||||
|
||||
function updatePlayer(player)
|
||||
{
|
||||
//rotation
|
||||
rotation = Math.min((velocity / 10) * 90, 90);
|
||||
|
||||
//apply rotation and position
|
||||
$(player).css({ rotate: rotation, top: position });
|
||||
}
|
||||
|
||||
function gameloop() {
|
||||
var player = $("#player");
|
||||
|
||||
//update the player speed/position
|
||||
velocity += gravity;
|
||||
position += velocity;
|
||||
|
||||
//update the player
|
||||
updatePlayer(player);
|
||||
|
||||
//create the bounding box
|
||||
var box = document.getElementById('player').getBoundingClientRect();
|
||||
var origwidth = 34.0;
|
||||
var origheight = 24.0;
|
||||
|
||||
var boxwidth = origwidth - (Math.sin(Math.abs(rotation) / 90) * 8);
|
||||
var boxheight = (origheight + box.height) / 2;
|
||||
var boxleft = ((box.width - boxwidth) / 2) + box.left;
|
||||
var boxtop = ((box.height - boxheight) / 2) + box.top;
|
||||
var boxright = boxleft + boxwidth;
|
||||
var boxbottom = boxtop + boxheight;
|
||||
|
||||
//if we're in debug mode, draw the bounding box
|
||||
if(debugmode)
|
||||
{
|
||||
var boundingbox = $("#playerbox");
|
||||
boundingbox.css('left', boxleft);
|
||||
boundingbox.css('top', boxtop);
|
||||
boundingbox.css('height', boxheight);
|
||||
boundingbox.css('width', boxwidth);
|
||||
}
|
||||
|
||||
//did we hit the ground?
|
||||
if(box.bottom >= $("#land").offset().top)
|
||||
{
|
||||
playerDead();
|
||||
return;
|
||||
}
|
||||
|
||||
//have they tried to escape through the ceiling? :o
|
||||
var ceiling = $("#ceiling");
|
||||
if(boxtop <= (ceiling.offset().top + ceiling.height()))
|
||||
position = 0;
|
||||
|
||||
//we can't go any further without a pipe
|
||||
if(pipes[0] == null)
|
||||
return;
|
||||
|
||||
//determine the bounding box of the next pipes inner area
|
||||
var nextpipe = pipes[0];
|
||||
var nextpipeupper = nextpipe.children(".pipe_upper");
|
||||
|
||||
var pipetop = nextpipeupper.offset().top + nextpipeupper.height();
|
||||
var pipeleft = nextpipeupper.offset().left - 2; // for some reason it starts at the inner pipes offset, not the outer pipes.
|
||||
var piperight = pipeleft + pipewidth;
|
||||
var pipebottom = pipetop + pipeheight;
|
||||
|
||||
if(debugmode)
|
||||
{
|
||||
var boundingbox = $("#pipebox");
|
||||
boundingbox.css('left', pipeleft);
|
||||
boundingbox.css('top', pipetop);
|
||||
boundingbox.css('height', pipeheight);
|
||||
boundingbox.css('width', pipewidth);
|
||||
}
|
||||
|
||||
//have we gotten inside the pipe yet?
|
||||
if(boxright > pipeleft)
|
||||
{
|
||||
//we're within the pipe, have we passed between upper and lower pipes?
|
||||
if(boxtop > pipetop && boxbottom < pipebottom)
|
||||
{
|
||||
//yeah! we're within bounds
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//no! we touched the pipe
|
||||
playerDead();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//have we passed the imminent danger?
|
||||
if(boxleft > piperight)
|
||||
{
|
||||
//yes, remove it
|
||||
pipes.splice(0, 1);
|
||||
|
||||
//and score a point
|
||||
playerScore();
|
||||
}
|
||||
}
|
||||
|
||||
//Handle space bar
|
||||
$(document).keydown(function(e){
|
||||
//space bar!
|
||||
if(e.keyCode == 32)
|
||||
{
|
||||
//in ScoreScreen, hitting space should click the "replay" button. else it's just a regular spacebar hit
|
||||
if(currentstate == states.ScoreScreen)
|
||||
$("#replay").click();
|
||||
else
|
||||
screenClick();
|
||||
}
|
||||
});
|
||||
|
||||
//Handle mouse down OR touch start
|
||||
if("ontouchstart" in window)
|
||||
$(document).on("touchstart", screenClick);
|
||||
else
|
||||
$(document).on("mousedown", screenClick);
|
||||
|
||||
function screenClick()
|
||||
{
|
||||
if(currentstate == states.GameScreen)
|
||||
{
|
||||
playerJump();
|
||||
}
|
||||
else if(currentstate == states.SplashScreen)
|
||||
{
|
||||
startGame();
|
||||
}
|
||||
}
|
||||
|
||||
function playerJump()
|
||||
{
|
||||
velocity = jump;
|
||||
//play jump sound
|
||||
soundJump.stop();
|
||||
soundJump.play();
|
||||
}
|
||||
|
||||
function setBigScore(erase)
|
||||
{
|
||||
var elemscore = $("#bigscore");
|
||||
elemscore.empty();
|
||||
|
||||
if(erase)
|
||||
return;
|
||||
|
||||
var digits = score.toString().split('');
|
||||
for(var i = 0; i < digits.length; i++)
|
||||
elemscore.append("<img src='assets/font_big_" + digits[i] + ".png' alt='" + digits[i] + "'>");
|
||||
}
|
||||
|
||||
function setSmallScore()
|
||||
{
|
||||
var elemscore = $("#currentscore");
|
||||
elemscore.empty();
|
||||
|
||||
var digits = score.toString().split('');
|
||||
for(var i = 0; i < digits.length; i++)
|
||||
elemscore.append("<img src='assets/font_small_" + digits[i] + ".png' alt='" + digits[i] + "'>");
|
||||
}
|
||||
|
||||
function setHighScore()
|
||||
{
|
||||
var elemscore = $("#highscore");
|
||||
elemscore.empty();
|
||||
|
||||
var digits = highscore.toString().split('');
|
||||
for(var i = 0; i < digits.length; i++)
|
||||
elemscore.append("<img src='assets/font_small_" + digits[i] + ".png' alt='" + digits[i] + "'>");
|
||||
}
|
||||
|
||||
function setMedal()
|
||||
{
|
||||
var elemmedal = $("#medal");
|
||||
elemmedal.empty();
|
||||
|
||||
if(score < 10)
|
||||
//signal that no medal has been won
|
||||
return false;
|
||||
|
||||
if(score >= 10)
|
||||
medal = "bronze";
|
||||
if(score >= 20)
|
||||
medal = "silver";
|
||||
if(score >= 30)
|
||||
medal = "gold";
|
||||
if(score >= 40)
|
||||
medal = "platinum";
|
||||
|
||||
elemmedal.append('<img src="assets/medal_' + medal +'.png" alt="' + medal +'">');
|
||||
|
||||
//signal that a medal has been won
|
||||
return true;
|
||||
}
|
||||
|
||||
function playerDead()
|
||||
{
|
||||
//stop animating everything!
|
||||
$(".animated").css('animation-play-state', 'paused');
|
||||
$(".animated").css('-webkit-animation-play-state', 'paused');
|
||||
|
||||
//drop the bird to the floor
|
||||
var playerbottom = $("#player").position().top + $("#player").width(); //we use width because he'll be rotated 90 deg
|
||||
var floor = flyArea;
|
||||
var movey = Math.max(0, floor - playerbottom);
|
||||
$("#player").transition({ y: movey + 'px', rotate: 90}, 1000, 'easeInOutCubic');
|
||||
|
||||
//it's time to change states. as of now we're considered ScoreScreen to disable left click/flying
|
||||
currentstate = states.ScoreScreen;
|
||||
|
||||
//destroy our gameloops
|
||||
clearInterval(loopGameloop);
|
||||
clearInterval(loopPipeloop);
|
||||
loopGameloop = null;
|
||||
loopPipeloop = null;
|
||||
|
||||
//mobile browsers don't support buzz bindOnce event
|
||||
if(isIncompatible.any())
|
||||
{
|
||||
//skip right to showing score
|
||||
showScore();
|
||||
}
|
||||
else
|
||||
{
|
||||
//play the hit sound (then the dead sound) and then show score
|
||||
soundHit.play().bindOnce("ended", function() {
|
||||
soundDie.play().bindOnce("ended", function() {
|
||||
showScore();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function showScore()
|
||||
{
|
||||
//unhide us
|
||||
$("#scoreboard").css("display", "block");
|
||||
|
||||
//remove the big score
|
||||
setBigScore(true);
|
||||
|
||||
//have they beaten their high score?
|
||||
if(score > highscore)
|
||||
{
|
||||
//yeah!
|
||||
highscore = score;
|
||||
//save it!
|
||||
setCookie("highscore", highscore, 999);
|
||||
}
|
||||
|
||||
//update the scoreboard
|
||||
setSmallScore();
|
||||
setHighScore();
|
||||
var wonmedal = setMedal();
|
||||
|
||||
//SWOOSH!
|
||||
soundSwoosh.stop();
|
||||
soundSwoosh.play();
|
||||
|
||||
//show the scoreboard
|
||||
$("#scoreboard").css({ y: '40px', opacity: 0 }); //move it down so we can slide it up
|
||||
$("#replay").css({ y: '40px', opacity: 0 });
|
||||
$("#scoreboard").transition({ y: '0px', opacity: 1}, 600, 'ease', function() {
|
||||
//When the animation is done, animate in the replay button and SWOOSH!
|
||||
soundSwoosh.stop();
|
||||
soundSwoosh.play();
|
||||
$("#replay").transition({ y: '0px', opacity: 1}, 600, 'ease');
|
||||
|
||||
//also animate in the MEDAL! WOO!
|
||||
if(wonmedal)
|
||||
{
|
||||
$("#medal").css({ scale: 2, opacity: 0 });
|
||||
$("#medal").transition({ opacity: 1, scale: 1 }, 1200, 'ease');
|
||||
}
|
||||
});
|
||||
|
||||
//make the replay button clickable
|
||||
replayclickable = true;
|
||||
}
|
||||
|
||||
$("#replay").click(function() {
|
||||
//make sure we can only click once
|
||||
if(!replayclickable)
|
||||
return;
|
||||
else
|
||||
replayclickable = false;
|
||||
//SWOOSH!
|
||||
soundSwoosh.stop();
|
||||
soundSwoosh.play();
|
||||
|
||||
//fade out the scoreboard
|
||||
$("#scoreboard").transition({ y: '-40px', opacity: 0}, 1000, 'ease', function() {
|
||||
//when that's done, display us back to nothing
|
||||
$("#scoreboard").css("display", "none");
|
||||
|
||||
//start the game over!
|
||||
newGame();
|
||||
});
|
||||
});
|
||||
|
||||
function playerScore()
|
||||
{
|
||||
score += 1;
|
||||
//play score sound
|
||||
soundScore.stop();
|
||||
soundScore.play();
|
||||
setBigScore();
|
||||
}
|
||||
|
||||
function updatePipes()
|
||||
{
|
||||
//Do any pipes need removal?
|
||||
$(".pipe").filter(function() { return $(this).position().left <= -100; }).remove()
|
||||
|
||||
//add a new pipe (top height + bottom height + pipeheight == flyArea) and put it in our tracker
|
||||
var padding = 80;
|
||||
var constraint = flyArea - pipeheight - (padding * 2); //double padding (for top and bottom)
|
||||
var topheight = Math.floor((Math.random()*constraint) + padding); //add lower padding
|
||||
var bottomheight = (flyArea - pipeheight) - topheight;
|
||||
var newpipe = $('<div class="pipe animated"><div class="pipe_upper" style="height: ' + topheight + 'px;"></div><div class="pipe_lower" style="height: ' + bottomheight + 'px;"></div></div>');
|
||||
$("#flyarea").append(newpipe);
|
||||
pipes.push(newpipe);
|
||||
}
|
||||
|
||||
var isIncompatible = {
|
||||
Android: function() {
|
||||
return navigator.userAgent.match(/Android/i);
|
||||
},
|
||||
BlackBerry: function() {
|
||||
return navigator.userAgent.match(/BlackBerry/i);
|
||||
},
|
||||
iOS: function() {
|
||||
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
||||
},
|
||||
Opera: function() {
|
||||
return navigator.userAgent.match(/Opera Mini/i);
|
||||
},
|
||||
Safari: function() {
|
||||
return (navigator.userAgent.match(/OS X.*Safari/) && ! navigator.userAgent.match(/Chrome/));
|
||||
},
|
||||
Windows: function() {
|
||||
return navigator.userAgent.match(/IEMobile/i);
|
||||
},
|
||||
any: function() {
|
||||
return (isIncompatible.Android() || isIncompatible.BlackBerry() || isIncompatible.iOS() || isIncompatible.Opera() || isIncompatible.Safari() || isIncompatible.Windows());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var pipe = $('<div class="pipe animated"><div class="pipe_upper"></div><div class="pipe_lower"></div></div>');
|
||||
$("#flyarea").append(pipe);
|
||||
|
||||
var gameSpeed = 20
|
||||
var playing = false;
|
||||
function newGame() {
|
||||
if (playing) {
|
||||
playing = false;
|
||||
setTimeout(newGame, gameSpeed);
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loading').addClass('active');
|
||||
|
||||
fetch('/play').then(res => res.json()).then(function(states) {
|
||||
playing = true;
|
||||
|
||||
$('#loading').removeClass('active');
|
||||
|
||||
$("#player").css({ rotate: 0 });
|
||||
|
||||
var i = 0;
|
||||
setTimeout(function p() {
|
||||
if (!playing) return;
|
||||
|
||||
var state = states[i];
|
||||
if (!state || state.lost) {
|
||||
$(".animated").css('animation-play-state', 'paused');
|
||||
$(".animated").css('-webkit-animation-play-state', 'paused');
|
||||
|
||||
//drop the bird to the floor
|
||||
var playerbottom = $("#player").position().top + $("#player").width(); //we use width because he'll be rotated 90 deg
|
||||
var floor = flyArea;
|
||||
var movey = Math.max(0, floor - playerbottom);
|
||||
$("#player").transition({ top: movey + 'px', rotate: 90}, 1000, 'easeInOutCubic');
|
||||
|
||||
if(isIncompatible.any())
|
||||
{
|
||||
//skip right to showing score
|
||||
showScore();
|
||||
}
|
||||
else
|
||||
{
|
||||
//play the hit sound (then the dead sound) and then show score
|
||||
soundHit.play().bindOnce("ended", function() {
|
||||
soundDie.play().bindOnce("ended", function() {
|
||||
showScore();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
score = Math.round((state.score - i * 0.1) / 10);
|
||||
setBigScore();
|
||||
|
||||
$("#player").css({ top: state.bird.y, left: state.bird.x });
|
||||
|
||||
$(".pipe").css({ left: state.wall.x });
|
||||
$(".pipe_upper").css({ height: state.wall.gate.y });
|
||||
$(".pipe_lower").css({ height: 200 - state.wall.gate.y - state.wall.gate.height });
|
||||
|
||||
i++;
|
||||
setTimeout(p, gameSpeed)
|
||||
}, gameSpeed)
|
||||
});
|
||||
}
|
||||
|
||||
$('#new').click(newGame)
|
||||
|
||||
$('#faster').click(function() {
|
||||
gameSpeed = Math.max(5, gameSpeed - 5);
|
||||
});
|
||||
|
||||
$('#slower').click(function() {
|
||||
gameSpeed = Math.min(50, gameSpeed + 5);
|
||||
});
|
||||
|
||||
|
||||
newGame();
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
<html class="fa-events-icons-ready"><head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>Playing Flappy Bird using Evolution Strategies</title>
|
||||
|
||||
<link rel="stylesheet" href="main_files/style.css">
|
||||
|
||||
<script src="main_files/befea5cf35.js"></script><link href="main_files/befea5cf35.css" media="all" rel="stylesheet">
|
||||
<script src="main_files/socket.js"></script>
|
||||
</head>
|
||||
|
||||
<body><header>
|
||||
<h1>Playing Flappy Bird using Evolution Strategies</h1>
|
||||
</header>
|
||||
|
||||
<canvas id="canvas" width="450" height="400"></canvas>
|
||||
|
||||
<footer>
|
||||
<p>Inspired by <a href="https://blog.openai.com/evolution-strategies/">Evolution Strategies as a Scalable Alternative to Reinforcement Learning</a> by <a href="https://openai.com/">OpenAI</a></p><a href="https://openai.com/">
|
||||
|
||||
</a><div class="links"><a href="https://openai.com/">
|
||||
</a><a class="github" href="https://github.com/mdibaiee/flappy-es" alt="GitHub">GitHub <i class="fa fa-github"></i></a>
|
||||
<a class="aylien" href="https://aylien.com/"><img src="main_files/aylien.png" alt="Aylien" width="32"></a>
|
||||
</div>
|
||||
</footer>
|
||||
</body></html>
|
Before Width: | Height: | Size: 3.9 KiB |
@ -1,21 +0,0 @@
|
||||
/*!
|
||||
* Font Awesome v4.7.0 by @davegandy - http://fontawesome.io - @fontawesome
|
||||
* License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License)
|
||||
*/
|
||||
@import url('//use.fontawesome.com/releases/v4.7.0/css/font-awesome-css.min.css');
|
||||
/* FONT PATH
|
||||
* -------------------------- */
|
||||
@font-face {
|
||||
font-family: 'FontAwesome';
|
||||
src: url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.eot');
|
||||
src: url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.eot?#iefix') format('embedded-opentype'),
|
||||
url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.woff2') format('woff2'),
|
||||
url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.woff') format('woff'),
|
||||
url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.ttf') format('truetype'),
|
||||
url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.svg#fontawesomeregular') format('svg');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
/*
|
||||
Embed code befea5cf35
|
||||
*/
|
@ -1,36 +0,0 @@
|
||||
html, body {
|
||||
color: rgb(50, 50, 50);
|
||||
background: rgb(246, 248, 251);
|
||||
|
||||
font-family: Open Sans, sans-serif;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
a {
|
||||
color: rgb(140, 140, 180);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: rgb(90, 90, 130);
|
||||
}
|
||||
|
||||
.github {
|
||||
font-size: 0;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.github .fa {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.links {
|
||||
display: flex;
|
||||
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.links a {
|
||||
margin: 0 0.5rem;
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
html, body {
|
||||
color: rgb(50, 50, 50);
|
||||
background: rgb(246, 248, 251);
|
||||
|
||||
font-family: Open Sans, sans-serif;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
header {
|
||||
margin-top: 3rem;
|
||||
}
|
||||
|
||||
a {
|
||||
color: rgb(140, 140, 180);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: rgb(90, 90, 130);
|
||||
}
|
||||
|
||||
.github {
|
||||
font-size: 0;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.github .fa {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.links {
|
||||
display: flex;
|
||||
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.links a {
|
||||
margin: 0 0.5rem;
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 8px;
|
||||
}
|
||||
|
||||
footer > * {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.btn {
|
||||
cursor: pointer;
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.btn i {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
|
||||
z-index: 9999;
|
||||
|
||||
font-size: 25px;
|
||||
font-weight: bold;
|
||||
|
||||
overflow: hidden;
|
||||
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
|
||||
position: fixed;
|
||||
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
|
||||
text-align: center;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.overlay.active {
|
||||
opacity: 1;
|
||||
pointer-events: all;
|
||||
}
|