-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
69 lines (65 loc) · 2.02 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
67
68
69
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Solidity</title>
</head>
<body>
<script>
const worker = new Worker('/dist/worker.js');
worker.addEventListener("message", (e) => {
console.log("event", e.data);
if(e.data.type === "simulateResult") {
console.log(e.data.result);
}
});
// worker.postMessage({
// type: "simulate",
// game: "tic_tac_toe",
// code: `
// // SPDX-License-Identifier: MIT
// pragma solidity ^0.8.7;
//
// import { Tic_tac_toe_strategy, Player } from "./tic_tac_toe.sol";
//
// contract CustomStrategy is Tic_tac_toe_strategy {
// function get_move(Player[] memory _board) external override pure returns (uint) {
// // Returns first free position
// for (uint i = 0; i < _board.length; i++) {
// if (_board[i] == Player.None) return i;
// }
// // Cannot reach here
// revert();
// }
// }
// `
// });
worker.postMessage({
type: "playGame",
game: "tic_tac_toe",
code: `
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import { Tic_tac_toe_strategy, Player } from "./tic_tac_toe.sol";
contract CustomStrategy is Tic_tac_toe_strategy {
function get_move(Player[] memory _board) external override pure returns (uint) {
// Returns first free position
for (uint i = 0; i < _board.length; i++) {
if (_board[i] == Player.None) return i;
}
// Returns last free position
// for (uint i = _board.length - 1; i >= 0; i--) {
// if (_board[i] == Player.None) return i;
// }
// Cannot reach here
revert();
}
}
`
});
</script>
</body>
</html>