-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.html
126 lines (115 loc) · 3.78 KB
/
play.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<html>
<head>
<title>Rummi Assistant</title>
<style type='text/css'>
span.tilecolour-R { background: red; color: white }
span.tilecolour-T { background: aqua; color: black }
span.tilecolour-Y { background: orange; color: black }
span.tilecolour-B { background: black; color: white }
#solution li {
margin: 1ex;
border: 1px solid black;
padding: 2ex 2ex 2ex 1ex;
list-style: none;
width: fit-content;
background: #e0e0e0;
display: inline-block;
}
li > span { margin-left: 1ex; padding: 4px; width: 4ex; display: inline-block; text-align: center }
li > span.joker { font-weight: bold }
#tosolve span { margin-left: 1ex; padding: 4px }
#tosolve span.joker { font-weight: bold }
#tosolve { margin: 1ex; line-height: 2em; }
#solvebutton { height: 2em; width: 8em; }
</style>
<script src='./rummi.js'></script>
<script>
function parse_tiles(str) {
const pieces = str.toUpperCase().split(/[ ,]+/),
tiles = [];
let prev = 0;
for (const t of pieces) {
let tc = colour(prev), digits = '';
for (c in Colours) if (t.includes(Colours[c])) tc = c;
for (d of t) if (Number.isInteger(d - 0)) digits = digits.concat(d);
if (!digits) digits = rank(prev);
prev = card(tc, digits);
if (t.includes('J'))
for (j in Jokers)
if (t == Jokers[j]) prev = (j - 0 + 1) << 4;
if (prev) tiles.push(prev);
}
return tiles;
}
function dosolve() {
const tdiv = document.getElementById('table'),
hdiv = document.getElementById('hand'),
groups = [];
for (let box of tdiv.querySelectorAll('textarea')) {
let contents = box.value.split('\n').map(parse_tiles);
box.value = contents.map(cardsstr).join('\n');
groups.push(contents);
}
for (let box of hdiv.querySelectorAll('textarea')) {
let contents = box.value.split('\n').map(parse_tiles);
box.value = contents.map(cardsstr).join('\n');
groups.push(contents);
}
const li = document.querySelector('#tosolve'),
display = document.getElementById('solution'),
arr = groups.flat().flat();
arr.sort(tilesort);
while (li.firstChild) li.removeChild(li.firstChild);
arr.map(c => prettytile(c, document)).forEach(el => {
li.appendChild(el);
li.append(document.createTextNode(' '));
});
while (display.firstChild) display.removeChild(display.firstChild);
document.getElementById('solvestatus').textContent = 'Working...';
console.log(arr);
workersolve(arr);
}
function get_worker() {
if (!window.solve_worker) solve_worker = new Worker('./worker.js');
return solve_worker;
}
function workersolve(tiles) {
get_worker();
let starttm = new Date().getTime();
solve_worker.onmessage = (msg) => {
console.log('solve:', msg.data);
if (msg.data.completed)
solve_complete(tiles, starttm, msg.data);
else {
const seconds = (new Date().getTime() - msg.data.start_time)/1000;
document.getElementById('solvestatus').textContent = 'Working ' + Math.floor(seconds) + 's';
}
}
solve_worker.postMessage(tiles);
console.log('waiting for solve');
}
</script>
</head>
<body>
<div>
<p>Colours: R T Y B /
Ranks: 1 - 13 /
Jokers: JS JD JM JC</p>
<p><a href='https://github.com/andrewmcguinness/rk-ventura'>source on Github</a></p>
</div>
<div id='table'>
<h3>Table</h3>
<textarea cols='25' rows='10'></textarea>
<textarea cols='25' rows='10'></textarea>
<textarea cols='25' rows='10'></textarea>
</div>
<div id='hand'>
<h3>Hand</h3>
<textarea cols='40' rows='3'></textarea>
</div>
<button type='button' id='solvebutton' onclick='dosolve()'>Solve</button>
<div id='tosolve'></div>
<p id='solvestatus'></p>
<ul id='solution'></ul>
</body>
</html>