-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
66 lines (61 loc) · 1.79 KB
/
index.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
<script src='./numeric.js'></script>
<script src='./connection.js'></script>
<script src='./test.js'></script>
<script src='./main.js'>
</script>
<script>
function changedInput(){
let p1 = toBinary(parseInt(document.getElementById('p1').value))
let p2 = toBinary(parseInt(document.getElementById('p2').value))
let p3 = toBinary(parseInt(document.getElementById('p3').value))
let res = main(p1,p2,p3)
document.getElementById('result').innerHTML = JSON.stringify(res[18])
console.log(res)
// explanation
let piles = [p1,p2,p3]
let pile = 1
if (res[18][1]>0) pile = 2
if (res[18][2]>0) pile = 3
let a = new Int32Array(res[18]).subarray(3)
let psize = parseInt(Array.from(a).join(''),2)
let error = ''
if (a >= piles[pile-1]) {
error = 'THERE IS PROBABLY AN ERROR'
}
console.log('binary',psize)
document.getElementById('explanation').innerHTML = (`It says to make pile ${pile} have ${psize} stones. ${error}`)
}
function toBinary(n){
let str = n.toString(2).padStart(6,'0')
let fu = str.split('').map((a)=>{return parseInt(a)})
return fu
}
function draw() {
let net = mainNetwork()
let can = net.draw(30, 15)
document.body.appendChild(can)
}
setTimeout(draw, 100)
window.addEventListener('DOMContentLoaded', changedInput, false);
</script>
<body>
<div>
<h2>
Neural network Nim
</h2>
Cody Smith. 2019
</div>
<hr>
<br>
<div>pile 1: <input type="number" id='p1' value=5 ></div>
<div>pile 2: <input type="number" id='p2' value=13 ></div>
<div>pile 3: <input type="number" id='p3' value=2 ></div>
<button onclick="changedInput()">run</button>
<div></div>
<div style='font-size: xx-large;'>result: <span id='result'></span></div>
<div id="explanation"></div>
<br><br><br>
<br><br><br>
<br><br><br>
<br><br><br>
</body>