@renju-note/quintet 0.0.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Renju Note
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # quintet
2
+
3
+ Renju mate solver compilable to WebAssembly
4
+
5
+ ## Run
6
+
7
+ ### VCF
8
+
9
+ ```
10
+ % cargo run --release --example solve vcf 10 5 x \
11
+ H8,H7,F6,G7,I7,G9,G6,H6,F8,E8,F9,F7,E7,D6,H4,G5,J6,I5,J4,K5,J5,J3,J8,J7,I4,K4,K6,L7,L6,M6,I2,N7,L5,K7,M7,G4,I8,G8,K8,L8,D5,E4,F4,F3,H3,G2,E2,I10,J11,F11,G11,D9,E10,E12,F13,C10,B11,C12,D12
12
+ Finished release [optimized] target(s) in 0.00s
13
+ Running `target/release/examples/solve vcf 10 x H8,H7,F6,G7,I7,G9,G6,H6,F8,E8,F9,F7,E7,D6,H4,G5,J6,I5,J4,K5,J5,J3,J8,J7,I4,K4,K6,L7,L6,M6,I2,N7,L5,K7,M7,G4,I8,G8,K8,L8,D5,E4,F4,F3,H3,G2,E2,I10,J11,F11,G11,D9,E10,E12,F13,C10,B11,C12,D12`
14
+ Kind: VCF
15
+ MaxDepth: 10
16
+ Player: White
17
+ Board:
18
+ 15 . . . . . . . . . . . . . . .
19
+ 14 . . . . . . . . . . . . . . .
20
+ 13 . . . . . o . . . . . . . . .
21
+ 12 . . x o x . . . . . . . . . .
22
+ 11 . o . . . x o . . o . . . . .
23
+ 10 . . x . o . . . x . . . . . .
24
+ 9 . . . x . o x . . . . . . . .
25
+ 8 . . . . x o x o o o o x . . .
26
+ 7 . . . . o x x x o x x x o x .
27
+ 6 . . . x . o o x . o o o x . .
28
+ 5 . . . o . . x . x o x o . . .
29
+ 4 . . . . x o x o o o x . . . .
30
+ 3 . . . . . x . o . x . . . . .
31
+ 2 . . . . o . x . o . . . . . .
32
+ 1 . . . . . . . . . . . . . . .
33
+ A B C D E F G H I J K L M N O
34
+
35
+ Solving...
36
+
37
+ Elapsed: 45.041µs
38
+ Depth: 8
39
+ Solution: G1,G3,E6,H9,H5,I6,F5,E5,C8,D7,C11,C9,C14,C13,D13
40
+ ```
41
+
42
+ ### VCT
43
+
44
+ ```
45
+ % cargo run --release --example solve vct_dfpns 255 3 x \
46
+ H8,I9,H7,J8,F8,H9,G9,H10,G11,F10,I10,G10,I8,J9,E10,K9,L9,G8,J10,K7,L6,K8,K6,L10,I7,J6,M9,I5,H4,F7,G6,E6,D5,F5,G4
47
+ Finished release [optimized] target(s) in 0.03s
48
+ Running `target/release/examples/solve vct_dfpn 255 x H8,I9,H7,J8,F8,H9,G9,H10,G11,F10,I10,G10,I8,J9,E10,K9,L9,G8,J10,K7,L6,K8,K6,L10,I7,J6,M9,I5,H4,F7,G6,E6,D5,F5,G4`
49
+ Kind: VCTDFPN
50
+ MaxDepth: 255
51
+ Player: White
52
+ Board:
53
+ 15 . . . . . . . . . . . . . . .
54
+ 14 . . . . . . . . . . . . . . .
55
+ 13 . . . . . . . . . . . . . . .
56
+ 12 . . . . . . . . . . . . . . .
57
+ 11 . . . . . . o . . . . . . . .
58
+ 10 . . . . o x x x o o . x . . .
59
+ 9 . . . . . . o x x x x o o . .
60
+ 8 . . . . . o x o o x x . . . .
61
+ 7 . . . . . x . o o . x . . . .
62
+ 6 . . . . x . o . . x o o . . .
63
+ 5 . . . o . x . . x . . . . . .
64
+ 4 . . . . . . o o . . . . . . .
65
+ 3 . . . . . . . . . . . . . . .
66
+ 2 . . . . . . . . . . . . . . .
67
+ 1 . . . . . . . . . . . . . . .
68
+ A B C D E F G H I J K L M N O
69
+
70
+ Solving...
71
+
72
+ Elapsed: 2.370459s
73
+ Depth: 17
74
+ Solution: K11,K10,N12,M11,N8,H5,H6,L8,J5,J7,M5,L4,M6,K5,N7,N5,M4,M7,J4,I6,F3,M8,M10,I12,J11,K3,K4,J3,O8,L5,M2,M3,N1
75
+ ```
76
+
77
+ Original game: https://www.renju.net/media/games.php?gameid=92337
78
+
79
+ ## Release
80
+
81
+ ```
82
+ # build
83
+ $ wasm-pack build --scope renju-note
84
+
85
+ # publish
86
+ $ wasm-pack publish
87
+ ```
88
+
89
+ See also: https://developer.mozilla.org/ja/docs/WebAssembly/Rust_to_wasm
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@renju-note/quintet",
3
+ "collaborators": [
4
+ "yubessy <yubessy0@gmail.com>"
5
+ ],
6
+ "description": "Renju mate solver compilable to WebAssemby",
7
+ "version": "0.0.0-dev",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/renju-note/quintet"
12
+ },
13
+ "files": [
14
+ "quintet_bg.wasm",
15
+ "quintet.js",
16
+ "quintet_bg.js",
17
+ "quintet.d.ts"
18
+ ],
19
+ "module": "quintet.js",
20
+ "types": "quintet.d.ts",
21
+ "sideEffects": false
22
+ }
package/quintet.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {number} mode
5
+ * @param {number} limit
6
+ * @param {Uint8Array} blacks
7
+ * @param {Uint8Array} whites
8
+ * @param {boolean} black
9
+ * @param {number} threat_limit
10
+ * @returns {Uint8Array | undefined}
11
+ */
12
+ export function solve(mode: number, limit: number, blacks: Uint8Array, whites: Uint8Array, black: boolean, threat_limit: number): Uint8Array | undefined;
13
+ /**
14
+ * @param {Uint8Array} blacks
15
+ * @param {Uint8Array} whites
16
+ * @param {boolean} black
17
+ * @param {number} limit
18
+ * @returns {Uint8Array | undefined}
19
+ */
20
+ export function solve_vcf(blacks: Uint8Array, whites: Uint8Array, black: boolean, limit: number): Uint8Array | undefined;
21
+ /**
22
+ * @param {Uint8Array} blacks
23
+ * @param {Uint8Array} whites
24
+ * @param {boolean} black
25
+ * @param {number} limit
26
+ * @returns {Uint8Array | undefined}
27
+ */
28
+ export function solve_vct(blacks: Uint8Array, whites: Uint8Array, black: boolean, limit: number): Uint8Array | undefined;
29
+ /**
30
+ * @param {Uint8Array} blacks
31
+ * @param {Uint8Array} whites
32
+ * @param {boolean} black
33
+ * @param {number} limit
34
+ * @returns {Uint8Array | undefined}
35
+ */
36
+ export function solve_vct_dfpn(blacks: Uint8Array, whites: Uint8Array, black: boolean, limit: number): Uint8Array | undefined;
37
+ /**
38
+ * @param {number} x
39
+ * @param {number} y
40
+ * @returns {number}
41
+ */
42
+ export function encode_xy(x: number, y: number): number;
43
+ /**
44
+ * @param {number} code
45
+ * @returns {number}
46
+ */
47
+ export function decode_x(code: number): number;
48
+ /**
49
+ * @param {number} code
50
+ * @returns {number}
51
+ */
52
+ export function decode_y(code: number): number;
package/quintet.js ADDED
@@ -0,0 +1,4 @@
1
+ import * as wasm from "./quintet_bg.wasm";
2
+ import { __wbg_set_wasm } from "./quintet_bg.js";
3
+ __wbg_set_wasm(wasm);
4
+ export * from "./quintet_bg.js";
package/quintet_bg.js ADDED
@@ -0,0 +1,179 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+
7
+ let cachedUint8Memory0 = null;
8
+
9
+ function getUint8Memory0() {
10
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
11
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
12
+ }
13
+ return cachedUint8Memory0;
14
+ }
15
+
16
+ let WASM_VECTOR_LEN = 0;
17
+
18
+ function passArray8ToWasm0(arg, malloc) {
19
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
20
+ getUint8Memory0().set(arg, ptr / 1);
21
+ WASM_VECTOR_LEN = arg.length;
22
+ return ptr;
23
+ }
24
+
25
+ let cachedInt32Memory0 = null;
26
+
27
+ function getInt32Memory0() {
28
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
29
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
30
+ }
31
+ return cachedInt32Memory0;
32
+ }
33
+
34
+ function getArrayU8FromWasm0(ptr, len) {
35
+ ptr = ptr >>> 0;
36
+ return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
37
+ }
38
+ /**
39
+ * @param {number} mode
40
+ * @param {number} limit
41
+ * @param {Uint8Array} blacks
42
+ * @param {Uint8Array} whites
43
+ * @param {boolean} black
44
+ * @param {number} threat_limit
45
+ * @returns {Uint8Array | undefined}
46
+ */
47
+ export function solve(mode, limit, blacks, whites, black, threat_limit) {
48
+ try {
49
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
50
+ const ptr0 = passArray8ToWasm0(blacks, wasm.__wbindgen_malloc);
51
+ const len0 = WASM_VECTOR_LEN;
52
+ const ptr1 = passArray8ToWasm0(whites, wasm.__wbindgen_malloc);
53
+ const len1 = WASM_VECTOR_LEN;
54
+ wasm.solve(retptr, mode, limit, ptr0, len0, ptr1, len1, black, threat_limit);
55
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
56
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
57
+ let v3;
58
+ if (r0 !== 0) {
59
+ v3 = getArrayU8FromWasm0(r0, r1).slice();
60
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
61
+ }
62
+ return v3;
63
+ } finally {
64
+ wasm.__wbindgen_add_to_stack_pointer(16);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * @param {Uint8Array} blacks
70
+ * @param {Uint8Array} whites
71
+ * @param {boolean} black
72
+ * @param {number} limit
73
+ * @returns {Uint8Array | undefined}
74
+ */
75
+ export function solve_vcf(blacks, whites, black, limit) {
76
+ try {
77
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
78
+ const ptr0 = passArray8ToWasm0(blacks, wasm.__wbindgen_malloc);
79
+ const len0 = WASM_VECTOR_LEN;
80
+ const ptr1 = passArray8ToWasm0(whites, wasm.__wbindgen_malloc);
81
+ const len1 = WASM_VECTOR_LEN;
82
+ wasm.solve_vcf(retptr, ptr0, len0, ptr1, len1, black, limit);
83
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
84
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
85
+ let v3;
86
+ if (r0 !== 0) {
87
+ v3 = getArrayU8FromWasm0(r0, r1).slice();
88
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
89
+ }
90
+ return v3;
91
+ } finally {
92
+ wasm.__wbindgen_add_to_stack_pointer(16);
93
+ }
94
+ }
95
+
96
+ /**
97
+ * @param {Uint8Array} blacks
98
+ * @param {Uint8Array} whites
99
+ * @param {boolean} black
100
+ * @param {number} limit
101
+ * @returns {Uint8Array | undefined}
102
+ */
103
+ export function solve_vct(blacks, whites, black, limit) {
104
+ try {
105
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
106
+ const ptr0 = passArray8ToWasm0(blacks, wasm.__wbindgen_malloc);
107
+ const len0 = WASM_VECTOR_LEN;
108
+ const ptr1 = passArray8ToWasm0(whites, wasm.__wbindgen_malloc);
109
+ const len1 = WASM_VECTOR_LEN;
110
+ wasm.solve_vct(retptr, ptr0, len0, ptr1, len1, black, limit);
111
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
112
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
113
+ let v3;
114
+ if (r0 !== 0) {
115
+ v3 = getArrayU8FromWasm0(r0, r1).slice();
116
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
117
+ }
118
+ return v3;
119
+ } finally {
120
+ wasm.__wbindgen_add_to_stack_pointer(16);
121
+ }
122
+ }
123
+
124
+ /**
125
+ * @param {Uint8Array} blacks
126
+ * @param {Uint8Array} whites
127
+ * @param {boolean} black
128
+ * @param {number} limit
129
+ * @returns {Uint8Array | undefined}
130
+ */
131
+ export function solve_vct_dfpn(blacks, whites, black, limit) {
132
+ try {
133
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
134
+ const ptr0 = passArray8ToWasm0(blacks, wasm.__wbindgen_malloc);
135
+ const len0 = WASM_VECTOR_LEN;
136
+ const ptr1 = passArray8ToWasm0(whites, wasm.__wbindgen_malloc);
137
+ const len1 = WASM_VECTOR_LEN;
138
+ wasm.solve_vct_dfpn(retptr, ptr0, len0, ptr1, len1, black, limit);
139
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
140
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
141
+ let v3;
142
+ if (r0 !== 0) {
143
+ v3 = getArrayU8FromWasm0(r0, r1).slice();
144
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
145
+ }
146
+ return v3;
147
+ } finally {
148
+ wasm.__wbindgen_add_to_stack_pointer(16);
149
+ }
150
+ }
151
+
152
+ /**
153
+ * @param {number} x
154
+ * @param {number} y
155
+ * @returns {number}
156
+ */
157
+ export function encode_xy(x, y) {
158
+ const ret = wasm.encode_xy(x, y);
159
+ return ret;
160
+ }
161
+
162
+ /**
163
+ * @param {number} code
164
+ * @returns {number}
165
+ */
166
+ export function decode_x(code) {
167
+ const ret = wasm.decode_x(code);
168
+ return ret;
169
+ }
170
+
171
+ /**
172
+ * @param {number} code
173
+ * @returns {number}
174
+ */
175
+ export function decode_y(code) {
176
+ const ret = wasm.decode_y(code);
177
+ return ret;
178
+ }
179
+
Binary file