-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcartpole.html
109 lines (92 loc) · 4.41 KB
/
cartpole.html
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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cartpole Game</title>
<meta name=viewport content="width=device-width, initial-scale=1">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-131436916-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-131436916-2');
</script>
<!-- <script type="text/javascript" src="http://livejs.com/live.js"></script> -->
</head>
<body>
<div style="max-width: 850px; text-align: left; padding: 0 1em 0 1em;" id="big-container">
<h1>Can you balance this cartpole?</h1>
<p>
Here is a pole sitting on top of a cart.
<!-- If the pole falls down, then you lose. If the cart falls off the platform, you also lose. -->
How long can you balance the pole?
</p>
<p style="font-size: smaller;">
Use the <i>left and right arrow keys</i> (or <code>h/l</code>) to push the cart.<br/>
Use the <i>Start button</i> (or spacebar) to pause, resume, and restart.
</p>
<p>
<input type="button" id="start" style="font-weight:bold; font-size: large;" value="Start">
<input type="button" id="reset" value="Reset" disabled>
High Score: <span id="hi-score">0.0</span>
</p>
<div style="display: inline-block;">
<canvas id="canvas" width="400" height="400" style="border: 1px black solid;">
Your browser doesn't support the HTML5 canvas :(
</canvas>
<p>
<label for="theme">Theme: </label>
<select id="theme" autocomplete="off">
<option value="plain">Plain</option>
<option value="gobears">Go Bears</option>
</select>
<label for="immortal-checkbox">Immortal: </label>
<input type="checkbox" name="immortal-checkbox" id="immortal-checkbox" autocomplete="off">
<br/>
Mode:
<input type="radio" name="auto-radio" id="manual" checked="checked" autocomplete="off"><label for="manual">Manual</label>
<input type="radio" name="auto-radio" id="auto" autocomplete="off"><label for="auto">Automatic</label>
</p>
</div>
<div style="display: none; vertical-align: top; border: 1px solid black; padding: 0 1em 0 1em; width=100%;" id="advanced-div">
<p style="max-width: 400px;">Write some code to balance the cart for you!</p>
<div style="border: 1px dashed gray; padding: 0.5em; display: inline-block;">
<code>
function pickAction(x, xDot, theta, thetaDot, t, obj) {<br/>
<textarea style="margin-left: 2em" id="code-box" rows="7" cols="33">
if (theta < - Math.PI / 50) {
return RIGHT_PUSH;
} else if (theta > Math.PI / 50) {
return LEFT_PUSH;
} else {
return NO_PUSH;
}
</textarea>
<br/>
}<br/>
</code>
<br/>
<input type="button" id="run-code" value="Run this code">
<span id="run-confirm"></span>
</div>
<p style="font-size: smaller; max-width: 400px;">
The function <code>pickAction</code> will be executed on each frame.
<!-- Its arguments represent the current state of the cartpole. -->
It should return one of three possible actions: LEFT_PUSH, RIGHT_PUSH, or NO_PUSH.
See the <a href="cartpole.js" target="_blank">source code</a> for more details.
(The function <code>pickAction</code> is at the end of the file.)
</p>
</div>
<img style="display:none" id="kiwibot" src="img/kiwibot.png" />
<img style="display:none" id="cal-flag" src="img/cal-flag.png" />
<img style="display:none" id="arrow" src="img/left-arrow.png" />
<script src="cartpole.js"></script>
<p>
This is the classic <a href="https://en.wikipedia.org/wiki/Inverted_pendulum" target="_blank">inverted pendulum problem</a> of control theory—also known as the <a href="https://gym.openai.com/envs/CartPole-v0/" target="_blank">cartpole problem</a> of reinforcement learning (or "AI"). With a proper strategy, you can stabilize the cart indefinitely. The strategy can either come from mathematical principles (control theory) or from experience (reinforcement learning).
</p>
<hr style="width: 100%">
<address><a href="https://jeffjar.me">Jeffrey Chang</a></address>
<small>Icons made by <a href="https://www.flaticon.com/authors/roundicons" title="Roundicons">Roundicons</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>. Last updated on Dec 19, 2019.</small>
<br/>
</div>
</body>