diff --git a/10.bootstrap.js b/10.bootstrap.js index d680d46..99dc4a4 100644 --- a/10.bootstrap.js +++ b/10.bootstrap.js @@ -1,2 +1,2 @@ -(self.webpackChunkdraught=self.webpackChunkdraught||[]).push([[10],{171:(t,e,r)=>{"use strict";r.a(t,(async n=>{r.d(e,{wc:()=>x,SZ:()=>j,i0:()=>O,Tt:()=>S,rh:()=>q,lA:()=>I,Ck:()=>B,ug:()=>A,h4:()=>U,h9:()=>$,Dz:()=>M,kF:()=>D,s8:()=>J,WB:()=>P,cP:()=>R,a:()=>z,l_:()=>F,U_:()=>N,EN:()=>Y,qu:()=>K,Wg:()=>L,B3:()=>Q,I6:()=>Z,Qb:()=>X,cI:()=>H,QK:()=>G,Md:()=>V,ox:()=>tt,ES:()=>et,Ae:()=>rt,UL:()=>nt,qw:()=>_t,tS:()=>at,R$:()=>ct,md:()=>it,IF:()=>ot,XP:()=>st,m_:()=>ut,fY:()=>pt,Or:()=>lt});var _=r(813);t=r.hmd(t);var a=n([_]);_=(a.then?await a:a)[0];const c=new Array(32).fill(void 0);function i(t){return c[t]}c.push(void 0,null,!0,!1);let o=c.length;let s=new("undefined"==typeof TextDecoder?(0,t.require)("util").TextDecoder:TextDecoder)("utf-8",{ignoreBOM:!0,fatal:!0});s.decode();let u=null;function p(){return null!==u&&u.buffer===_.memory.buffer||(u=new Uint8Array(_.memory.buffer)),u}function l(t,e){return s.decode(p().subarray(t,t+e))}function d(t){o===c.length&&c.push(c.length+1);const e=o;return o=c[e],c[e]=t,e}function b(t){const e=typeof t;if("number"==e||"boolean"==e||null==t)return`${t}`;if("string"==e)return`"${t}"`;if("symbol"==e){const e=t.description;return null==e?"Symbol":`Symbol(${e})`}if("function"==e){const e=t.name;return"string"==typeof e&&e.length>0?`Function(${e})`:"Function"}if(Array.isArray(t)){const e=t.length;let r="[";e>0&&(r+=b(t[0]));for(let n=1;n1))return toString.call(t);if(n=r[1],"Object"==n)try{return"Object("+JSON.stringify(t)+")"}catch(t){return"Object"}return t instanceof Error?`${t.name}: ${t.message}\n${t.stack}`:n}let g=0,w=new("undefined"==typeof TextEncoder?(0,t.require)("util").TextEncoder:TextEncoder)("utf-8");const f="function"==typeof w.encodeInto?function(t,e){return w.encodeInto(t,e)}:function(t,e){const r=w.encode(t);return e.set(r),{read:t.length,written:r.length}};function h(t,e,r){if(void 0===r){const r=w.encode(t),n=e(r.length);return p().subarray(n,n+r.length).set(r),g=r.length,n}let n=t.length,_=e(n);const a=p();let c=0;for(;c127)break;a[_+c]=e}if(c!==n){0!==c&&(t=t.slice(c)),_=r(_,n,n=c+3*t.length);const e=p().subarray(_+c,_+n);c+=f(t,e).written}return g=c,_}let m=null;function v(){return null!==m&&m.buffer===_.memory.buffer||(m=new Int32Array(_.memory.buffer)),m}function y(t){return null==t}function k(t,e){if(!(t instanceof e))throw new Error(`expected instance of ${e.name}`);return t.ptr}function x(){_.init_wasm()}function T(t,e){try{return t.apply(this,e)}catch(t){_.__wbindgen_exn_store(d(t))}}Object.freeze({Move:0,0:"Move",Jump:1,1:"Jump"});const j=Object.freeze({Black:0,0:"Black",White:1,1:"White"}),O=(Object.freeze({Man:0,0:"Man",King:1,1:"King"}),Object.freeze({Empty:0,0:"Empty",Occupied:1,1:"Occupied",Unplayable:2,2:"Unplayable"})),S=Object.freeze({Allowed:0,0:"Allowed",UnoccupiedSrc:1,1:"UnoccupiedSrc",OccupiedDest:2,2:"OccupiedDest",OutOfBounds:3,3:"OutOfBounds",Unplayable:4,4:"Unplayable",WrongTeamSrc:5,5:"WrongTeamSrc",IllegalTrajectory:6,6:"IllegalTrajectory",NoJumpablePiece:7,7:"NoJumpablePiece",JumpingSameTeam:8,8:"JumpingSameTeam"});class E{static __wrap(t){const e=Object.create(E.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_board_free(t)}get width(){return _.__wbg_get_board_width(this.ptr)>>>0}set width(t){_.__wbg_set_board_width(this.ptr,t)}get height(){return _.__wbg_get_board_height(this.ptr)>>>0}set height(t){_.__wbg_set_board_height(this.ptr,t)}get current_turn(){return _.__wbg_get_board_current_turn(this.ptr)>>>0}set current_turn(t){_.__wbg_set_board_current_turn(this.ptr,t)}cell(t){var e=_.board_cell(this.ptr,t);return W.__wrap(e)}set_cell(t,e){k(e,W);var r=e.ptr;e.ptr=0,_.board_set_cell(this.ptr,t,r)}grid_cell(t){k(t,q);var e=t.ptr;t.ptr=0;var r=_.board_grid_cell(this.ptr,e);return W.__wrap(r)}cell_index(t,e){return _.board_cell_index(this.ptr,t,e)>>>0}cell_idx(t){k(t,q);var e=t.ptr;return t.ptr=0,_.board_cell_idx(this.ptr,e)>>>0}board_index(t){var e=_.board_board_index(this.ptr,t);return q.__wrap(e)}can_move(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;return e.ptr=0,_.board_can_move(this.ptr,r,n)>>>0}validate_man_move(t,e,r){k(t,q);var n=t.ptr;t.ptr=0,k(e,q);var a=e.ptr;e.ptr=0,k(r,C);var c=r.ptr;return r.ptr=0,_.board_validate_man_move(this.ptr,n,a,c)>>>0}validate_king_move(t,e,r){k(t,q);var n=t.ptr;t.ptr=0,k(e,q);var a=e.ptr;e.ptr=0,k(r,C);var c=r.ptr;return r.ptr=0,_.board_validate_king_move(this.ptr,n,a,c)>>>0}jumpee_idx(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;return e.ptr=0,_.board_jumpee_idx(this.ptr,r,n)>>>0}cells(){return _.board_cells(this.ptr)}num_cells(){return _.board_num_cells(this.ptr)>>>0}num_pieces(){return _.board_num_pieces(this.ptr)>>>0}num_player(t){return _.board_num_player(this.ptr,t)>>>0}score(){return _.board_score(this.ptr)}cell_state(t){return _.board_cell_state(this.ptr,t)>>>0}apply_move(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;e.ptr=0;var a=_.board_apply_move(this.ptr,r,n);return E.__wrap(a)}apply_jump(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;e.ptr=0;var a=_.board_apply_jump(this.ptr,r,n);return E.__wrap(a)}static validate_jumpee(t,e){k(t,W);var r=t.ptr;t.ptr=0,k(e,C);var n=e.ptr;return e.ptr=0,_.board_validate_jumpee(r,n)>>>0}static check_jumpee_team(t,e){k(t,C);var r=t.ptr;t.ptr=0,k(e,C);var n=e.ptr;return e.ptr=0,0!==_.board_check_jumpee_team(r,n)}constructor(t,e,r){var n=_.board_new(t,e,r);return E.__wrap(n)}static init_game(t,e){k(t,E);var r=t.ptr;t.ptr=0;var n=_.board_init_game(r,e);return E.__wrap(n)}}class q{static __wrap(t){const e=Object.create(q.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_brdidx_free(t)}get row(){return _.__wbg_get_brdidx_row(this.ptr)>>>0}set row(t){_.__wbg_set_brdidx_row(this.ptr,t)}get col(){return _.__wbg_get_brdidx_col(this.ptr)>>>0}set col(t){_.__wbg_set_brdidx_col(this.ptr,t)}constructor(t,e){var r=_.brdidx_from(t,e);return q.__wrap(r)}eq(t){return k(t,q),0!==_.brdidx_eq(this.ptr,t.ptr)}}class I{static __wrap(t){const e=Object.create(I.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_game_free(t)}current_board_cells(){return _.game_current_board_cells(this.ptr)}current_board_len(){return _.game_current_board_len(this.ptr)>>>0}current_turn(){return _.game_current_turn(this.ptr)>>>0}current_cell_state(t){k(t,q);var e=_.game_current_cell_state(this.ptr,t.ptr);return W.__wrap(e)}make_move(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;return e.ptr=0,_.game_make_move(this.ptr,r,n)>>>0}execute_move(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;e.ptr=0,_.game_execute_move(this.ptr,r,n)}execute_jump(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;e.ptr=0,_.game_execute_jump(this.ptr,r,n)}push_new_board(t){k(t,E);var e=t.ptr;t.ptr=0,_.game_push_new_board(this.ptr,e)}set_current(t){k(t,E);var e=t.ptr;t.ptr=0,_.game_set_current(this.ptr,e)}constructor(t,e,r,n){var a=_.game_new(t,e,r,n);return I.__wrap(a)}static new_with_canvas(t,e,r,n,a,c,i){var o=h(a,_.__wbindgen_malloc,_.__wbindgen_realloc),s=g,u=_.game_new_with_canvas(t,e,r,n,o,s,c,i);return I.__wrap(u)}set_painter(t){k(t,B);var e=t.ptr;t.ptr=0,_.game_set_painter(this.ptr,e)}draw(){_.game_draw(this.ptr)}}class B{static __wrap(t){const e=Object.create(B.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_painter_free(t)}constructor(t,e,r){var n=h(r,_.__wbindgen_malloc,_.__wbindgen_realloc),a=g,c=_.painter_new(t,e,n,a);return B.__wrap(c)}static new_with_canvas(t,e,r){var n=_.painter_new_with_canvas(t,e,d(r));return B.__wrap(n)}set_square_outline(t){_.painter_set_square_outline(this.ptr,d(t))}set_outline_width(t){_.painter_set_outline_width(this.ptr,t)}set_draw_outline(t){_.painter_set_draw_outline(this.ptr,t)}reset_dimensions(){_.painter_reset_dimensions(this.ptr)}validate_board_dim(t){return k(t,E),0!==_.painter_validate_board_dim(this.ptr,t.ptr)}draw(t){k(t,E),_.painter_draw(this.ptr,t.ptr)}}class C{static __wrap(t){const e=Object.create(C.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_piece_free(t)}get team(){return _.__wbg_get_piece_team(this.ptr)>>>0}set team(t){_.__wbg_set_piece_team(this.ptr,t)}get strength(){return _.__wbg_get_piece_strength(this.ptr)>>>0}set strength(t){_.__wbg_set_piece_strength(this.ptr,t)}constructor(t,e){var r=_.piece_new(t,e);return C.__wrap(r)}}class W{static __wrap(t){const e=Object.create(W.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_square_free(t)}get occupant(){var t=_.__wbg_get_square_occupant(this.ptr);return 0===t?void 0:C.__wrap(t)}set occupant(t){let e=0;y(t)||(k(t,C),e=t.ptr,t.ptr=0),_.__wbg_set_square_occupant(this.ptr,e)}get state(){return _.__wbg_get_square_state(this.ptr)>>>0}set state(t){_.__wbg_set_square_state(this.ptr,t)}constructor(t,e){let r=0;y(e)||(k(e,C),r=e.ptr,e.ptr=0);var n=_.square_new(t,r);return W.__wrap(n)}static pc(t,e){var r=_.square_pc(t,e);return W.__wrap(r)}static empty(){var t=_.square_empty();return W.__wrap(t)}static unplay(){var t=_.square_unplay();return W.__wrap(t)}}function A(t){!function(t){const e=i(t);(function(t){t<36||(c[t]=o,o=t)})(t)}(t)}function U(t,e){return d(l(t,e))}function $(){return d(new Error)}function M(t,e){var r=h(i(e).stack,_.__wbindgen_malloc,_.__wbindgen_realloc),n=g;v()[t/4+1]=n,v()[t/4+0]=r}function D(t,e){try{console.error(l(t,e))}finally{_.__wbindgen_free(t,e)}}function J(t){return i(t)instanceof Window}function P(t){var e=i(t).document;return y(e)?0:d(e)}function R(t,e,r){var n=i(t).getElementById(l(e,r));return y(n)?0:d(n)}function z(t){console.log(i(t))}function F(t){return i(t)instanceof CanvasRenderingContext2D}function N(t,e){i(t).strokeStyle=i(e)}function Y(t,e){i(t).fillStyle=i(e)}function K(t,e){i(t).lineWidth=e}function L(t){i(t).beginPath()}function Q(t){i(t).fill()}function Z(t){i(t).stroke()}function X(){return T((function(t,e,r,n,_,a){i(t).arc(e,r,n,_,a)}),arguments)}function H(t,e,r,n,_){i(t).fillRect(e,r,n,_)}function G(t,e,r,n,_){i(t).strokeRect(e,r,n,_)}function V(t){return i(t)instanceof HTMLCanvasElement}function tt(t,e){i(t).width=e>>>0}function et(t,e){i(t).height=e>>>0}function rt(){return T((function(t,e,r){var n=i(t).getContext(l(e,r));return y(n)?0:d(n)}),arguments)}function nt(t,e){return d(new Function(l(t,e)))}function _t(){return T((function(t,e){return d(i(t).call(i(e)))}),arguments)}function at(){return T((function(){return d(self.self)}),arguments)}function ct(){return T((function(){return d(window.window)}),arguments)}function it(){return T((function(){return d(globalThis.globalThis)}),arguments)}function ot(){return T((function(){return d(r.g.global)}),arguments)}function st(t){return void 0===i(t)}function ut(t){return d(i(t))}function pt(t,e){var r=h(b(i(e)),_.__wbindgen_malloc,_.__wbindgen_realloc),n=g;v()[t/4+1]=n,v()[t/4+0]=r}function lt(t,e){throw new Error(l(t,e))}}))},813:(t,e,r)=>{"use strict";var n=([n])=>r.v(e,t.id,"96b9a573923750a3ae94",{"./draught_bg.js":{__wbindgen_object_drop_ref:n.ug,__wbindgen_string_new:n.h4,__wbg_new_59cb74e423758ede:n.h9,__wbg_stack_558ba5917b466edd:n.Dz,__wbg_error_4bb6c2a97407129a:n.kF,__wbg_instanceof_Window_11e25482011fc506:n.s8,__wbg_document_5aff8cd83ef968f5:n.WB,__wbg_getElementById_b180ea4ada06a837:n.cP,__wbg_log_9a99fb1af846153b:n.a,__wbg_instanceof_CanvasRenderingContext2d_779e79c4121aa91b:n.l_,__wbg_setstrokeStyle_2939ee453716e462:n.U_,__wbg_setfillStyle_af790b5baf4d3210:n.EN,__wbg_setlineWidth_3e6b1837ae38d099:n.qu,__wbg_beginPath_2378575e37027ad3:n.Wg,__wbg_fill_558339447ed6ad43:n.B3,__wbg_stroke_c1e0313c58997dcf:n.I6,__wbg_arc_fffd87d9113dce32:n.Qb,__wbg_fillRect_46ffc8d2cef7e298:n.cI,__wbg_strokeRect_7ea34fad8a7f0fe2:n.QK,__wbg_instanceof_HtmlCanvasElement_fd3cbbe3906d7792:n.Md,__wbg_setwidth_f3c88eb520ba8d47:n.ox,__wbg_setheight_5a1abba41e35c42a:n.ES,__wbg_getContext_813df131fcbd6e91:n.Ae,__wbg_newnoargs_9fdd8f3961dd1bee:n.UL,__wbg_call_ba36642bd901572b:n.qw,__wbg_self_bb69a836a72ec6e9:n.tS,__wbg_window_3304fc4b414c9693:n.R$,__wbg_globalThis_e0d21cabc6630763:n.md,__wbg_global_8463719227271676:n.IF,__wbindgen_is_undefined:n.XP,__wbindgen_object_clone_ref:n.m_,__wbindgen_debug_string:n.fY,__wbindgen_throw:n.Or}});r.a(t,(t=>{var e=t([r(171)]);return e.then?e.then(n):n(e)}),1)},10:(t,e,r)=>{"use strict";r.a(t,(async t=>{r.r(e);var n=r(171),_=t([n]);n=(_.then?await _:_)[0];const a="human_turn.thinking",c="human_turn.from_selected";(0,n.wc)(),document.getElementById("status-p");const i=document.getElementById("status-d"),o=document.getElementById("team-p");let s=null,u=function(t,e="danger",r=!0){null!=s&&clearInterval(s),i.className=`alert alert-${e}`,i.innerText=t,i.hidden=!1,r&&(s=setTimeout((()=>{i.hidden=!0}),3e3))},p=a,l=new n.Ck(480,480,"game-canvas"),d=[],b=new n.lA(8,8,3,n.SZ.Black);b.set_painter(l),b.draw(),w();const g=document.getElementById("game-canvas");function w(){switch(b.current_turn()){case n.SZ.White:o.innerText="⚪ White ⚪";break;case n.SZ.Black:o.innerText="🔴 Black 🔴"}}g.addEventListener("click",(t=>{var e=function(t,e){var r=t.getBoundingClientRect();return{x:e.clientX-r.left,y:e.clientY-r.top}}(g,t);!function(t){switch(p){case a:if(b.current_cell_state(t).state!=n.i0.Occupied)return;if(b.current_cell_state(t).occupant.team!=b.current_turn())return;console.log("Your turn, first piece picked"),d.push(t),p=c;break;case c:if(b.current_cell_state(t).state!=n.i0.Empty)return;if(console.log("Your turn, first piece already picked, picking second"),d.push(t),2!=d.length)return u(`Error: wrong number of clicks to process ${d.length}`),void console.error(`Error: wrong number of clicks to process ${d.length}`);if(d[0].eq(d[1]))u("Move Cancelled");else switch(b.make_move(d[0],d[1])){case n.Tt.Allowed:break;case n.Tt.IllegalTrajectory:u("You can't move like that!");break;case n.Tt.JumpingSameTeam:u("You can't jump your own piece!");break;case n.Tt.NoJumpablePiece:u("There's nothing to jump!");break;case n.Tt.OccupiedDest:u("There's a piece there!");break;case n.Tt.OutOfBounds:u("That square's not on the board! (how have you managed that?)");break;case n.Tt.UnoccupiedSrc:u("There's no piece to move!");break;case n.Tt.Unplayable:u("That's not a playable square!");break;case n.Tt.WrongTeamSrc:u("That's not your piece!")}b.draw(),d=[],p=a;break;case"ai_turn":console.log("It's the AI's turn!")}w()}(new n.rh(Math.floor(e.y/480*8),Math.floor(e.x/480*8)))}))}))}}]); +(self.webpackChunkdraught=self.webpackChunkdraught||[]).push([[10],{171:(t,e,r)=>{"use strict";r.a(t,(async n=>{r.d(e,{wc:()=>x,SZ:()=>j,i0:()=>O,Tt:()=>E,rh:()=>q,lA:()=>B,Ck:()=>I,ug:()=>C,h4:()=>U,h9:()=>$,Dz:()=>M,kF:()=>D,s8:()=>J,WB:()=>P,cP:()=>R,a:()=>z,l_:()=>F,U_:()=>N,EN:()=>Y,qu:()=>K,Wg:()=>L,B3:()=>Q,I6:()=>Z,Qb:()=>X,cI:()=>H,QK:()=>G,Md:()=>V,ox:()=>tt,ES:()=>et,Ae:()=>rt,UL:()=>nt,qw:()=>_t,tS:()=>at,R$:()=>ct,md:()=>it,IF:()=>ot,XP:()=>st,m_:()=>ut,fY:()=>pt,Or:()=>lt});var _=r(813);t=r.hmd(t);var a=n([_]);_=(a.then?await a:a)[0];const c=new Array(32).fill(void 0);function i(t){return c[t]}c.push(void 0,null,!0,!1);let o=c.length;let s=new("undefined"==typeof TextDecoder?(0,t.require)("util").TextDecoder:TextDecoder)("utf-8",{ignoreBOM:!0,fatal:!0});s.decode();let u=null;function p(){return null!==u&&u.buffer===_.memory.buffer||(u=new Uint8Array(_.memory.buffer)),u}function l(t,e){return s.decode(p().subarray(t,t+e))}function d(t){o===c.length&&c.push(c.length+1);const e=o;return o=c[e],c[e]=t,e}function b(t){const e=typeof t;if("number"==e||"boolean"==e||null==t)return`${t}`;if("string"==e)return`"${t}"`;if("symbol"==e){const e=t.description;return null==e?"Symbol":`Symbol(${e})`}if("function"==e){const e=t.name;return"string"==typeof e&&e.length>0?`Function(${e})`:"Function"}if(Array.isArray(t)){const e=t.length;let r="[";e>0&&(r+=b(t[0]));for(let n=1;n1))return toString.call(t);if(n=r[1],"Object"==n)try{return"Object("+JSON.stringify(t)+")"}catch(t){return"Object"}return t instanceof Error?`${t.name}: ${t.message}\n${t.stack}`:n}let g=0,w=new("undefined"==typeof TextEncoder?(0,t.require)("util").TextEncoder:TextEncoder)("utf-8");const h="function"==typeof w.encodeInto?function(t,e){return w.encodeInto(t,e)}:function(t,e){const r=w.encode(t);return e.set(r),{read:t.length,written:r.length}};function f(t,e,r){if(void 0===r){const r=w.encode(t),n=e(r.length);return p().subarray(n,n+r.length).set(r),g=r.length,n}let n=t.length,_=e(n);const a=p();let c=0;for(;c127)break;a[_+c]=e}if(c!==n){0!==c&&(t=t.slice(c)),_=r(_,n,n=c+3*t.length);const e=p().subarray(_+c,_+n);c+=h(t,e).written}return g=c,_}let m=null;function v(){return null!==m&&m.buffer===_.memory.buffer||(m=new Int32Array(_.memory.buffer)),m}function y(t){return null==t}function k(t,e){if(!(t instanceof e))throw new Error(`expected instance of ${e.name}`);return t.ptr}function x(){_.init_wasm()}function T(t,e){try{return t.apply(this,e)}catch(t){_.__wbindgen_exn_store(d(t))}}Object.freeze({Move:0,0:"Move",Jump:1,1:"Jump"});const j=Object.freeze({Black:0,0:"Black",White:1,1:"White"}),O=(Object.freeze({Man:0,0:"Man",King:1,1:"King"}),Object.freeze({Empty:0,0:"Empty",Occupied:1,1:"Occupied",Unplayable:2,2:"Unplayable"})),E=Object.freeze({Allowed:0,0:"Allowed",UnoccupiedSrc:1,1:"UnoccupiedSrc",OccupiedDest:2,2:"OccupiedDest",OutOfBounds:3,3:"OutOfBounds",Unplayable:4,4:"Unplayable",WrongTeamSrc:5,5:"WrongTeamSrc",IllegalTrajectory:6,6:"IllegalTrajectory",NoJumpablePiece:7,7:"NoJumpablePiece",JumpingSameTeam:8,8:"JumpingSameTeam"});class S{static __wrap(t){const e=Object.create(S.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_board_free(t)}get width(){return _.__wbg_get_board_width(this.ptr)>>>0}set width(t){_.__wbg_set_board_width(this.ptr,t)}get height(){return _.__wbg_get_board_height(this.ptr)>>>0}set height(t){_.__wbg_set_board_height(this.ptr,t)}get current_turn(){return _.__wbg_get_board_current_turn(this.ptr)>>>0}set current_turn(t){_.__wbg_set_board_current_turn(this.ptr,t)}cell(t){var e=_.board_cell(this.ptr,t);return A.__wrap(e)}set_cell(t,e){k(e,A);var r=e.ptr;e.ptr=0,_.board_set_cell(this.ptr,t,r)}grid_cell(t){k(t,q);var e=t.ptr;t.ptr=0;var r=_.board_grid_cell(this.ptr,e);return A.__wrap(r)}cell_index(t,e){return _.board_cell_index(this.ptr,t,e)>>>0}cell_idx(t){k(t,q);var e=t.ptr;return t.ptr=0,_.board_cell_idx(this.ptr,e)>>>0}board_index(t){var e=_.board_board_index(this.ptr,t);return q.__wrap(e)}can_move(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;return e.ptr=0,_.board_can_move(this.ptr,r,n)>>>0}validate_man_move(t,e,r){k(t,q);var n=t.ptr;t.ptr=0,k(e,q);var a=e.ptr;e.ptr=0,k(r,W);var c=r.ptr;return r.ptr=0,_.board_validate_man_move(this.ptr,n,a,c)>>>0}validate_king_move(t,e,r){k(t,q);var n=t.ptr;t.ptr=0,k(e,q);var a=e.ptr;e.ptr=0,k(r,W);var c=r.ptr;return r.ptr=0,_.board_validate_king_move(this.ptr,n,a,c)>>>0}jumpee_idx(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;return e.ptr=0,_.board_jumpee_idx(this.ptr,r,n)>>>0}cells(){return _.board_cells(this.ptr)}num_cells(){return _.board_num_cells(this.ptr)>>>0}num_pieces(){return _.board_num_pieces(this.ptr)>>>0}num_player(t){return _.board_num_player(this.ptr,t)>>>0}score(){return _.board_score(this.ptr)}cell_state(t){return _.board_cell_state(this.ptr,t)>>>0}apply_move(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;e.ptr=0;var a=_.board_apply_move(this.ptr,r,n);return S.__wrap(a)}apply_jump(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;e.ptr=0;var a=_.board_apply_jump(this.ptr,r,n);return S.__wrap(a)}king_row_idx(){return _.board_king_row_idx(this.ptr)>>>0}static validate_jumpee(t,e){k(t,A);var r=t.ptr;t.ptr=0,k(e,W);var n=e.ptr;return e.ptr=0,_.board_validate_jumpee(r,n)>>>0}static check_jumpee_team(t,e){k(t,W);var r=t.ptr;t.ptr=0,k(e,W);var n=e.ptr;return e.ptr=0,0!==_.board_check_jumpee_team(r,n)}constructor(t,e,r){var n=_.board_new(t,e,r);return S.__wrap(n)}static init_game(t,e){k(t,S);var r=t.ptr;t.ptr=0;var n=_.board_init_game(r,e);return S.__wrap(n)}}class q{static __wrap(t){const e=Object.create(q.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_brdidx_free(t)}get row(){return _.__wbg_get_brdidx_row(this.ptr)>>>0}set row(t){_.__wbg_set_brdidx_row(this.ptr,t)}get col(){return _.__wbg_get_brdidx_col(this.ptr)>>>0}set col(t){_.__wbg_set_brdidx_col(this.ptr,t)}constructor(t,e){var r=_.brdidx_from(t,e);return q.__wrap(r)}eq(t){return k(t,q),0!==_.brdidx_eq(this.ptr,t.ptr)}}class B{static __wrap(t){const e=Object.create(B.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_game_free(t)}current_board_cells(){return _.game_current_board_cells(this.ptr)}current_board_len(){return _.game_current_board_len(this.ptr)>>>0}current_turn(){return _.game_current_turn(this.ptr)>>>0}current_cell_state(t){k(t,q);var e=_.game_current_cell_state(this.ptr,t.ptr);return A.__wrap(e)}set_selected(t){k(t,q),_.game_set_selected(this.ptr,t.ptr)}clear_selected(){_.game_clear_selected(this.ptr)}make_move(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;return e.ptr=0,_.game_make_move(this.ptr,r,n)>>>0}execute_move(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;e.ptr=0,_.game_execute_move(this.ptr,r,n)}execute_jump(t,e){k(t,q);var r=t.ptr;t.ptr=0,k(e,q);var n=e.ptr;e.ptr=0,_.game_execute_jump(this.ptr,r,n)}push_new_board(t){k(t,S);var e=t.ptr;t.ptr=0,_.game_push_new_board(this.ptr,e)}set_current(t){k(t,S);var e=t.ptr;t.ptr=0,_.game_set_current(this.ptr,e)}constructor(t,e,r,n){var a=_.game_new(t,e,r,n);return B.__wrap(a)}static new_with_canvas(t,e,r,n,a,c,i){var o=f(a,_.__wbindgen_malloc,_.__wbindgen_realloc),s=g,u=_.game_new_with_canvas(t,e,r,n,o,s,c,i);return B.__wrap(u)}set_painter(t){k(t,I);var e=t.ptr;t.ptr=0,_.game_set_painter(this.ptr,e)}draw(){_.game_draw(this.ptr)}}class I{static __wrap(t){const e=Object.create(I.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_painter_free(t)}constructor(t,e,r){var n=f(r,_.__wbindgen_malloc,_.__wbindgen_realloc),a=g,c=_.painter_new(t,e,n,a);return I.__wrap(c)}static new_with_canvas(t,e,r){var n=_.painter_new_with_canvas(t,e,d(r));return I.__wrap(n)}set_square_outline(t){_.painter_set_square_outline(this.ptr,d(t))}set_outline_width(t){_.painter_set_outline_width(this.ptr,t)}set_draw_outline(t){_.painter_set_draw_outline(this.ptr,t)}reset_dimensions(){_.painter_reset_dimensions(this.ptr)}validate_board_dim(t){return k(t,S),0!==_.painter_validate_board_dim(this.ptr,t.ptr)}draw(t){k(t,S),_.painter_draw(this.ptr,t.ptr)}}class W{static __wrap(t){const e=Object.create(W.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_piece_free(t)}get team(){return _.__wbg_get_piece_team(this.ptr)>>>0}set team(t){_.__wbg_set_piece_team(this.ptr,t)}get strength(){return _.__wbg_get_piece_strength(this.ptr)>>>0}set strength(t){_.__wbg_set_piece_strength(this.ptr,t)}constructor(t,e){var r=_.piece_new(t,e);return W.__wrap(r)}}class A{static __wrap(t){const e=Object.create(A.prototype);return e.ptr=t,e}__destroy_into_raw(){const t=this.ptr;return this.ptr=0,t}free(){const t=this.__destroy_into_raw();_.__wbg_square_free(t)}get occupant(){var t=_.__wbg_get_square_occupant(this.ptr);return 0===t?void 0:W.__wrap(t)}set occupant(t){let e=0;y(t)||(k(t,W),e=t.ptr,t.ptr=0),_.__wbg_set_square_occupant(this.ptr,e)}get state(){return _.__wbg_get_square_state(this.ptr)>>>0}set state(t){_.__wbg_set_square_state(this.ptr,t)}constructor(t,e){let r=0;y(e)||(k(e,W),r=e.ptr,e.ptr=0);var n=_.square_new(t,r);return A.__wrap(n)}static pc(t,e){var r=_.square_pc(t,e);return A.__wrap(r)}static empty(){var t=_.square_empty();return A.__wrap(t)}static unplay(){var t=_.square_unplay();return A.__wrap(t)}}function C(t){!function(t){const e=i(t);(function(t){t<36||(c[t]=o,o=t)})(t)}(t)}function U(t,e){return d(l(t,e))}function $(){return d(new Error)}function M(t,e){var r=f(i(e).stack,_.__wbindgen_malloc,_.__wbindgen_realloc),n=g;v()[t/4+1]=n,v()[t/4+0]=r}function D(t,e){try{console.error(l(t,e))}finally{_.__wbindgen_free(t,e)}}function J(t){return i(t)instanceof Window}function P(t){var e=i(t).document;return y(e)?0:d(e)}function R(t,e,r){var n=i(t).getElementById(l(e,r));return y(n)?0:d(n)}function z(t){console.log(i(t))}function F(t){return i(t)instanceof CanvasRenderingContext2D}function N(t,e){i(t).strokeStyle=i(e)}function Y(t,e){i(t).fillStyle=i(e)}function K(t,e){i(t).lineWidth=e}function L(t){i(t).beginPath()}function Q(t){i(t).fill()}function Z(t){i(t).stroke()}function X(){return T((function(t,e,r,n,_,a){i(t).arc(e,r,n,_,a)}),arguments)}function H(t,e,r,n,_){i(t).fillRect(e,r,n,_)}function G(t,e,r,n,_){i(t).strokeRect(e,r,n,_)}function V(t){return i(t)instanceof HTMLCanvasElement}function tt(t,e){i(t).width=e>>>0}function et(t,e){i(t).height=e>>>0}function rt(){return T((function(t,e,r){var n=i(t).getContext(l(e,r));return y(n)?0:d(n)}),arguments)}function nt(t,e){return d(new Function(l(t,e)))}function _t(){return T((function(t,e){return d(i(t).call(i(e)))}),arguments)}function at(){return T((function(){return d(self.self)}),arguments)}function ct(){return T((function(){return d(window.window)}),arguments)}function it(){return T((function(){return d(globalThis.globalThis)}),arguments)}function ot(){return T((function(){return d(r.g.global)}),arguments)}function st(t){return void 0===i(t)}function ut(t){return d(i(t))}function pt(t,e){var r=f(b(i(e)),_.__wbindgen_malloc,_.__wbindgen_realloc),n=g;v()[t/4+1]=n,v()[t/4+0]=r}function lt(t,e){throw new Error(l(t,e))}}))},813:(t,e,r)=>{"use strict";var n=([n])=>r.v(e,t.id,"cc96734576b00860ab91",{"./draught_bg.js":{__wbindgen_object_drop_ref:n.ug,__wbindgen_string_new:n.h4,__wbg_new_59cb74e423758ede:n.h9,__wbg_stack_558ba5917b466edd:n.Dz,__wbg_error_4bb6c2a97407129a:n.kF,__wbg_instanceof_Window_11e25482011fc506:n.s8,__wbg_document_5aff8cd83ef968f5:n.WB,__wbg_getElementById_b180ea4ada06a837:n.cP,__wbg_log_9a99fb1af846153b:n.a,__wbg_instanceof_CanvasRenderingContext2d_779e79c4121aa91b:n.l_,__wbg_setstrokeStyle_2939ee453716e462:n.U_,__wbg_setfillStyle_af790b5baf4d3210:n.EN,__wbg_setlineWidth_3e6b1837ae38d099:n.qu,__wbg_beginPath_2378575e37027ad3:n.Wg,__wbg_fill_558339447ed6ad43:n.B3,__wbg_stroke_c1e0313c58997dcf:n.I6,__wbg_arc_fffd87d9113dce32:n.Qb,__wbg_fillRect_46ffc8d2cef7e298:n.cI,__wbg_strokeRect_7ea34fad8a7f0fe2:n.QK,__wbg_instanceof_HtmlCanvasElement_fd3cbbe3906d7792:n.Md,__wbg_setwidth_f3c88eb520ba8d47:n.ox,__wbg_setheight_5a1abba41e35c42a:n.ES,__wbg_getContext_813df131fcbd6e91:n.Ae,__wbg_newnoargs_9fdd8f3961dd1bee:n.UL,__wbg_call_ba36642bd901572b:n.qw,__wbg_self_bb69a836a72ec6e9:n.tS,__wbg_window_3304fc4b414c9693:n.R$,__wbg_globalThis_e0d21cabc6630763:n.md,__wbg_global_8463719227271676:n.IF,__wbindgen_is_undefined:n.XP,__wbindgen_object_clone_ref:n.m_,__wbindgen_debug_string:n.fY,__wbindgen_throw:n.Or}});r.a(t,(t=>{var e=t([r(171)]);return e.then?e.then(n):n(e)}),1)},10:(t,e,r)=>{"use strict";r.a(t,(async t=>{r.r(e);var n=r(171),_=t([n]);n=(_.then?await _:_)[0];const a="human_turn.thinking",c="human_turn.from_selected";(0,n.wc)(),document.getElementById("status-p");const i=document.getElementById("status-d"),o=document.getElementById("team-p");document.getElementById("startBtn").onclick=w;let s=null,u=function(t,e="danger",r=!0){null!=s&&clearInterval(s),i.className=`alert alert-${e}`,i.innerText=t,i.hidden=!1,r&&(s=setTimeout((()=>{i.hidden=!0}),3e3))},p=a,l=null,d=null,b=[];w();const g=document.getElementById("game-canvas");function w(){l=new n.lA(8,8,3,n.SZ.Black),d=new n.Ck(480,480,"game-canvas"),l.set_painter(d),l.draw(),h(),p=a}function h(){switch(l.current_turn()){case n.SZ.White:o.innerText="⚪ White ⚪";break;case n.SZ.Black:o.innerText="🔴 Black 🔴"}}g.addEventListener("click",(t=>{var e=function(t,e){var r=t.getBoundingClientRect();return{x:e.clientX-r.left,y:e.clientY-r.top}}(g,t);!function(t){switch(p){case a:if(l.current_cell_state(t).state!=n.i0.Occupied)return;if(l.current_cell_state(t).occupant.team!=l.current_turn())return;b.push(t),p=c,l.set_selected(t),l.draw();break;case c:if(!b[0].eq(t)){if(l.current_cell_state(t).state!=n.i0.Empty)return;if(b.push(t),2!=b.length)return u(`Error: wrong number of clicks to process ${b.length}`),void console.error(`Error: wrong number of clicks to process ${b.length}`);switch(l.make_move(b[0],b[1])){case n.Tt.Allowed:break;case n.Tt.IllegalTrajectory:u("You can't move like that!");break;case n.Tt.JumpingSameTeam:u("You can't jump your own piece!");break;case n.Tt.NoJumpablePiece:u("There's nothing to jump!");break;case n.Tt.OccupiedDest:u("There's a piece there!");break;case n.Tt.OutOfBounds:u("That square's not on the board! (how have you managed that?)");break;case n.Tt.UnoccupiedSrc:u("There's no piece to move!");break;case n.Tt.Unplayable:u("That's not a playable square!");break;case n.Tt.WrongTeamSrc:u("That's not your piece!")}}l.clear_selected(),l.draw(),b=[],p=a;break;case"ai_turn":console.log("It's the AI's turn!")}h()}(new n.rh(Math.floor(e.y/480*8),Math.floor(e.x/480*8)))}))}))}}]); //# sourceMappingURL=10.bootstrap.js.map \ No newline at end of file diff --git a/10.bootstrap.js.map b/10.bootstrap.js.map index 4fc3621..cc31d1c 100644 --- a/10.bootstrap.js.map +++ b/10.bootstrap.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://draught/../pkg/draught_bg.js","webpack://draught/./index.js"],"names":["heap","Array","fill","undefined","getObject","idx","push","heap_next","length","cachedTextDecoder","TextDecoder","module","require","ignoreBOM","fatal","decode","cachegetUint8Memory0","getUint8Memory0","buffer","Uint8Array","getStringFromWasm0","ptr","len","subarray","addHeapObject","obj","debugString","val","type","description","name","isArray","debug","i","builtInMatches","exec","toString","call","className","JSON","stringify","_","Error","message","stack","WASM_VECTOR_LEN","cachedTextEncoder","TextEncoder","encodeString","encodeInto","arg","view","buf","encode","set","read","written","passStringToWasm0","malloc","realloc","mem","offset","code","charCodeAt","slice","cachegetInt32Memory0","getInt32Memory0","Int32Array","isLikeNone","x","_assertClass","instance","klass","init_wasm","handleError","f","args","apply","this","e","Object","freeze","Move","Jump","Team","Black","White","SquareState","Man","King","Empty","Occupied","Unplayable","Moveable","Allowed","UnoccupiedSrc","OccupiedDest","OutOfBounds","WrongTeamSrc","IllegalTrajectory","NoJumpablePiece","JumpingSameTeam","Board","create","prototype","__destroy_into_raw","arg0","ret","Square","__wrap","square","ptr0","BrdIdx","row","col","from","to","ptr1","from_square_occupant","Piece","ptr2","team","jumpee","from_occ","width","height","current_turn","board","piece_rows","other","Game","first_turn","canvas_id","canvas_width","canvas_height","len0","value","Painter","canvas","strength","state","occupant","__wbindgen_object_drop_ref","dropObject","takeObject","__wbindgen_string_new","arg1","__wbg_new_59cb74e423758ede","__wbg_stack_558ba5917b466edd","__wbg_error_4bb6c2a97407129a","console","error","__wbg_instanceof_Window_11e25482011fc506","Window","__wbg_document_5aff8cd83ef968f5","document","__wbg_getElementById_b180ea4ada06a837","arg2","getElementById","__wbg_log_9a99fb1af846153b","log","__wbg_instanceof_CanvasRenderingContext2d_779e79c4121aa91b","CanvasRenderingContext2D","__wbg_setstrokeStyle_2939ee453716e462","strokeStyle","__wbg_setfillStyle_af790b5baf4d3210","fillStyle","__wbg_setlineWidth_3e6b1837ae38d099","lineWidth","__wbg_beginPath_2378575e37027ad3","beginPath","__wbg_fill_558339447ed6ad43","__wbg_stroke_c1e0313c58997dcf","stroke","__wbg_arc_fffd87d9113dce32","arg3","arg4","arg5","arc","arguments","__wbg_fillRect_46ffc8d2cef7e298","fillRect","__wbg_strokeRect_7ea34fad8a7f0fe2","strokeRect","__wbg_instanceof_HtmlCanvasElement_fd3cbbe3906d7792","HTMLCanvasElement","__wbg_setwidth_f3c88eb520ba8d47","__wbg_setheight_5a1abba41e35c42a","__wbg_getContext_813df131fcbd6e91","getContext","__wbg_newnoargs_9fdd8f3961dd1bee","Function","__wbg_call_ba36642bd901572b","__wbg_self_bb69a836a72ec6e9","self","__wbg_window_3304fc4b414c9693","window","__wbg_globalThis_e0d21cabc6630763","globalThis","__wbg_global_8463719227271676","g","global","__wbindgen_is_undefined","__wbindgen_object_clone_ref","__wbindgen_debug_string","__wbindgen_throw","GameState","statusAlert","teamText","statusTimeout","setStatus","txt","alertType","hide","clearInterval","innerText","hidden","setTimeout","current_state","painter","clicks","game","set_painter","draw","updateTeamText","addEventListener","event","mousepos","evt","rect","getBoundingClientRect","clientX","left","y","clientY","top","getMousePos","cell_coord","current_cell_state","eq","make_move","process_canvas_click","Math","floor"],"mappings":"0iBAEA,MAAMA,EAAO,IAAIC,MAAM,IAAIC,UAAKC,GAIhC,SAASC,EAAUC,GAAO,OAAOL,EAAKK,GAFtCL,EAAKM,UAAKH,EAAW,MAAM,GAAM,GAIjC,IAAII,EAAYP,EAAKQ,OAgBrB,IAAIC,EAAoB,IAFoB,oBAAhBC,aAA8B,EAAIC,EAAOC,SAAS,QAAQF,YAAcA,aAE3D,QAAS,CAAEG,WAAW,EAAMC,OAAO,IAE5EL,EAAkBM,SAElB,IAAIC,EAAuB,KAC3B,SAASC,IAIL,OAH6B,OAAzBD,GAAiCA,EAAqBE,SAAW,kBACjEF,EAAuB,IAAIG,WAAW,kBAEnCH,EAGX,SAASI,EAAmBC,EAAKC,GAC7B,OAAOb,EAAkBM,OAAOE,IAAkBM,SAASF,EAAKA,EAAMC,IAG1E,SAASE,EAAcC,GACflB,IAAcP,EAAKQ,QAAQR,EAAKM,KAAKN,EAAKQ,OAAS,GACvD,MAAMH,EAAME,EAIZ,OAHAA,EAAYP,EAAKK,GAEjBL,EAAKK,GAAOoB,EACLpB,EAGX,SAASqB,EAAYC,GAEjB,MAAMC,SAAcD,EACpB,GAAY,UAARC,GAA4B,WAARA,GAA4B,MAAPD,EACzC,MAAQ,GAAGA,IAEf,GAAY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BACDA,EAAU,4BACV,MACJ,KAAK,kBACDA,EAAU,0BACV,MACJ,KAAK,iBACDA,EAAU,gEACV,MACJ,KAAK,mBACDA,EAAU,6BACV,MACJ,KAAK,gBACDA,EAAU,iCACV,MACJ,KAAK,kBACDA,EAAU,0BAMtBW,EAAKE,OACLH,EAAS,GACTF,EAAgBZ,EAEhB,MACJ,IA1IK,UA2IDxD,QAAQU,IAAI,uBAIpBgE,IAjGAiB,CALW,IAAI,KACXC,KAAKC,MAAOhB,EAASM,EAxDP,IAGD,GAsDbS,KAAKC,MAAOhB,EAAS9J,EA1DR,IAGD","file":"10.bootstrap.js","sourcesContent":["import * as wasm from './draught_bg.wasm';\n\nconst heap = new Array(32).fill(undefined);\n\nheap.push(undefined, null, true, false);\n\nfunction getObject(idx) { return heap[idx]; }\n\nlet heap_next = heap.length;\n\nfunction dropObject(idx) {\n if (idx < 36) return;\n heap[idx] = heap_next;\n heap_next = idx;\n}\n\nfunction takeObject(idx) {\n const ret = getObject(idx);\n dropObject(idx);\n return ret;\n}\n\nconst lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;\n\nlet cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n\ncachedTextDecoder.decode();\n\nlet cachegetUint8Memory0 = null;\nfunction getUint8Memory0() {\n if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {\n cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachegetUint8Memory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));\n}\n\nfunction addHeapObject(obj) {\n if (heap_next === heap.length) heap.push(heap.length + 1);\n const idx = heap_next;\n heap_next = heap[idx];\n\n heap[idx] = obj;\n return idx;\n}\n\nfunction debugString(val) {\n // primitive types\n const type = typeof val;\n if (type == 'number' || type == 'boolean' || val == null) {\n return `${val}`;\n }\n if (type == 'string') {\n return `\"${val}\"`;\n }\n if (type == 'symbol') {\n const description = val.description;\n if (description == null) {\n return 'Symbol';\n } else {\n return `Symbol(${description})`;\n }\n }\n if (type == 'function') {\n const name = val.name;\n if (typeof name == 'string' && name.length > 0) {\n return `Function(${name})`;\n } else {\n return 'Function';\n }\n }\n // objects\n if (Array.isArray(val)) {\n const length = val.length;\n let debug = '[';\n if (length > 0) {\n debug += debugString(val[0]);\n }\n for(let i = 1; i < length; i++) {\n debug += ', ' + debugString(val[i]);\n }\n debug += ']';\n return debug;\n }\n // Test for built-in\n const builtInMatches = /\\[object ([^\\]]+)\\]/.exec(toString.call(val));\n let className;\n if (builtInMatches.length > 1) {\n className = builtInMatches[1];\n } else {\n // Failed to match the standard '[object ClassName]'\n return toString.call(val);\n }\n if (className == 'Object') {\n // we're a user defined class or Object\n // JSON.stringify avoids problems with cycles, and is generally much\n // easier than looping through ownProperties of `val`.\n try {\n return 'Object(' + JSON.stringify(val) + ')';\n } catch (_) {\n return 'Object';\n }\n }\n // errors\n if (val instanceof Error) {\n return `${val.name}: ${val.message}\\n${val.stack}`;\n }\n // TODO we could test for more things here, like `Set`s and `Map`s.\n return className;\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nconst lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;\n\nlet cachedTextEncoder = new lTextEncoder('utf-8');\n\nconst encodeString = (typeof cachedTextEncoder.encodeInto === 'function'\n ? function (arg, view) {\n return cachedTextEncoder.encodeInto(arg, view);\n}\n : function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n});\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length);\n getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len);\n\n const mem = getUint8Memory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3);\n const view = getUint8Memory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nlet cachegetInt32Memory0 = null;\nfunction getInt32Memory0() {\n if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {\n cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);\n }\n return cachegetInt32Memory0;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nfunction _assertClass(instance, klass) {\n if (!(instance instanceof klass)) {\n throw new Error(`expected instance of ${klass.name}`);\n }\n return instance.ptr;\n}\n/**\n*/\nexport function init_wasm() {\n wasm.init_wasm();\n}\n\nfunction handleError(f, args) {\n try {\n return f.apply(this, args);\n } catch (e) {\n wasm.__wbindgen_exn_store(addHeapObject(e));\n }\n}\n/**\n*/\nexport const MoveType = Object.freeze({ Move:0,\"0\":\"Move\",Jump:1,\"1\":\"Jump\", });\n/**\n*/\nexport const Team = Object.freeze({ Black:0,\"0\":\"Black\",White:1,\"1\":\"White\", });\n/**\n*/\nexport const Strength = Object.freeze({ Man:0,\"0\":\"Man\",King:1,\"1\":\"King\", });\n/**\n*/\nexport const SquareState = Object.freeze({ Empty:0,\"0\":\"Empty\",Occupied:1,\"1\":\"Occupied\",Unplayable:2,\"2\":\"Unplayable\", });\n/**\n*/\nexport const Moveable = Object.freeze({ Allowed:0,\"0\":\"Allowed\",UnoccupiedSrc:1,\"1\":\"UnoccupiedSrc\",OccupiedDest:2,\"2\":\"OccupiedDest\",OutOfBounds:3,\"3\":\"OutOfBounds\",Unplayable:4,\"4\":\"Unplayable\",WrongTeamSrc:5,\"5\":\"WrongTeamSrc\",IllegalTrajectory:6,\"6\":\"IllegalTrajectory\",NoJumpablePiece:7,\"7\":\"NoJumpablePiece\",JumpingSameTeam:8,\"8\":\"JumpingSameTeam\", });\n/**\n* Single state of a checkers board\n*/\nexport class Board {\n\n static __wrap(ptr) {\n const obj = Object.create(Board.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_board_free(ptr);\n }\n /**\n * @returns {number}\n */\n get width() {\n var ret = wasm.__wbg_get_board_width(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set width(arg0) {\n wasm.__wbg_set_board_width(this.ptr, arg0);\n }\n /**\n * @returns {number}\n */\n get height() {\n var ret = wasm.__wbg_get_board_height(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set height(arg0) {\n wasm.__wbg_set_board_height(this.ptr, arg0);\n }\n /**\n * @returns {number}\n */\n get current_turn() {\n var ret = wasm.__wbg_get_board_current_turn(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set current_turn(arg0) {\n wasm.__wbg_set_board_current_turn(this.ptr, arg0);\n }\n /**\n * Get a copy of a board square by 1D array index\n * @param {number} idx\n * @returns {Square}\n */\n cell(idx) {\n var ret = wasm.board_cell(this.ptr, idx);\n return Square.__wrap(ret);\n }\n /**\n * Get a copy of a board square by 1D array index\n * @param {number} idx\n * @param {Square} square\n */\n set_cell(idx, square) {\n _assertClass(square, Square);\n var ptr0 = square.ptr;\n square.ptr = 0;\n wasm.board_set_cell(this.ptr, idx, ptr0);\n }\n /**\n * Get a copy of a board square by 2D [`BrdIdx`] index\n * @param {BrdIdx} idx\n * @returns {Square}\n */\n grid_cell(idx) {\n _assertClass(idx, BrdIdx);\n var ptr0 = idx.ptr;\n idx.ptr = 0;\n var ret = wasm.board_grid_cell(this.ptr, ptr0);\n return Square.__wrap(ret);\n }\n /**\n * Transform a 2D row/column board index into a single 1D index for use with [`Board::cells`]\n * @param {number} row\n * @param {number} col\n * @returns {number}\n */\n cell_index(row, col) {\n var ret = wasm.board_cell_index(this.ptr, row, col);\n return ret >>> 0;\n }\n /**\n * Similar to [`Board::cell_index`] but with a [`BrdIdx`] instead of separate indices. Transform a 2D row/column board index into a single 1D index for use with [`Board::cells`]\n * @param {BrdIdx} idx\n * @returns {number}\n */\n cell_idx(idx) {\n _assertClass(idx, BrdIdx);\n var ptr0 = idx.ptr;\n idx.ptr = 0;\n var ret = wasm.board_cell_idx(this.ptr, ptr0);\n return ret >>> 0;\n }\n /**\n * Transform a 1D array index (for [`Board::cells`]) into a 2D game board index (by row/col)\n * @param {number} idx\n * @returns {BrdIdx}\n */\n board_index(idx) {\n var ret = wasm.board_board_index(this.ptr, idx);\n return BrdIdx.__wrap(ret);\n }\n /**\n * Check whether a move given by source and destination indices is legal\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {number}\n */\n can_move(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.board_can_move(this.ptr, ptr0, ptr1);\n return ret >>> 0;\n }\n /**\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @param {Piece} from_square_occupant\n * @returns {number}\n */\n validate_man_move(from, to, from_square_occupant) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n _assertClass(from_square_occupant, Piece);\n var ptr2 = from_square_occupant.ptr;\n from_square_occupant.ptr = 0;\n var ret = wasm.board_validate_man_move(this.ptr, ptr0, ptr1, ptr2);\n return ret >>> 0;\n }\n /**\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @param {Piece} from_square_occupant\n * @returns {number}\n */\n validate_king_move(from, to, from_square_occupant) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n _assertClass(from_square_occupant, Piece);\n var ptr2 = from_square_occupant.ptr;\n from_square_occupant.ptr = 0;\n var ret = wasm.board_validate_king_move(this.ptr, ptr0, ptr1, ptr2);\n return ret >>> 0;\n }\n /**\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {number}\n */\n jumpee_idx(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.board_jumpee_idx(this.ptr, ptr0, ptr1);\n return ret >>> 0;\n }\n /**\n * Get a pointer to the backing array of board squares, [`Board::cells`]\n * @returns {number}\n */\n cells() {\n var ret = wasm.board_cells(this.ptr);\n return ret;\n }\n /**\n * Get the number of board squares\n * @returns {number}\n */\n num_cells() {\n var ret = wasm.board_num_cells(this.ptr);\n return ret >>> 0;\n }\n /**\n * Get the number of remaining pieces\n * @returns {number}\n */\n num_pieces() {\n var ret = wasm.board_num_pieces(this.ptr);\n return ret >>> 0;\n }\n /**\n * Get the number of remaining pieces for a player\n * @param {number} team\n * @returns {number}\n */\n num_player(team) {\n var ret = wasm.board_num_player(this.ptr, team);\n return ret >>> 0;\n }\n /**\n * Get the score value, Black - White pieces\n * @returns {number}\n */\n score() {\n var ret = wasm.board_score(this.ptr);\n return ret;\n }\n /**\n * Get the state of a board square by 1D array index\n * @param {number} idx\n * @returns {number}\n */\n cell_state(idx) {\n var ret = wasm.board_cell_state(this.ptr, idx);\n return ret >>> 0;\n }\n /**\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {Board}\n */\n apply_move(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.board_apply_move(this.ptr, ptr0, ptr1);\n return Board.__wrap(ret);\n }\n /**\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {Board}\n */\n apply_jump(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.board_apply_jump(this.ptr, ptr0, ptr1);\n return Board.__wrap(ret);\n }\n /**\n * Unwrap the jumpee piece from the square and [`Board::check_jumpee_team`] with [`Moveable`] response\n * @param {Square} jumpee\n * @param {Piece} from_occ\n * @returns {number}\n */\n static validate_jumpee(jumpee, from_occ) {\n _assertClass(jumpee, Square);\n var ptr0 = jumpee.ptr;\n jumpee.ptr = 0;\n _assertClass(from_occ, Piece);\n var ptr1 = from_occ.ptr;\n from_occ.ptr = 0;\n var ret = wasm.board_validate_jumpee(ptr0, ptr1);\n return ret >>> 0;\n }\n /**\n * Check that the source piece and the jumpee are of opposing teams\n * @param {Piece} from\n * @param {Piece} jumpee\n * @returns {boolean}\n */\n static check_jumpee_team(from, jumpee) {\n _assertClass(from, Piece);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(jumpee, Piece);\n var ptr1 = jumpee.ptr;\n jumpee.ptr = 0;\n var ret = wasm.board_check_jumpee_team(ptr0, ptr1);\n return ret !== 0;\n }\n /**\n * Initialise a game board without game pieces\n * @param {number} width\n * @param {number} height\n * @param {number} current_turn\n */\n constructor(width, height, current_turn) {\n var ret = wasm.board_new(width, height, current_turn);\n return Board.__wrap(ret);\n }\n /**\n * Reset the given board to a starting layout with 3 rows of opposing pieces\n * @param {Board} board\n * @param {number} piece_rows\n * @returns {Board}\n */\n static init_game(board, piece_rows) {\n _assertClass(board, Board);\n var ptr0 = board.ptr;\n board.ptr = 0;\n var ret = wasm.board_init_game(ptr0, piece_rows);\n return Board.__wrap(ret);\n }\n}\n/**\n* Rank 2 tensor index to identify a board square by row and column\n*/\nexport class BrdIdx {\n\n static __wrap(ptr) {\n const obj = Object.create(BrdIdx.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_brdidx_free(ptr);\n }\n /**\n * @returns {number}\n */\n get row() {\n var ret = wasm.__wbg_get_brdidx_row(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set row(arg0) {\n wasm.__wbg_set_brdidx_row(this.ptr, arg0);\n }\n /**\n * @returns {number}\n */\n get col() {\n var ret = wasm.__wbg_get_brdidx_col(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set col(arg0) {\n wasm.__wbg_set_brdidx_col(this.ptr, arg0);\n }\n /**\n * @param {number} row\n * @param {number} col\n */\n constructor(row, col) {\n var ret = wasm.brdidx_from(row, col);\n return BrdIdx.__wrap(ret);\n }\n /**\n * @param {BrdIdx} other\n * @returns {boolean}\n */\n eq(other) {\n _assertClass(other, BrdIdx);\n var ret = wasm.brdidx_eq(this.ptr, other.ptr);\n return ret !== 0;\n }\n}\n/**\n* Root-level structure for managing the game as a collection of board states\n*/\nexport class Game {\n\n static __wrap(ptr) {\n const obj = Object.create(Game.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_game_free(ptr);\n }\n /**\n * Get pointer to current board's squares\n * @returns {number}\n */\n current_board_cells() {\n var ret = wasm.game_current_board_cells(this.ptr);\n return ret;\n }\n /**\n * Get pointer to current board's squares\n * @returns {number}\n */\n current_board_len() {\n var ret = wasm.game_current_board_len(this.ptr);\n return ret >>> 0;\n }\n /**\n * Current turn's team\n * @returns {number}\n */\n current_turn() {\n var ret = wasm.game_current_turn(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {BrdIdx} idx\n * @returns {Square}\n */\n current_cell_state(idx) {\n _assertClass(idx, BrdIdx);\n var ret = wasm.game_current_cell_state(this.ptr, idx.ptr);\n return Square.__wrap(ret);\n }\n /**\n * Attempt to make a move given a source and destination index\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {number}\n */\n make_move(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.game_make_move(this.ptr, ptr0, ptr1);\n return ret >>> 0;\n }\n /**\n * Update board state with given move and push new board into current state\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n */\n execute_move(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n wasm.game_execute_move(this.ptr, ptr0, ptr1);\n }\n /**\n * Update board state with given jump move and push new board into current state\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n */\n execute_jump(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n wasm.game_execute_jump(this.ptr, ptr0, ptr1);\n }\n /**\n * Push current board into the previous turns and set given board to current\n * @param {Board} board\n */\n push_new_board(board) {\n _assertClass(board, Board);\n var ptr0 = board.ptr;\n board.ptr = 0;\n wasm.game_push_new_board(this.ptr, ptr0);\n }\n /**\n * Set current board to given\n * @param {Board} board\n */\n set_current(board) {\n _assertClass(board, Board);\n var ptr0 = board.ptr;\n board.ptr = 0;\n wasm.game_set_current(this.ptr, ptr0);\n }\n /**\n * @param {number} width\n * @param {number} height\n * @param {number} piece_rows\n * @param {number} first_turn\n */\n constructor(width, height, piece_rows, first_turn) {\n var ret = wasm.game_new(width, height, piece_rows, first_turn);\n return Game.__wrap(ret);\n }\n /**\n * @param {number} width\n * @param {number} height\n * @param {number} piece_rows\n * @param {number} first_turn\n * @param {string} canvas_id\n * @param {number} canvas_width\n * @param {number} canvas_height\n * @returns {Game}\n */\n static new_with_canvas(width, height, piece_rows, first_turn, canvas_id, canvas_width, canvas_height) {\n var ptr0 = passStringToWasm0(canvas_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len0 = WASM_VECTOR_LEN;\n var ret = wasm.game_new_with_canvas(width, height, piece_rows, first_turn, ptr0, len0, canvas_width, canvas_height);\n return Game.__wrap(ret);\n }\n /**\n * @param {Painter} value\n */\n set_painter(value) {\n _assertClass(value, Painter);\n var ptr0 = value.ptr;\n value.ptr = 0;\n wasm.game_set_painter(this.ptr, ptr0);\n }\n /**\n */\n draw() {\n wasm.game_draw(this.ptr);\n }\n}\n/**\n* Used to paint boards onto HTML canvases\n*/\nexport class Painter {\n\n static __wrap(ptr) {\n const obj = Object.create(Painter.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_painter_free(ptr);\n }\n /**\n * Default constructor which queries for canvas by ID\n * @param {number} width\n * @param {number} height\n * @param {string} canvas_id\n */\n constructor(width, height, canvas_id) {\n var ptr0 = passStringToWasm0(canvas_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len0 = WASM_VECTOR_LEN;\n var ret = wasm.painter_new(width, height, ptr0, len0);\n return Painter.__wrap(ret);\n }\n /**\n * Constructor with given canvas element\n * @param {number} width\n * @param {number} height\n * @param {HTMLCanvasElement} canvas\n * @returns {Painter}\n */\n static new_with_canvas(width, height, canvas) {\n var ret = wasm.painter_new_with_canvas(width, height, addHeapObject(canvas));\n return Painter.__wrap(ret);\n }\n /**\n * Set new square outline colour value\n * @param {any} value\n */\n set_square_outline(value) {\n wasm.painter_set_square_outline(this.ptr, addHeapObject(value));\n }\n /**\n * Set new line width for outlining squares\n * @param {number} value\n */\n set_outline_width(value) {\n wasm.painter_set_outline_width(this.ptr, value);\n }\n /**\n * Set whether squares are outlined\n * @param {boolean} value\n */\n set_draw_outline(value) {\n wasm.painter_set_draw_outline(this.ptr, value);\n }\n /**\n * Reset the canvas dimensions to the given width and height\n */\n reset_dimensions() {\n wasm.painter_reset_dimensions(this.ptr);\n }\n /**\n * Check whether given canvas dimensions divide evenly by given board dimenions\n * @param {Board} board\n * @returns {boolean}\n */\n validate_board_dim(board) {\n _assertClass(board, Board);\n var ret = wasm.painter_validate_board_dim(this.ptr, board.ptr);\n return ret !== 0;\n }\n /**\n * Draw a board onto the canvas\n * @param {Board} board\n */\n draw(board) {\n _assertClass(board, Board);\n wasm.painter_draw(this.ptr, board.ptr);\n }\n}\n/**\n* Game piece given by its team and strength (normal or kinged)\n*/\nexport class Piece {\n\n static __wrap(ptr) {\n const obj = Object.create(Piece.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_piece_free(ptr);\n }\n /**\n * @returns {number}\n */\n get team() {\n var ret = wasm.__wbg_get_piece_team(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set team(arg0) {\n wasm.__wbg_set_piece_team(this.ptr, arg0);\n }\n /**\n * @returns {number}\n */\n get strength() {\n var ret = wasm.__wbg_get_piece_strength(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set strength(arg0) {\n wasm.__wbg_set_piece_strength(this.ptr, arg0);\n }\n /**\n * @param {number} team\n * @param {number} strength\n */\n constructor(team, strength) {\n var ret = wasm.piece_new(team, strength);\n return Piece.__wrap(ret);\n }\n}\n/**\n*/\nexport class Player {\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_player_free(ptr);\n }\n}\n/**\n* Board squares given by a state and a possible occupying game piece\n*/\nexport class Square {\n\n static __wrap(ptr) {\n const obj = Object.create(Square.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_square_free(ptr);\n }\n /**\n * Game piece if square is occupied\n * @returns {Piece | undefined}\n */\n get occupant() {\n var ret = wasm.__wbg_get_square_occupant(this.ptr);\n return ret === 0 ? undefined : Piece.__wrap(ret);\n }\n /**\n * Game piece if square is occupied\n * @param {Piece | undefined} arg0\n */\n set occupant(arg0) {\n let ptr0 = 0;\n if (!isLikeNone(arg0)) {\n _assertClass(arg0, Piece);\n ptr0 = arg0.ptr;\n arg0.ptr = 0;\n }\n wasm.__wbg_set_square_occupant(this.ptr, ptr0);\n }\n /**\n * Description of whether the square is occupied or an unplayable, i.e. off-lattice square\n * @returns {number}\n */\n get state() {\n var ret = wasm.__wbg_get_square_state(this.ptr);\n return ret >>> 0;\n }\n /**\n * Description of whether the square is occupied or an unplayable, i.e. off-lattice square\n * @param {number} arg0\n */\n set state(arg0) {\n wasm.__wbg_set_square_state(this.ptr, arg0);\n }\n /**\n * Standard constructor function to form square from state and occupant\n * @param {number} state\n * @param {Piece | undefined} occupant\n */\n constructor(state, occupant) {\n let ptr0 = 0;\n if (!isLikeNone(occupant)) {\n _assertClass(occupant, Piece);\n ptr0 = occupant.ptr;\n occupant.ptr = 0;\n }\n var ret = wasm.square_new(state, ptr0);\n return Square.__wrap(ret);\n }\n /**\n * Helper function for a well-formed piece square by team and strength\n * @param {number} team\n * @param {number} strength\n * @returns {Square}\n */\n static pc(team, strength) {\n var ret = wasm.square_pc(team, strength);\n return Square.__wrap(ret);\n }\n /**\n * Helper function for a well-formed empty square\n * @returns {Square}\n */\n static empty() {\n var ret = wasm.square_empty();\n return Square.__wrap(ret);\n }\n /**\n * Helper function for a well-formed unplayable square\n * @returns {Square}\n */\n static unplay() {\n var ret = wasm.square_unplay();\n return Square.__wrap(ret);\n }\n}\n\nexport function __wbindgen_object_drop_ref(arg0) {\n takeObject(arg0);\n};\n\nexport function __wbindgen_string_new(arg0, arg1) {\n var ret = getStringFromWasm0(arg0, arg1);\n return addHeapObject(ret);\n};\n\nexport function __wbg_new_59cb74e423758ede() {\n var ret = new Error();\n return addHeapObject(ret);\n};\n\nexport function __wbg_stack_558ba5917b466edd(arg0, arg1) {\n var ret = getObject(arg1).stack;\n var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len0 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len0;\n getInt32Memory0()[arg0 / 4 + 0] = ptr0;\n};\n\nexport function __wbg_error_4bb6c2a97407129a(arg0, arg1) {\n try {\n console.error(getStringFromWasm0(arg0, arg1));\n } finally {\n wasm.__wbindgen_free(arg0, arg1);\n }\n};\n\nexport function __wbg_instanceof_Window_11e25482011fc506(arg0) {\n var ret = getObject(arg0) instanceof Window;\n return ret;\n};\n\nexport function __wbg_document_5aff8cd83ef968f5(arg0) {\n var ret = getObject(arg0).document;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n};\n\nexport function __wbg_getElementById_b180ea4ada06a837(arg0, arg1, arg2) {\n var ret = getObject(arg0).getElementById(getStringFromWasm0(arg1, arg2));\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n};\n\nexport function __wbg_log_9a99fb1af846153b(arg0) {\n console.log(getObject(arg0));\n};\n\nexport function __wbg_instanceof_CanvasRenderingContext2d_779e79c4121aa91b(arg0) {\n var ret = getObject(arg0) instanceof CanvasRenderingContext2D;\n return ret;\n};\n\nexport function __wbg_setstrokeStyle_2939ee453716e462(arg0, arg1) {\n getObject(arg0).strokeStyle = getObject(arg1);\n};\n\nexport function __wbg_setfillStyle_af790b5baf4d3210(arg0, arg1) {\n getObject(arg0).fillStyle = getObject(arg1);\n};\n\nexport function __wbg_setlineWidth_3e6b1837ae38d099(arg0, arg1) {\n getObject(arg0).lineWidth = arg1;\n};\n\nexport function __wbg_beginPath_2378575e37027ad3(arg0) {\n getObject(arg0).beginPath();\n};\n\nexport function __wbg_fill_558339447ed6ad43(arg0) {\n getObject(arg0).fill();\n};\n\nexport function __wbg_stroke_c1e0313c58997dcf(arg0) {\n getObject(arg0).stroke();\n};\n\nexport function __wbg_arc_fffd87d9113dce32() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {\n getObject(arg0).arc(arg1, arg2, arg3, arg4, arg5);\n}, arguments) };\n\nexport function __wbg_fillRect_46ffc8d2cef7e298(arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).fillRect(arg1, arg2, arg3, arg4);\n};\n\nexport function __wbg_strokeRect_7ea34fad8a7f0fe2(arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).strokeRect(arg1, arg2, arg3, arg4);\n};\n\nexport function __wbg_instanceof_HtmlCanvasElement_fd3cbbe3906d7792(arg0) {\n var ret = getObject(arg0) instanceof HTMLCanvasElement;\n return ret;\n};\n\nexport function __wbg_setwidth_f3c88eb520ba8d47(arg0, arg1) {\n getObject(arg0).width = arg1 >>> 0;\n};\n\nexport function __wbg_setheight_5a1abba41e35c42a(arg0, arg1) {\n getObject(arg0).height = arg1 >>> 0;\n};\n\nexport function __wbg_getContext_813df131fcbd6e91() { return handleError(function (arg0, arg1, arg2) {\n var ret = getObject(arg0).getContext(getStringFromWasm0(arg1, arg2));\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_newnoargs_9fdd8f3961dd1bee(arg0, arg1) {\n var ret = new Function(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n};\n\nexport function __wbg_call_ba36642bd901572b() { return handleError(function (arg0, arg1) {\n var ret = getObject(arg0).call(getObject(arg1));\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_self_bb69a836a72ec6e9() { return handleError(function () {\n var ret = self.self;\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_window_3304fc4b414c9693() { return handleError(function () {\n var ret = window.window;\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_globalThis_e0d21cabc6630763() { return handleError(function () {\n var ret = globalThis.globalThis;\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_global_8463719227271676() { return handleError(function () {\n var ret = global.global;\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbindgen_is_undefined(arg0) {\n var ret = getObject(arg0) === undefined;\n return ret;\n};\n\nexport function __wbindgen_object_clone_ref(arg0) {\n var ret = getObject(arg0);\n return addHeapObject(ret);\n};\n\nexport function __wbindgen_debug_string(arg0, arg1) {\n var ret = debugString(getObject(arg1));\n var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len0 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len0;\n getInt32Memory0()[arg0 / 4 + 0] = ptr0;\n};\n\nexport function __wbindgen_throw(arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n};\n\n","import { Game, Board, BrdIdx, Painter, Team, init_wasm, Moveable, SquareState, Square } from \"draught\";\n// import { memory } from \"draught/draught_bg.wasm\";\n\n///////////////////\n// CONSTS\n///////////////////\n\nconst CANVAS_WIDTH = 480;\nconst CANVAS_HEIGHT = 480;\n\nconst BOARD_WIDTH = 8;\nconst BOARD_HEIGHT = 8;\n\nconst PIECE_ROWS = 3;\n\nconst STATUS_TIMEOUT = 3000;\n\nconst GameState = {\n HUMAN_TURN: {\n THINKING: \"human_turn.thinking\",\n FROM_SELECTED: \"human_turn.from_selected\"\n },\n AI_TURN: \"ai_turn\"\n}\n\n//////////////////\n// GAME STUFF\n//////////////////\n\ninit_wasm();\n\n// let board = new Board(BOARD_WIDTH, BOARD_HEIGHT, Team.Black);\n\nconst statusText = document.getElementById(\"status-p\");\nconst statusAlert = document.getElementById(\"status-d\");\nconst teamText = document.getElementById(\"team-p\");\n\n// const startBtn = document.getElementById(\"startBtn\");\n// startBtn.onclick = start_game;\n\nlet statusTimeout = null;\nlet setStatus = setStatusAlert;\n\nlet current_state = GameState.HUMAN_TURN.THINKING;\nlet painter = new Painter(CANVAS_WIDTH, CANVAS_HEIGHT, \"game-canvas\");\n// painter.draw(board);\n\nlet clicks = [];\n\nlet game = new Game(BOARD_WIDTH, BOARD_HEIGHT, PIECE_ROWS, Team.Black);\ngame.set_painter(painter);\ngame.draw();\n\nupdateTeamText();\n\n/////////////////\n// CANVAS\n/////////////////\n\nconst canvas = document.getElementById(\"game-canvas\");\ncanvas.addEventListener(\"click\", (event) => {\n var mousepos = getMousePos(canvas, event);\n // console.log(mousepos);\n var cell = new BrdIdx(\n Math.floor((mousepos.y / CANVAS_HEIGHT) * BOARD_HEIGHT),\n Math.floor((mousepos.x / CANVAS_WIDTH) * BOARD_WIDTH),\n );\n // console.log(cell);\n process_canvas_click(cell);\n})\n\n////////////////\n// FUNCS\n////////////////\n\nfunction start_game() {\n game = new Game(BOARD_WIDTH, BOARD_HEIGHT, PIECE_ROWS, Team.Black);\n game.set_painter(painter);\n game.draw();\n\n updateTeamText();\n current_state = GameState.HUMAN_TURN.THINKING;\n}\n\nfunction process_canvas_click(cell_coord) {\n\n switch(current_state) {\n case GameState.HUMAN_TURN.THINKING:\n if (game.current_cell_state(cell_coord).state != SquareState.Occupied ) {\n return;\n }\n\n if (game.current_cell_state(cell_coord).occupant.team != game.current_turn() ) {\n return;\n }\n\n console.log(\"Your turn, first piece picked\");\n\n clicks.push(cell_coord);\n current_state = GameState.HUMAN_TURN.FROM_SELECTED; \n \n break;\n case GameState.HUMAN_TURN.FROM_SELECTED:\n if (game.current_cell_state(cell_coord).state != SquareState.Empty ) {\n return;\n }\n\n console.log(\"Your turn, first piece already picked, picking second\");\n\n clicks.push(cell_coord);\n\n if (clicks.length != 2) {\n setStatus(`Error: wrong number of clicks to process ${clicks.length}`);\n console.error(`Error: wrong number of clicks to process ${clicks.length}`);\n\n return;\n }\n\n if (clicks[0].eq(clicks[1])) {\n setStatus(\"Move Cancelled\");\n } else {\n\n let status = game.make_move(clicks[0], clicks[1]);\n\n switch(status) {\n case Moveable.Allowed:\n break;\n case Moveable.IllegalTrajectory:\n setStatus(\"You can't move like that!\");\n break;\n case Moveable.JumpingSameTeam:\n setStatus(\"You can't jump your own piece!\");\n break;\n case Moveable.NoJumpablePiece:\n setStatus(\"There's nothing to jump!\");\n break;\n case Moveable.OccupiedDest:\n setStatus(\"There's a piece there!\");\n break;\n case Moveable.OutOfBounds:\n setStatus(\"That square's not on the board! (how have you managed that?)\");\n break;\n case Moveable.UnoccupiedSrc:\n setStatus(\"There's no piece to move!\");\n break;\n case Moveable.Unplayable:\n setStatus(\"That's not a playable square!\");\n break;\n case Moveable.WrongTeamSrc:\n setStatus(\"That's not your piece!\");\n break;\n }\n \n }\n\n game.draw();\n clicks = [];\n current_state = GameState.HUMAN_TURN.THINKING;\n \n break;\n case GameState.AI_TURN:\n console.log(\"It's the AI's turn!\");\n break;\n }\n\n updateTeamText();\n}\n\nfunction getMousePos(canvas, evt) {\n var rect = canvas.getBoundingClientRect();\n return {\n x: evt.clientX - rect.left,\n y: evt.clientY - rect.top\n };\n}\n\nfunction setStatusText(txt, hide = true) {\n if(statusTimeout != null) {\n clearInterval(statusTimeout);\n }\n\n statusText.innerText = txt;\n\n if(hide) {\n statusTimeout = setTimeout(() => {\n statusText.innerText = \"\";\n }, STATUS_TIMEOUT);\n }\n}\n\nfunction setStatusAlert(txt, alertType = \"danger\", hide = true) {\n if(statusTimeout != null) {\n clearInterval(statusTimeout);\n }\n\n statusAlert.className = `alert alert-${alertType}`;\n statusAlert.innerText = txt;\n statusAlert.hidden = false;\n\n if(hide) {\n statusTimeout = setTimeout(() => {\n statusAlert.hidden = true;\n }, STATUS_TIMEOUT);\n }\n}\n\nfunction updateTeamText(){\n let team = game.current_turn();\n switch(team) {\n case Team.White:\n teamText.innerText = \"⚪ White ⚪\";\n break;\n case Team.Black:\n teamText.innerText = \"🔴 Black 🔴\";\n break;\n }\n}\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://draught/../pkg/draught_bg.js","webpack://draught/./index.js"],"names":["heap","Array","fill","undefined","getObject","idx","push","heap_next","length","cachedTextDecoder","TextDecoder","module","require","ignoreBOM","fatal","decode","cachegetUint8Memory0","getUint8Memory0","buffer","Uint8Array","getStringFromWasm0","ptr","len","subarray","addHeapObject","obj","debugString","val","type","description","name","isArray","debug","i","builtInMatches","exec","toString","call","className","JSON","stringify","_","Error","message","stack","WASM_VECTOR_LEN","cachedTextEncoder","TextEncoder","encodeString","encodeInto","arg","view","buf","encode","set","read","written","passStringToWasm0","malloc","realloc","mem","offset","code","charCodeAt","slice","cachegetInt32Memory0","getInt32Memory0","Int32Array","isLikeNone","x","_assertClass","instance","klass","init_wasm","handleError","f","args","apply","this","e","Object","freeze","Move","Jump","Team","Black","White","SquareState","Man","King","Empty","Occupied","Unplayable","Moveable","Allowed","UnoccupiedSrc","OccupiedDest","OutOfBounds","WrongTeamSrc","IllegalTrajectory","NoJumpablePiece","JumpingSameTeam","Board","create","prototype","__destroy_into_raw","arg0","ret","Square","__wrap","square","ptr0","BrdIdx","row","col","from","to","ptr1","from_square_occupant","Piece","ptr2","team","jumpee","from_occ","width","height","current_turn","board","piece_rows","other","Game","first_turn","canvas_id","canvas_width","canvas_height","len0","value","Painter","canvas","strength","state","occupant","__wbindgen_object_drop_ref","dropObject","takeObject","__wbindgen_string_new","arg1","__wbg_new_59cb74e423758ede","__wbg_stack_558ba5917b466edd","__wbg_error_4bb6c2a97407129a","console","error","__wbg_instanceof_Window_11e25482011fc506","Window","__wbg_document_5aff8cd83ef968f5","document","__wbg_getElementById_b180ea4ada06a837","arg2","getElementById","__wbg_log_9a99fb1af846153b","log","__wbg_instanceof_CanvasRenderingContext2d_779e79c4121aa91b","CanvasRenderingContext2D","__wbg_setstrokeStyle_2939ee453716e462","strokeStyle","__wbg_setfillStyle_af790b5baf4d3210","fillStyle","__wbg_setlineWidth_3e6b1837ae38d099","lineWidth","__wbg_beginPath_2378575e37027ad3","beginPath","__wbg_fill_558339447ed6ad43","__wbg_stroke_c1e0313c58997dcf","stroke","__wbg_arc_fffd87d9113dce32","arg3","arg4","arg5","arc","arguments","__wbg_fillRect_46ffc8d2cef7e298","fillRect","__wbg_strokeRect_7ea34fad8a7f0fe2","strokeRect","__wbg_instanceof_HtmlCanvasElement_fd3cbbe3906d7792","HTMLCanvasElement","__wbg_setwidth_f3c88eb520ba8d47","__wbg_setheight_5a1abba41e35c42a","__wbg_getContext_813df131fcbd6e91","getContext","__wbg_newnoargs_9fdd8f3961dd1bee","Function","__wbg_call_ba36642bd901572b","__wbg_self_bb69a836a72ec6e9","self","__wbg_window_3304fc4b414c9693","window","__wbg_globalThis_e0d21cabc6630763","globalThis","__wbg_global_8463719227271676","g","global","__wbindgen_is_undefined","__wbindgen_object_clone_ref","__wbindgen_debug_string","__wbindgen_throw","GameState","statusAlert","teamText","onclick","start_game","statusTimeout","setStatus","txt","alertType","hide","clearInterval","innerText","hidden","setTimeout","current_state","game","painter","clicks","set_painter","draw","updateTeamText","addEventListener","event","mousepos","evt","rect","getBoundingClientRect","clientX","left","y","clientY","top","getMousePos","cell_coord","current_cell_state","set_selected","eq","make_move","clear_selected","process_canvas_click","Math","floor"],"mappings":"0iBAEA,MAAMA,EAAO,IAAIC,MAAM,IAAIC,UAAKC,GAIhC,SAASC,EAAUC,GAAO,OAAOL,EAAKK,GAFtCL,EAAKM,UAAKH,EAAW,MAAM,GAAM,GAIjC,IAAII,EAAYP,EAAKQ,OAgBrB,IAAIC,EAAoB,IAFoB,oBAAhBC,aAA8B,EAAIC,EAAOC,SAAS,QAAQF,YAAcA,aAE3D,QAAS,CAAEG,WAAW,EAAMC,OAAO,IAE5EL,EAAkBM,SAElB,IAAIC,E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EAAIM,QAAUL,EAAKM,KAvHXC,CAAYpG,EAAQ0F,IAwBvC,SAA8BW,GAE1B,OAAOnB,GAEH,KAAKd,EACD,GAAIe,EAAKmB,mBAAmBD,GAAYnG,OAAS,cAC7C,OAGJ,GAAIiF,EAAKmB,mBAAmBD,GAAYlG,SAASpB,MAAQoG,EAAK/F,eAC1D,OAKJiG,EAAOzN,KAAKyO,GACZnB,EAAgBd,EAChBe,EAAKoB,aAAaF,GAClBlB,EAAKI,OAEL,MAGJ,KAAKnB,EAID,IAAKiB,EAAO,GAAGmB,GAAGH,GAAa,CAE3B,GAAIlB,EAAKmB,mBAAmBD,GAAYnG,OAAS,WAC7C,OAOJ,GAFAmF,EAAOzN,KAAKyO,GAES,GAAjBhB,EAAOvN,OAIP,OAHA4M,EAAU,4CAA4CW,EAAOvN,eAC7D8I,QAAQC,MAAM,4CAA4CwE,EAAOvN,UAOrE,OAFaqN,EAAKsB,UAAUpB,EAAO,GAAIA,EAAO,KAG1C,KAAK,aACD,MACJ,KAAK,uBACDX,EAAU,6BACV,MACJ,KAAK,qBACDA,EAAU,kCACV,MACJ,KAAK,qBACDA,EAAU,4BACV,MACJ,KAAK,kBACDA,EAAU,0BACV,MACJ,KAAK,iBACDA,EAAU,gEACV,MACJ,KAAK,mBACDA,EAAU,6BACV,MACJ,KAAK,gBACDA,EAAU,iCACV,MACJ,KAAK,kBACDA,EAAU,2BAMtBS,EAAKuB,iBACLvB,EAAKI,OACLF,EAAS,GACTH,EAAgBd,EAEhB,MACJ,IA/IK,UAgJDxD,QAAQU,IAAI,uBAIpBkE,IAzGAmB,CALW,IAAI,KACXC,KAAKC,MAAOlB,EAASM,EArDP,IAGD,GAmDbW,KAAKC,MAAOlB,EAAShK,EAvDR,IAGD","file":"10.bootstrap.js","sourcesContent":["import * as wasm from './draught_bg.wasm';\n\nconst heap = new Array(32).fill(undefined);\n\nheap.push(undefined, null, true, false);\n\nfunction getObject(idx) { return heap[idx]; }\n\nlet heap_next = heap.length;\n\nfunction dropObject(idx) {\n if (idx < 36) return;\n heap[idx] = heap_next;\n heap_next = idx;\n}\n\nfunction takeObject(idx) {\n const ret = getObject(idx);\n dropObject(idx);\n return ret;\n}\n\nconst lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;\n\nlet cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n\ncachedTextDecoder.decode();\n\nlet cachegetUint8Memory0 = null;\nfunction getUint8Memory0() {\n if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {\n cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachegetUint8Memory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));\n}\n\nfunction addHeapObject(obj) {\n if (heap_next === heap.length) heap.push(heap.length + 1);\n const idx = heap_next;\n heap_next = heap[idx];\n\n heap[idx] = obj;\n return idx;\n}\n\nfunction debugString(val) {\n // primitive types\n const type = typeof val;\n if (type == 'number' || type == 'boolean' || val == null) {\n return `${val}`;\n }\n if (type == 'string') {\n return `\"${val}\"`;\n }\n if (type == 'symbol') {\n const description = val.description;\n if (description == null) {\n return 'Symbol';\n } else {\n return `Symbol(${description})`;\n }\n }\n if (type == 'function') {\n const name = val.name;\n if (typeof name == 'string' && name.length > 0) {\n return `Function(${name})`;\n } else {\n return 'Function';\n }\n }\n // objects\n if (Array.isArray(val)) {\n const length = val.length;\n let debug = '[';\n if (length > 0) {\n debug += debugString(val[0]);\n }\n for(let i = 1; i < length; i++) {\n debug += ', ' + debugString(val[i]);\n }\n debug += ']';\n return debug;\n }\n // Test for built-in\n const builtInMatches = /\\[object ([^\\]]+)\\]/.exec(toString.call(val));\n let className;\n if (builtInMatches.length > 1) {\n className = builtInMatches[1];\n } else {\n // Failed to match the standard '[object ClassName]'\n return toString.call(val);\n }\n if (className == 'Object') {\n // we're a user defined class or Object\n // JSON.stringify avoids problems with cycles, and is generally much\n // easier than looping through ownProperties of `val`.\n try {\n return 'Object(' + JSON.stringify(val) + ')';\n } catch (_) {\n return 'Object';\n }\n }\n // errors\n if (val instanceof Error) {\n return `${val.name}: ${val.message}\\n${val.stack}`;\n }\n // TODO we could test for more things here, like `Set`s and `Map`s.\n return className;\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nconst lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;\n\nlet cachedTextEncoder = new lTextEncoder('utf-8');\n\nconst encodeString = (typeof cachedTextEncoder.encodeInto === 'function'\n ? function (arg, view) {\n return cachedTextEncoder.encodeInto(arg, view);\n}\n : function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n});\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length);\n getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len);\n\n const mem = getUint8Memory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3);\n const view = getUint8Memory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nlet cachegetInt32Memory0 = null;\nfunction getInt32Memory0() {\n if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {\n cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);\n }\n return cachegetInt32Memory0;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nfunction _assertClass(instance, klass) {\n if (!(instance instanceof klass)) {\n throw new Error(`expected instance of ${klass.name}`);\n }\n return instance.ptr;\n}\n/**\n*/\nexport function init_wasm() {\n wasm.init_wasm();\n}\n\nfunction handleError(f, args) {\n try {\n return f.apply(this, args);\n } catch (e) {\n wasm.__wbindgen_exn_store(addHeapObject(e));\n }\n}\n/**\n*/\nexport const MoveType = Object.freeze({ Move:0,\"0\":\"Move\",Jump:1,\"1\":\"Jump\", });\n/**\n*/\nexport const Team = Object.freeze({ Black:0,\"0\":\"Black\",White:1,\"1\":\"White\", });\n/**\n*/\nexport const Strength = Object.freeze({ Man:0,\"0\":\"Man\",King:1,\"1\":\"King\", });\n/**\n*/\nexport const SquareState = Object.freeze({ Empty:0,\"0\":\"Empty\",Occupied:1,\"1\":\"Occupied\",Unplayable:2,\"2\":\"Unplayable\", });\n/**\n*/\nexport const Moveable = Object.freeze({ Allowed:0,\"0\":\"Allowed\",UnoccupiedSrc:1,\"1\":\"UnoccupiedSrc\",OccupiedDest:2,\"2\":\"OccupiedDest\",OutOfBounds:3,\"3\":\"OutOfBounds\",Unplayable:4,\"4\":\"Unplayable\",WrongTeamSrc:5,\"5\":\"WrongTeamSrc\",IllegalTrajectory:6,\"6\":\"IllegalTrajectory\",NoJumpablePiece:7,\"7\":\"NoJumpablePiece\",JumpingSameTeam:8,\"8\":\"JumpingSameTeam\", });\n/**\n* Single state of a checkers board\n*/\nexport class Board {\n\n static __wrap(ptr) {\n const obj = Object.create(Board.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_board_free(ptr);\n }\n /**\n * @returns {number}\n */\n get width() {\n var ret = wasm.__wbg_get_board_width(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set width(arg0) {\n wasm.__wbg_set_board_width(this.ptr, arg0);\n }\n /**\n * @returns {number}\n */\n get height() {\n var ret = wasm.__wbg_get_board_height(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set height(arg0) {\n wasm.__wbg_set_board_height(this.ptr, arg0);\n }\n /**\n * @returns {number}\n */\n get current_turn() {\n var ret = wasm.__wbg_get_board_current_turn(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set current_turn(arg0) {\n wasm.__wbg_set_board_current_turn(this.ptr, arg0);\n }\n /**\n * Get a copy of a board square by 1D array index\n * @param {number} idx\n * @returns {Square}\n */\n cell(idx) {\n var ret = wasm.board_cell(this.ptr, idx);\n return Square.__wrap(ret);\n }\n /**\n * Get a copy of a board square by 1D array index\n * @param {number} idx\n * @param {Square} square\n */\n set_cell(idx, square) {\n _assertClass(square, Square);\n var ptr0 = square.ptr;\n square.ptr = 0;\n wasm.board_set_cell(this.ptr, idx, ptr0);\n }\n /**\n * Get a copy of a board square by 2D [`BrdIdx`] index\n * @param {BrdIdx} idx\n * @returns {Square}\n */\n grid_cell(idx) {\n _assertClass(idx, BrdIdx);\n var ptr0 = idx.ptr;\n idx.ptr = 0;\n var ret = wasm.board_grid_cell(this.ptr, ptr0);\n return Square.__wrap(ret);\n }\n /**\n * Transform a 2D row/column board index into a single 1D index for use with [`Board::cells`]\n * @param {number} row\n * @param {number} col\n * @returns {number}\n */\n cell_index(row, col) {\n var ret = wasm.board_cell_index(this.ptr, row, col);\n return ret >>> 0;\n }\n /**\n * Similar to [`Board::cell_index`] but with a [`BrdIdx`] instead of separate indices. Transform a 2D row/column board index into a single 1D index for use with [`Board::cells`]\n * @param {BrdIdx} idx\n * @returns {number}\n */\n cell_idx(idx) {\n _assertClass(idx, BrdIdx);\n var ptr0 = idx.ptr;\n idx.ptr = 0;\n var ret = wasm.board_cell_idx(this.ptr, ptr0);\n return ret >>> 0;\n }\n /**\n * Transform a 1D array index (for [`Board::cells`]) into a 2D game board index (by row/col)\n * @param {number} idx\n * @returns {BrdIdx}\n */\n board_index(idx) {\n var ret = wasm.board_board_index(this.ptr, idx);\n return BrdIdx.__wrap(ret);\n }\n /**\n * Check whether a move given by source and destination indices is legal\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {number}\n */\n can_move(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.board_can_move(this.ptr, ptr0, ptr1);\n return ret >>> 0;\n }\n /**\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @param {Piece} from_square_occupant\n * @returns {number}\n */\n validate_man_move(from, to, from_square_occupant) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n _assertClass(from_square_occupant, Piece);\n var ptr2 = from_square_occupant.ptr;\n from_square_occupant.ptr = 0;\n var ret = wasm.board_validate_man_move(this.ptr, ptr0, ptr1, ptr2);\n return ret >>> 0;\n }\n /**\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @param {Piece} from_square_occupant\n * @returns {number}\n */\n validate_king_move(from, to, from_square_occupant) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n _assertClass(from_square_occupant, Piece);\n var ptr2 = from_square_occupant.ptr;\n from_square_occupant.ptr = 0;\n var ret = wasm.board_validate_king_move(this.ptr, ptr0, ptr1, ptr2);\n return ret >>> 0;\n }\n /**\n * Get cell index of jumpee square given from and to locations\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {number}\n */\n jumpee_idx(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.board_jumpee_idx(this.ptr, ptr0, ptr1);\n return ret >>> 0;\n }\n /**\n * Get a pointer to the backing array of board squares, [`Board::cells`]\n * @returns {number}\n */\n cells() {\n var ret = wasm.board_cells(this.ptr);\n return ret;\n }\n /**\n * Get the number of board squares\n * @returns {number}\n */\n num_cells() {\n var ret = wasm.board_num_cells(this.ptr);\n return ret >>> 0;\n }\n /**\n * Get the number of remaining pieces\n * @returns {number}\n */\n num_pieces() {\n var ret = wasm.board_num_pieces(this.ptr);\n return ret >>> 0;\n }\n /**\n * Get the number of remaining pieces for a player\n * @param {number} team\n * @returns {number}\n */\n num_player(team) {\n var ret = wasm.board_num_player(this.ptr, team);\n return ret >>> 0;\n }\n /**\n * Get the score value, Black - White pieces\n * @returns {number}\n */\n score() {\n var ret = wasm.board_score(this.ptr);\n return ret;\n }\n /**\n * Get the state of a board square by 1D array index\n * @param {number} idx\n * @returns {number}\n */\n cell_state(idx) {\n var ret = wasm.board_cell_state(this.ptr, idx);\n return ret >>> 0;\n }\n /**\n * Get new board derived from current with given move applied\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {Board}\n */\n apply_move(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.board_apply_move(this.ptr, ptr0, ptr1);\n return Board.__wrap(ret);\n }\n /**\n * Get new board derived from current with given jump applied\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {Board}\n */\n apply_jump(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.board_apply_jump(this.ptr, ptr0, ptr1);\n return Board.__wrap(ret);\n }\n /**\n * Get row index for current team, top row for black, bottom row for white\n * @returns {number}\n */\n king_row_idx() {\n var ret = wasm.board_king_row_idx(this.ptr);\n return ret >>> 0;\n }\n /**\n * Unwrap the jumpee piece from the square and [`Board::check_jumpee_team`] with [`Moveable`] response\n * @param {Square} jumpee\n * @param {Piece} from_occ\n * @returns {number}\n */\n static validate_jumpee(jumpee, from_occ) {\n _assertClass(jumpee, Square);\n var ptr0 = jumpee.ptr;\n jumpee.ptr = 0;\n _assertClass(from_occ, Piece);\n var ptr1 = from_occ.ptr;\n from_occ.ptr = 0;\n var ret = wasm.board_validate_jumpee(ptr0, ptr1);\n return ret >>> 0;\n }\n /**\n * Check that the source piece and the jumpee are of opposing teams\n * @param {Piece} from\n * @param {Piece} jumpee\n * @returns {boolean}\n */\n static check_jumpee_team(from, jumpee) {\n _assertClass(from, Piece);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(jumpee, Piece);\n var ptr1 = jumpee.ptr;\n jumpee.ptr = 0;\n var ret = wasm.board_check_jumpee_team(ptr0, ptr1);\n return ret !== 0;\n }\n /**\n * Initialise a game board without game pieces\n * @param {number} width\n * @param {number} height\n * @param {number} current_turn\n */\n constructor(width, height, current_turn) {\n var ret = wasm.board_new(width, height, current_turn);\n return Board.__wrap(ret);\n }\n /**\n * Reset the given board to a starting layout with 3 rows of opposing pieces\n * @param {Board} board\n * @param {number} piece_rows\n * @returns {Board}\n */\n static init_game(board, piece_rows) {\n _assertClass(board, Board);\n var ptr0 = board.ptr;\n board.ptr = 0;\n var ret = wasm.board_init_game(ptr0, piece_rows);\n return Board.__wrap(ret);\n }\n}\n/**\n* Rank 2 tensor index to identify a board square by row and column\n*/\nexport class BrdIdx {\n\n static __wrap(ptr) {\n const obj = Object.create(BrdIdx.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_brdidx_free(ptr);\n }\n /**\n * @returns {number}\n */\n get row() {\n var ret = wasm.__wbg_get_brdidx_row(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set row(arg0) {\n wasm.__wbg_set_brdidx_row(this.ptr, arg0);\n }\n /**\n * @returns {number}\n */\n get col() {\n var ret = wasm.__wbg_get_brdidx_col(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set col(arg0) {\n wasm.__wbg_set_brdidx_col(this.ptr, arg0);\n }\n /**\n * @param {number} row\n * @param {number} col\n */\n constructor(row, col) {\n var ret = wasm.brdidx_from(row, col);\n return BrdIdx.__wrap(ret);\n }\n /**\n * @param {BrdIdx} other\n * @returns {boolean}\n */\n eq(other) {\n _assertClass(other, BrdIdx);\n var ret = wasm.brdidx_eq(this.ptr, other.ptr);\n return ret !== 0;\n }\n}\n/**\n* Root-level structure for managing the game as a collection of board states\n*/\nexport class Game {\n\n static __wrap(ptr) {\n const obj = Object.create(Game.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_game_free(ptr);\n }\n /**\n * Get pointer to current board's squares\n * @returns {number}\n */\n current_board_cells() {\n var ret = wasm.game_current_board_cells(this.ptr);\n return ret;\n }\n /**\n * Get pointer to current board's squares\n * @returns {number}\n */\n current_board_len() {\n var ret = wasm.game_current_board_len(this.ptr);\n return ret >>> 0;\n }\n /**\n * Current turn's team\n * @returns {number}\n */\n current_turn() {\n var ret = wasm.game_current_turn(this.ptr);\n return ret >>> 0;\n }\n /**\n * Get square on current board for given index\n * @param {BrdIdx} idx\n * @returns {Square}\n */\n current_cell_state(idx) {\n _assertClass(idx, BrdIdx);\n var ret = wasm.game_current_cell_state(this.ptr, idx.ptr);\n return Square.__wrap(ret);\n }\n /**\n * Set given index as selected piece\n * TODO: Check whether valid square?\n * @param {BrdIdx} idx\n */\n set_selected(idx) {\n _assertClass(idx, BrdIdx);\n wasm.game_set_selected(this.ptr, idx.ptr);\n }\n /**\n * Clear currently selected piece\n */\n clear_selected() {\n wasm.game_clear_selected(this.ptr);\n }\n /**\n * Attempt to make a move given a source and destination index\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n * @returns {number}\n */\n make_move(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n var ret = wasm.game_make_move(this.ptr, ptr0, ptr1);\n return ret >>> 0;\n }\n /**\n * Update board state with given move and push new board into current state\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n */\n execute_move(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n wasm.game_execute_move(this.ptr, ptr0, ptr1);\n }\n /**\n * Update board state with given jump move and push new board into current state\n * @param {BrdIdx} from\n * @param {BrdIdx} to\n */\n execute_jump(from, to) {\n _assertClass(from, BrdIdx);\n var ptr0 = from.ptr;\n from.ptr = 0;\n _assertClass(to, BrdIdx);\n var ptr1 = to.ptr;\n to.ptr = 0;\n wasm.game_execute_jump(this.ptr, ptr0, ptr1);\n }\n /**\n * Push current board into the previous turns and set given board to current\n * @param {Board} board\n */\n push_new_board(board) {\n _assertClass(board, Board);\n var ptr0 = board.ptr;\n board.ptr = 0;\n wasm.game_push_new_board(this.ptr, ptr0);\n }\n /**\n * Set current board to given\n * @param {Board} board\n */\n set_current(board) {\n _assertClass(board, Board);\n var ptr0 = board.ptr;\n board.ptr = 0;\n wasm.game_set_current(this.ptr, ptr0);\n }\n /**\n * @param {number} width\n * @param {number} height\n * @param {number} piece_rows\n * @param {number} first_turn\n */\n constructor(width, height, piece_rows, first_turn) {\n var ret = wasm.game_new(width, height, piece_rows, first_turn);\n return Game.__wrap(ret);\n }\n /**\n * @param {number} width\n * @param {number} height\n * @param {number} piece_rows\n * @param {number} first_turn\n * @param {string} canvas_id\n * @param {number} canvas_width\n * @param {number} canvas_height\n * @returns {Game}\n */\n static new_with_canvas(width, height, piece_rows, first_turn, canvas_id, canvas_width, canvas_height) {\n var ptr0 = passStringToWasm0(canvas_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len0 = WASM_VECTOR_LEN;\n var ret = wasm.game_new_with_canvas(width, height, piece_rows, first_turn, ptr0, len0, canvas_width, canvas_height);\n return Game.__wrap(ret);\n }\n /**\n * @param {Painter} value\n */\n set_painter(value) {\n _assertClass(value, Painter);\n var ptr0 = value.ptr;\n value.ptr = 0;\n wasm.game_set_painter(this.ptr, ptr0);\n }\n /**\n */\n draw() {\n wasm.game_draw(this.ptr);\n }\n}\n/**\n* Used to paint boards onto HTML canvases\n*/\nexport class Painter {\n\n static __wrap(ptr) {\n const obj = Object.create(Painter.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_painter_free(ptr);\n }\n /**\n * Default constructor which queries for canvas by ID\n * @param {number} width\n * @param {number} height\n * @param {string} canvas_id\n */\n constructor(width, height, canvas_id) {\n var ptr0 = passStringToWasm0(canvas_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len0 = WASM_VECTOR_LEN;\n var ret = wasm.painter_new(width, height, ptr0, len0);\n return Painter.__wrap(ret);\n }\n /**\n * Constructor with given canvas element\n * @param {number} width\n * @param {number} height\n * @param {HTMLCanvasElement} canvas\n * @returns {Painter}\n */\n static new_with_canvas(width, height, canvas) {\n var ret = wasm.painter_new_with_canvas(width, height, addHeapObject(canvas));\n return Painter.__wrap(ret);\n }\n /**\n * Set new square outline colour value\n * @param {any} value\n */\n set_square_outline(value) {\n wasm.painter_set_square_outline(this.ptr, addHeapObject(value));\n }\n /**\n * Set new line width for outlining squares\n * @param {number} value\n */\n set_outline_width(value) {\n wasm.painter_set_outline_width(this.ptr, value);\n }\n /**\n * Set whether squares are outlined\n * @param {boolean} value\n */\n set_draw_outline(value) {\n wasm.painter_set_draw_outline(this.ptr, value);\n }\n /**\n * Reset the canvas dimensions to the given width and height\n */\n reset_dimensions() {\n wasm.painter_reset_dimensions(this.ptr);\n }\n /**\n * Check whether given canvas dimensions divide evenly by given board dimenions\n * @param {Board} board\n * @returns {boolean}\n */\n validate_board_dim(board) {\n _assertClass(board, Board);\n var ret = wasm.painter_validate_board_dim(this.ptr, board.ptr);\n return ret !== 0;\n }\n /**\n * Draw a board onto the canvas\n * @param {Board} board\n */\n draw(board) {\n _assertClass(board, Board);\n wasm.painter_draw(this.ptr, board.ptr);\n }\n}\n/**\n* Game piece given by its team and strength (normal or kinged)\n*/\nexport class Piece {\n\n static __wrap(ptr) {\n const obj = Object.create(Piece.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_piece_free(ptr);\n }\n /**\n * @returns {number}\n */\n get team() {\n var ret = wasm.__wbg_get_piece_team(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set team(arg0) {\n wasm.__wbg_set_piece_team(this.ptr, arg0);\n }\n /**\n * @returns {number}\n */\n get strength() {\n var ret = wasm.__wbg_get_piece_strength(this.ptr);\n return ret >>> 0;\n }\n /**\n * @param {number} arg0\n */\n set strength(arg0) {\n wasm.__wbg_set_piece_strength(this.ptr, arg0);\n }\n /**\n * @param {number} team\n * @param {number} strength\n */\n constructor(team, strength) {\n var ret = wasm.piece_new(team, strength);\n return Piece.__wrap(ret);\n }\n}\n/**\n*/\nexport class Player {\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_player_free(ptr);\n }\n}\n/**\n* Board squares given by a state and a possible occupying game piece\n*/\nexport class Square {\n\n static __wrap(ptr) {\n const obj = Object.create(Square.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n __destroy_into_raw() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_square_free(ptr);\n }\n /**\n * Game piece if square is occupied\n * @returns {Piece | undefined}\n */\n get occupant() {\n var ret = wasm.__wbg_get_square_occupant(this.ptr);\n return ret === 0 ? undefined : Piece.__wrap(ret);\n }\n /**\n * Game piece if square is occupied\n * @param {Piece | undefined} arg0\n */\n set occupant(arg0) {\n let ptr0 = 0;\n if (!isLikeNone(arg0)) {\n _assertClass(arg0, Piece);\n ptr0 = arg0.ptr;\n arg0.ptr = 0;\n }\n wasm.__wbg_set_square_occupant(this.ptr, ptr0);\n }\n /**\n * Description of whether the square is occupied or an unplayable, i.e. off-lattice square\n * @returns {number}\n */\n get state() {\n var ret = wasm.__wbg_get_square_state(this.ptr);\n return ret >>> 0;\n }\n /**\n * Description of whether the square is occupied or an unplayable, i.e. off-lattice square\n * @param {number} arg0\n */\n set state(arg0) {\n wasm.__wbg_set_square_state(this.ptr, arg0);\n }\n /**\n * Standard constructor function to form square from state and occupant\n * @param {number} state\n * @param {Piece | undefined} occupant\n */\n constructor(state, occupant) {\n let ptr0 = 0;\n if (!isLikeNone(occupant)) {\n _assertClass(occupant, Piece);\n ptr0 = occupant.ptr;\n occupant.ptr = 0;\n }\n var ret = wasm.square_new(state, ptr0);\n return Square.__wrap(ret);\n }\n /**\n * Helper function for a well-formed piece square by team and strength\n * @param {number} team\n * @param {number} strength\n * @returns {Square}\n */\n static pc(team, strength) {\n var ret = wasm.square_pc(team, strength);\n return Square.__wrap(ret);\n }\n /**\n * Helper function for a well-formed empty square\n * @returns {Square}\n */\n static empty() {\n var ret = wasm.square_empty();\n return Square.__wrap(ret);\n }\n /**\n * Helper function for a well-formed unplayable square\n * @returns {Square}\n */\n static unplay() {\n var ret = wasm.square_unplay();\n return Square.__wrap(ret);\n }\n}\n\nexport function __wbindgen_object_drop_ref(arg0) {\n takeObject(arg0);\n};\n\nexport function __wbindgen_string_new(arg0, arg1) {\n var ret = getStringFromWasm0(arg0, arg1);\n return addHeapObject(ret);\n};\n\nexport function __wbg_new_59cb74e423758ede() {\n var ret = new Error();\n return addHeapObject(ret);\n};\n\nexport function __wbg_stack_558ba5917b466edd(arg0, arg1) {\n var ret = getObject(arg1).stack;\n var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len0 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len0;\n getInt32Memory0()[arg0 / 4 + 0] = ptr0;\n};\n\nexport function __wbg_error_4bb6c2a97407129a(arg0, arg1) {\n try {\n console.error(getStringFromWasm0(arg0, arg1));\n } finally {\n wasm.__wbindgen_free(arg0, arg1);\n }\n};\n\nexport function __wbg_instanceof_Window_11e25482011fc506(arg0) {\n var ret = getObject(arg0) instanceof Window;\n return ret;\n};\n\nexport function __wbg_document_5aff8cd83ef968f5(arg0) {\n var ret = getObject(arg0).document;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n};\n\nexport function __wbg_getElementById_b180ea4ada06a837(arg0, arg1, arg2) {\n var ret = getObject(arg0).getElementById(getStringFromWasm0(arg1, arg2));\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n};\n\nexport function __wbg_log_9a99fb1af846153b(arg0) {\n console.log(getObject(arg0));\n};\n\nexport function __wbg_instanceof_CanvasRenderingContext2d_779e79c4121aa91b(arg0) {\n var ret = getObject(arg0) instanceof CanvasRenderingContext2D;\n return ret;\n};\n\nexport function __wbg_setstrokeStyle_2939ee453716e462(arg0, arg1) {\n getObject(arg0).strokeStyle = getObject(arg1);\n};\n\nexport function __wbg_setfillStyle_af790b5baf4d3210(arg0, arg1) {\n getObject(arg0).fillStyle = getObject(arg1);\n};\n\nexport function __wbg_setlineWidth_3e6b1837ae38d099(arg0, arg1) {\n getObject(arg0).lineWidth = arg1;\n};\n\nexport function __wbg_beginPath_2378575e37027ad3(arg0) {\n getObject(arg0).beginPath();\n};\n\nexport function __wbg_fill_558339447ed6ad43(arg0) {\n getObject(arg0).fill();\n};\n\nexport function __wbg_stroke_c1e0313c58997dcf(arg0) {\n getObject(arg0).stroke();\n};\n\nexport function __wbg_arc_fffd87d9113dce32() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {\n getObject(arg0).arc(arg1, arg2, arg3, arg4, arg5);\n}, arguments) };\n\nexport function __wbg_fillRect_46ffc8d2cef7e298(arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).fillRect(arg1, arg2, arg3, arg4);\n};\n\nexport function __wbg_strokeRect_7ea34fad8a7f0fe2(arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).strokeRect(arg1, arg2, arg3, arg4);\n};\n\nexport function __wbg_instanceof_HtmlCanvasElement_fd3cbbe3906d7792(arg0) {\n var ret = getObject(arg0) instanceof HTMLCanvasElement;\n return ret;\n};\n\nexport function __wbg_setwidth_f3c88eb520ba8d47(arg0, arg1) {\n getObject(arg0).width = arg1 >>> 0;\n};\n\nexport function __wbg_setheight_5a1abba41e35c42a(arg0, arg1) {\n getObject(arg0).height = arg1 >>> 0;\n};\n\nexport function __wbg_getContext_813df131fcbd6e91() { return handleError(function (arg0, arg1, arg2) {\n var ret = getObject(arg0).getContext(getStringFromWasm0(arg1, arg2));\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_newnoargs_9fdd8f3961dd1bee(arg0, arg1) {\n var ret = new Function(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n};\n\nexport function __wbg_call_ba36642bd901572b() { return handleError(function (arg0, arg1) {\n var ret = getObject(arg0).call(getObject(arg1));\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_self_bb69a836a72ec6e9() { return handleError(function () {\n var ret = self.self;\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_window_3304fc4b414c9693() { return handleError(function () {\n var ret = window.window;\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_globalThis_e0d21cabc6630763() { return handleError(function () {\n var ret = globalThis.globalThis;\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbg_global_8463719227271676() { return handleError(function () {\n var ret = global.global;\n return addHeapObject(ret);\n}, arguments) };\n\nexport function __wbindgen_is_undefined(arg0) {\n var ret = getObject(arg0) === undefined;\n return ret;\n};\n\nexport function __wbindgen_object_clone_ref(arg0) {\n var ret = getObject(arg0);\n return addHeapObject(ret);\n};\n\nexport function __wbindgen_debug_string(arg0, arg1) {\n var ret = debugString(getObject(arg1));\n var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n var len0 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len0;\n getInt32Memory0()[arg0 / 4 + 0] = ptr0;\n};\n\nexport function __wbindgen_throw(arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n};\n\n","import { Game, Board, BrdIdx, Painter, Team, init_wasm, Moveable, SquareState, Square } from \"draught\";\n// import { memory } from \"draught/draught_bg.wasm\";\n\n///////////////////\n// CONSTS\n///////////////////\n\nconst CANVAS_WIDTH = 480;\nconst CANVAS_HEIGHT = 480;\n\nconst BOARD_WIDTH = 8;\nconst BOARD_HEIGHT = 8;\n\nconst PIECE_ROWS = 3;\n\nconst STATUS_TIMEOUT = 3000;\n\nconst GameState = {\n HUMAN_TURN: {\n THINKING: \"human_turn.thinking\",\n FROM_SELECTED: \"human_turn.from_selected\"\n },\n AI_TURN: \"ai_turn\"\n}\n\n//////////////////\n// GAME STUFF\n//////////////////\n\ninit_wasm();\n\n// let board = new Board(BOARD_WIDTH, BOARD_HEIGHT, Team.Black);\n\nconst statusText = document.getElementById(\"status-p\");\nconst statusAlert = document.getElementById(\"status-d\");\nconst teamText = document.getElementById(\"team-p\");\n\nconst startBtn = document.getElementById(\"startBtn\");\nstartBtn.onclick = start_game;\n\nlet statusTimeout = null;\nlet setStatus = setStatusAlert;\n\nlet current_state = GameState.HUMAN_TURN.THINKING;\n\nlet game = null;\nlet painter = null;\n\nlet clicks = [];\n\nstart_game();\n\n/////////////////\n// CANVAS\n/////////////////\n\nconst canvas = document.getElementById(\"game-canvas\");\ncanvas.addEventListener(\"click\", (event) => {\n var mousepos = getMousePos(canvas, event);\n // console.log(mousepos);\n var cell = new BrdIdx(\n Math.floor((mousepos.y / CANVAS_HEIGHT) * BOARD_HEIGHT),\n Math.floor((mousepos.x / CANVAS_WIDTH) * BOARD_WIDTH),\n );\n // console.log(cell);\n process_canvas_click(cell);\n})\n\n////////////////\n// FUNCS\n////////////////\n\nfunction start_game() {\n game = new Game(BOARD_WIDTH, BOARD_HEIGHT, PIECE_ROWS, Team.Black);\n painter = new Painter(CANVAS_WIDTH, CANVAS_HEIGHT, \"game-canvas\");\n game.set_painter(painter);\n game.draw();\n\n updateTeamText();\n current_state = GameState.HUMAN_TURN.THINKING;\n}\n\nfunction process_canvas_click(cell_coord) {\n\n switch(current_state) {\n // first click of a move\n case GameState.HUMAN_TURN.THINKING:\n if (game.current_cell_state(cell_coord).state != SquareState.Occupied ) {\n return;\n }\n\n if (game.current_cell_state(cell_coord).occupant.team != game.current_turn() ) {\n return;\n }\n\n // console.log(\"Your turn, first piece picked\");\n\n clicks.push(cell_coord);\n current_state = GameState.HUMAN_TURN.FROM_SELECTED;\n game.set_selected(cell_coord);\n game.draw();\n \n break;\n \n // second click of a move\n case GameState.HUMAN_TURN.FROM_SELECTED:\n\n // second click is different to first, process as move\n // otherwise, will skip straight to clean up (clear selected and clicks) \n if (!clicks[0].eq(cell_coord)) {\n\n if (game.current_cell_state(cell_coord).state != SquareState.Empty ) {\n return;\n }\n \n // console.log(\"Your turn, first piece already picked, picking second\");\n \n clicks.push(cell_coord);\n \n if (clicks.length != 2) {\n setStatus(`Error: wrong number of clicks to process ${clicks.length}`);\n console.error(`Error: wrong number of clicks to process ${clicks.length}`);\n \n return;\n }\n\n let status = game.make_move(clicks[0], clicks[1]);\n\n switch(status) {\n case Moveable.Allowed:\n break;\n case Moveable.IllegalTrajectory:\n setStatus(\"You can't move like that!\");\n break;\n case Moveable.JumpingSameTeam:\n setStatus(\"You can't jump your own piece!\");\n break;\n case Moveable.NoJumpablePiece:\n setStatus(\"There's nothing to jump!\");\n break;\n case Moveable.OccupiedDest:\n setStatus(\"There's a piece there!\");\n break;\n case Moveable.OutOfBounds:\n setStatus(\"That square's not on the board! (how have you managed that?)\");\n break;\n case Moveable.UnoccupiedSrc:\n setStatus(\"There's no piece to move!\");\n break;\n case Moveable.Unplayable:\n setStatus(\"That's not a playable square!\");\n break;\n case Moveable.WrongTeamSrc:\n setStatus(\"That's not your piece!\");\n break;\n }\n \n }\n\n game.clear_selected();\n game.draw();\n clicks = [];\n current_state = GameState.HUMAN_TURN.THINKING;\n \n break;\n case GameState.AI_TURN:\n console.log(\"It's the AI's turn!\");\n break;\n }\n\n updateTeamText();\n}\n\nfunction getMousePos(canvas, evt) {\n var rect = canvas.getBoundingClientRect();\n return {\n x: evt.clientX - rect.left,\n y: evt.clientY - rect.top\n };\n}\n\nfunction setStatusText(txt, hide = true) {\n if(statusTimeout != null) {\n clearInterval(statusTimeout);\n }\n\n statusText.innerText = txt;\n\n if(hide) {\n statusTimeout = setTimeout(() => {\n statusText.innerText = \"\";\n }, STATUS_TIMEOUT);\n }\n}\n\nfunction setStatusAlert(txt, alertType = \"danger\", hide = true) {\n if(statusTimeout != null) {\n clearInterval(statusTimeout);\n }\n\n statusAlert.className = `alert alert-${alertType}`;\n statusAlert.innerText = txt;\n statusAlert.hidden = false;\n\n if(hide) {\n statusTimeout = setTimeout(() => {\n statusAlert.hidden = true;\n }, STATUS_TIMEOUT);\n }\n}\n\nfunction updateTeamText(){\n let team = game.current_turn();\n switch(team) {\n case Team.White:\n teamText.innerText = \"⚪ White ⚪\";\n break;\n case Team.Black:\n teamText.innerText = \"🔴 Black 🔴\";\n break;\n }\n}\n"],"sourceRoot":""} \ No newline at end of file diff --git a/96b9a573923750a3ae94.module.wasm b/96b9a573923750a3ae94.module.wasm deleted file mode 100644 index 87e8bdd..0000000 Binary files a/96b9a573923750a3ae94.module.wasm and /dev/null differ diff --git a/cc96734576b00860ab91.module.wasm b/cc96734576b00860ab91.module.wasm new file mode 100644 index 0000000..6167062 Binary files /dev/null and b/cc96734576b00860ab91.module.wasm differ diff --git a/doc/draught/all.html b/doc/draught/all.html index aa86ce9..9c84460 100644 --- a/doc/draught/all.html +++ b/doc/draught/all.html @@ -3,5 +3,5 @@

List of all items[] -

Structs

Enums

Macros

Functions

Constants

+

Structs

Enums

Macros

Functions

Constants

\ No newline at end of file diff --git a/doc/draught/board/index.html b/doc/draught/board/index.html index 9e7d056..57583e7 100644 --- a/doc/draught/board/index.html +++ b/doc/draught/board/index.html @@ -1,7 +1,7 @@ draught::board - Rust

Module draught::board[][src]

Board module for components related to the checkers board and game structure

+ Change settings

Module draught::board[][src]

Board module for components related to the checkers board and game structure

Modules

enums
iter

Structs

Board

Single state of a checkers board

diff --git a/doc/draught/board/struct.Board.html b/doc/draught/board/struct.Board.html index 2b1b0b5..4d8254b 100644 --- a/doc/draught/board/struct.Board.html +++ b/doc/draught/board/struct.Board.html @@ -1,6 +1,6 @@ Board in draught::board - Rust -

Module draught::comp[][src]

AI player logic

Structs

Computer

Root-level structure for managing the game as a collection of board states

Move
diff --git a/doc/draught/comp/struct.Computer.html b/doc/draught/comp/struct.Computer.html index 0c23e89..d3d094f 100644 --- a/doc/draught/comp/struct.Computer.html +++ b/doc/draught/comp/struct.Computer.html @@ -1,14 +1,14 @@ Computer in draught::comp - Rust -

Struct draught::comp::Computer[][src]

pub struct Computer {
-    pub tree: Arena<Board>,
+

Struct draught::comp::Computer[][src]

pub struct Computer {
     pub root_node_id: NodeId,
     pub search_depth: usize,
     pub team: Team,
 }

Root-level structure for managing the game as a collection of board states

- Fields

tree: Arena<Board>root_node_id: NodeIdsearch_depth: usizeteam: Team

Implementations

impl Computer[src]

pub fn new(initial_board: Board, search_depth: usize, team: Team) -> Computer[src]

pub fn update_board(&mut self, new_board: Board)[src]

pub fn available_turns(&self, board: &Board) -> Vec<Move>[src]

pub fn insert_boards(&mut self, boards: Vec<Board>) -> Vec<NodeId>[src]

pub fn get_move_boards(&self, board: &Board) -> Vec<Board>[src]

pub fn get_move(&self)[src]

Trait Implementations

impl Debug for Computer[src]

OUTLINE_WIDTH

Line width when outlining black squares

PIECE_MARGIN

Margin from square to define piece radius

PIECE_OUTLINE_WIDTH

Line width for outlining pieces

+
SELECTED_PIECE

Default hex colour value for selected piece

+
SELECTED_PIECE_OUTLINE

Default hex colour value for selected piece outline

SQUARE_OUTLINE

Default hex colour value for outline of black squares

WHITE_PIECE

Default hex colour value for white pieces

WHITE_PIECE_OUTLINE

Default hex colour value for white piece outline

diff --git a/doc/draught/paint/sidebar-items.js b/doc/draught/paint/sidebar-items.js index 3900efc..0c761e8 100644 --- a/doc/draught/paint/sidebar-items.js +++ b/doc/draught/paint/sidebar-items.js @@ -1 +1 @@ -initSidebarItems({"constant":[["BLACK_PIECE","Default hex colour value for black pieces"],["BLACK_PIECE_OUTLINE","Default hex colour value for black piece outline"],["BLACK_SQUARE","Default hex colour value for black square background"],["DRAW_OUTLINE","Whether to outline black squares"],["DRAW_PIECE_OUTLINES","Whether to outline pieces"],["KING_OUTLINE","Default hex colour value for black piece outline"],["OUTLINE_WIDTH","Line width when outlining black squares"],["PIECE_MARGIN","Margin from square to define piece radius"],["PIECE_OUTLINE_WIDTH","Line width for outlining pieces"],["SQUARE_OUTLINE","Default hex colour value for outline of black squares"],["WHITE_PIECE","Default hex colour value for white pieces"],["WHITE_PIECE_OUTLINE","Default hex colour value for white piece outline"],["WHITE_SQUARE","Default hex colour value for white square background"]],"struct":[["Painter","Used to paint boards onto HTML canvases"]]}); \ No newline at end of file +initSidebarItems({"constant":[["BLACK_PIECE","Default hex colour value for black pieces"],["BLACK_PIECE_OUTLINE","Default hex colour value for black piece outline"],["BLACK_SQUARE","Default hex colour value for black square background"],["DRAW_OUTLINE","Whether to outline black squares"],["DRAW_PIECE_OUTLINES","Whether to outline pieces"],["KING_OUTLINE","Default hex colour value for black piece outline"],["OUTLINE_WIDTH","Line width when outlining black squares"],["PIECE_MARGIN","Margin from square to define piece radius"],["PIECE_OUTLINE_WIDTH","Line width for outlining pieces"],["SELECTED_PIECE","Default hex colour value for selected piece"],["SELECTED_PIECE_OUTLINE","Default hex colour value for selected piece outline"],["SQUARE_OUTLINE","Default hex colour value for outline of black squares"],["WHITE_PIECE","Default hex colour value for white pieces"],["WHITE_PIECE_OUTLINE","Default hex colour value for white piece outline"],["WHITE_SQUARE","Default hex colour value for white square background"]],"struct":[["Painter","Used to paint boards onto HTML canvases"]]}); \ No newline at end of file diff --git a/doc/draught/paint/struct.Painter.html b/doc/draught/paint/struct.Painter.html index 80aa02a..7f021ce 100644 --- a/doc/draught/paint/struct.Painter.html +++ b/doc/draught/paint/struct.Painter.html @@ -1,15 +1,18 @@ Painter in draught::paint - Rust -

Struct draught::paint::Painter[][src]

pub struct Painter {
Show fields +

Struct draught::paint::Painter[][src]

pub struct Painter {
Show fields canvas: HtmlCanvasElement, context: CanvasRenderingContext2d, + selected_idx: Option<BrdIdx>, white_square: JsValue, black_square: JsValue, white_piece: JsValue, black_piece: JsValue, + selected_piece: JsValue, white_piece_line: JsValue, black_piece_line: JsValue, + selected_piece_line: JsValue, king_line: JsValue, piece_lines: bool, piece_line_width: f64, @@ -20,40 +23,41 @@ height: u32,
}

Used to paint boards onto HTML canvases

- Fields

canvas: HtmlCanvasElementcontext: CanvasRenderingContext2dwhite_square: JsValueblack_square: JsValuewhite_piece: JsValueblack_piece: JsValuewhite_piece_line: JsValueblack_piece_line: JsValueking_line: JsValuepiece_lines: boolpiece_line_width: f64square_outline: JsValueoutline_width: f64draw_outline: boolwidth: u32height: u32

Implementations

impl Painter[src]

fn get_canvas(canvas_id: &str) -> HtmlCanvasElement[src]

Get a canvas by element ID

-

fn get_canvas_context(canvas: &HtmlCanvasElement) -> CanvasRenderingContext2d[src]

Get a 2D canvas context for a given canvas

-

impl Painter[src]

pub fn new(width: u32, height: u32, canvas_id: &str) -> Painter[src]

Default constructor which queries for canvas by ID

-

pub fn new_with_canvas(
    width: u32,
    height: u32,
    canvas: HtmlCanvasElement
) -> Painter
[src]

Constructor with given canvas element

-

pub fn set_square_outline(&mut self, value: JsValue)[src]

Set new square outline colour value

-

pub fn set_outline_width(&mut self, value: f64)[src]

Set new line width for outlining squares

-

pub fn set_draw_outline(&mut self, value: bool)[src]

Set whether squares are outlined

-

pub fn reset_dimensions(&self)[src]

Reset the canvas dimensions to the given width and height

-

pub fn validate_board_dim(&self, board: &Board) -> bool[src]

Check whether given canvas dimensions divide evenly by given board dimenions

-

pub fn draw(&self, board: &Board)[src]

Draw a board onto the canvas

-

Trait Implementations

impl Debug for Painter[src]

impl From<Painter> for JsValue[src]

impl FromWasmAbi for Painter[src]

type Abi = u32

The wasm ABI type that this converts from when coming back out from the + Fieldscanvas: HtmlCanvasElementcontext: CanvasRenderingContext2dselected_idx: Option<BrdIdx>white_square: JsValueblack_square: JsValuewhite_piece: JsValueblack_piece: JsValueselected_piece: JsValuewhite_piece_line: JsValueblack_piece_line: JsValueselected_piece_line: JsValueking_line: JsValuepiece_lines: boolpiece_line_width: f64square_outline: JsValueoutline_width: f64draw_outline: boolwidth: u32height: u32

Implementations

impl Painter[src]

pub fn set_selected(&mut self, idx: &Option<BrdIdx>)[src]

Set selected piece by board index

+

fn get_canvas(canvas_id: &str) -> HtmlCanvasElement[src]

Get a canvas by element ID

+

fn get_canvas_context(canvas: &HtmlCanvasElement) -> CanvasRenderingContext2d[src]

Get a 2D canvas context for a given canvas

+

impl Painter[src]

pub fn new(width: u32, height: u32, canvas_id: &str) -> Painter[src]

Default constructor which queries for canvas by ID

+

pub fn new_with_canvas(
    width: u32,
    height: u32,
    canvas: HtmlCanvasElement
) -> Painter
[src]

Constructor with given canvas element

+

pub fn set_square_outline(&mut self, value: JsValue)[src]

Set new square outline colour value

+

pub fn set_outline_width(&mut self, value: f64)[src]

Set new line width for outlining squares

+

pub fn set_draw_outline(&mut self, value: bool)[src]

Set whether squares are outlined

+

pub fn reset_dimensions(&self)[src]

Reset the canvas dimensions to the given width and height

+

pub fn validate_board_dim(&self, board: &Board) -> bool[src]

Check whether given canvas dimensions divide evenly by given board dimenions

+

pub fn draw(&self, board: &Board)[src]

Draw a board onto the canvas

+

Trait Implementations

impl Debug for Painter[src]

impl From<Painter> for JsValue[src]

impl FromWasmAbi for Painter[src]

type Abi = u32

The wasm ABI type that this converts from when coming back out from the ABI boundary. Read more

-

impl IntoWasmAbi for Painter[src]

type Abi = u32

The wasm ABI type that this converts into when crossing the ABI +

impl IntoWasmAbi for Painter[src]

type Abi = u32

The wasm ABI type that this converts into when crossing the ABI boundary. Read more

-

impl OptionFromWasmAbi for Painter[src]

impl OptionFromWasmAbi for Painter[src]

impl OptionIntoWasmAbi for Painter[src]

impl OptionIntoWasmAbi for Painter[src]

impl RefFromWasmAbi for Painter[src]

type Abi = u32

The wasm ABI type references to Self are recovered from.

+

impl RefFromWasmAbi for Painter[src]

type Abi = u32

The wasm ABI type references to Self are recovered from.

type Anchor = Ref<'static, Painter>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous. Read more

-

impl RefMutFromWasmAbi for Painter[src]

type Abi = u32

Same as RefFromWasmAbi::Abi

+

impl RefMutFromWasmAbi for Painter[src]

type Abi = u32

Same as RefFromWasmAbi::Abi

type Anchor = RefMut<'static, Painter>

Same as RefFromWasmAbi::Anchor

-

impl WasmDescribe for Painter[src]

Auto Trait Implementations

impl RefUnwindSafe for Painter

impl !Send for Painter

impl !Sync for Painter

impl Unpin for Painter

impl UnwindSafe for Painter

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl WasmDescribe for Painter[src]

Auto Trait Implementations

impl RefUnwindSafe for Painter

impl !Send for Painter

impl !Sync for Painter

impl Unpin for Painter

impl UnwindSafe for Painter

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

 //! Board module for components related to the checkers board and game structure
 
@@ -1390,6 +1427,7 @@
         }
     }
 
+    /// Get cell index of jumpee square given from and to locations
     pub fn jumpee_idx(&self, from: BrdIdx, to: BrdIdx) -> usize {
         let (row_diff, col_diff) = Board::idx_diffs(from, to);
         self.cell_idx(
@@ -1437,13 +1475,20 @@
         let mut white: isize = 0;
 
         for (_, square) in PieceIterator::new(self) {
-            if let Some(x) = square.occupant {
-                match x.team {
+            if let Some(piece) = square.occupant {
+                
+                // kings are move valuable than men
+                let increment = match piece.strength {
+                    Man => 1,
+                    King => 2,
+                };
+
+                match piece.team {
                     Black => {
-                        black += 1;
+                        black += increment;
                     },
                     White => {
-                        white += 1;
+                        white += increment;
                     },
                 }
             }
@@ -1457,6 +1502,7 @@
         self.cell(idx).state
     }
 
+    /// Get new board derived from current with given move applied
     pub fn apply_move(&self, from: BrdIdx, to: BrdIdx) -> Board {
         let mut new = self.clone();
 
@@ -1475,9 +1521,12 @@
             Square::empty() // empty piece
         );
 
+        Board::check_kinged(&mut new, to);
+
         new
     }
 
+    /// Get new board derived from current with given jump applied
     pub fn apply_jump(&self, from: BrdIdx, to: BrdIdx) -> Board {
         let mut new = self.clone();
 
@@ -1502,9 +1551,18 @@
             Square::empty() // empty piece
         );
 
+        Board::check_kinged(&mut new, to);
 
         new
     }
+
+    /// Get row index for current team, top row for black, bottom row for white
+    pub fn king_row_idx(&self) -> usize {
+        match self.current_turn {
+            White => self.height - 1,
+            Black => 0,
+        }
+    }
 }
 
 /////////////////////////
@@ -1534,6 +1592,22 @@
         return from.team.opponent() == jumpee.team
     }
 
+    /// Check and apply king strength
+    fn check_kinged(new_board: &mut Board, idx: BrdIdx) {
+        if new_board.king_row_idx() == idx.row {
+            let cell_idx = new_board.cell_idx(idx);
+            let cell = new_board.cell(cell_idx);
+            match cell.occupant {
+                Some(piece) => {
+                    new_board.set_cell(cell_idx, Square::pc(piece.team, King));
+                },
+                None => {
+                    panic!("No piece found when checking king, idx: {}", idx);
+                },
+            }
+        }
+    }
+
     /// Initialise a game board without game pieces
     #[wasm_bindgen(constructor)]
     pub fn new(width: usize, height: usize, current_turn: Team) -> Board {
diff --git a/doc/src/draught/comp/mod.rs.html b/doc/src/draught/comp/mod.rs.html
index ca79278..b981af4 100644
--- a/doc/src/draught/comp/mod.rs.html
+++ b/doc/src/draught/comp/mod.rs.html
@@ -152,16 +152,6 @@
 149
 150
 151
-152
-153
-154
-155
-156
-157
-158
-159
-160
-161
 
 //! AI player logic
 
@@ -202,7 +192,6 @@
 /// Root-level structure for managing the game as a collection of board states
 #[derive(Debug)]
 pub struct Computer {
-    pub tree: Arena<Board>,
     pub root_node_id: NodeId,
     pub search_depth: usize,
     pub team: Team,
@@ -213,19 +202,13 @@
         let mut tree = Arena::new();
         let root_node_id = tree.new_node(initial_board);
         Computer {
-            tree,
             root_node_id,
             search_depth,
             team
         }
     }
 
-    pub fn update_board(&mut self, new_board: Board) {
-        let mut tree = Arena::new();
-        tree.new_node(new_board);
-        self.tree = tree;
-    }
-
+    /// Get vector of available moves for a given board
     pub fn available_turns(&self, board: &Board) -> Vec<Move> {
 
         // allocate capacity for 2 moves per piece, likely too much but will be shrunk
@@ -259,7 +242,7 @@
                             panic!("Unable to unwrap adjacent indices, from: {}, brd: {}", from_brd_idx, board);
                         }
 
-                        // iterate over adjacent indices
+                        // iterate over jumpable indices
                         if let Some(jump) = jump_op {
                             for i in jump {
                                 let to_brd_idx = board.board_index(i);
@@ -281,29 +264,26 @@
         moves
     }
 
-    // pub fn gen_tree(&mut self, tree: &mut Arena<Board>, board: Board) {
+    pub fn gen_tree(&mut self, tree: &mut Arena<Board>, board: Board) {
 
-        // let boards = self.get_move_boards(&board);
+        // possible boards from given
+        let boards = self.get_move_boards(&board);
 
-        // let root_id = vec!(tree.new_node(board));
-        // let ids = self.insert_boards(boards);
+        // root node of tree
+        let root = tree.new_node(board);
 
-        // for d in 0..self.search_depth {
+        // insert possible boards
+        let ids = self.insert_boards(tree, boards);
+        // append ids to root node
+        ids.iter().for_each( |id| root.append(*id, tree) );
 
-        //     for root in root_id.iter(){
-        //         for id in ids.into_iter() {
-        //             root.append(id, tree);
-        //         }
-        //     }
-        // }
+    }
 
-    // }
-
-    pub fn insert_boards(&mut self, boards: Vec<Board>) -> Vec<NodeId> {
+    pub fn insert_boards(&mut self, tree: &mut Arena<Board>, boards: Vec<Board>) -> Vec<NodeId> {
         
         boards
         .into_iter().map(
-            |b| self.tree.new_node(b)
+            |b| tree.new_node(b)
         ).collect()
     }
 
diff --git a/doc/src/draught/game/mod.rs.html b/doc/src/draught/game/mod.rs.html
index 89913f5..e89b7c5 100644
--- a/doc/src/draught/game/mod.rs.html
+++ b/doc/src/draught/game/mod.rs.html
@@ -151,6 +151,34 @@
 148
 149
 150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
 
 //! Top-level object for managing [`Board`]s, applying and managing turns
 
@@ -162,11 +190,11 @@
 use crate::log;
 
 use crate::board::{Square, BrdIdx};
-use crate::board::enums::{Moveable, Team};
+use crate::board::enums::{SquareState, Moveable, Team};
 use crate::paint::Painter;
 
 // use Team::*;
-// use SquareState::*;
+use SquareState::*;
 
 use std::fmt::{Display};
 
@@ -177,6 +205,7 @@
 #[derive(Debug)]
 pub struct Game {
     current: Board,
+    selected_piece: Option<BrdIdx>,
     previous_boards: Vec<Board>,
     painter: Option<Painter>
 }
@@ -210,10 +239,35 @@
         self.current.current_turn
     }
 
+    /// Get square on current board for given index
     pub fn current_cell_state(&self, idx: &BrdIdx) -> Square {
         self.current.cell(self.current.cell_idx(*idx))
     }
 
+    /// Set given index as selected piece
+    /// TODO: Check whether valid square?
+    pub fn set_selected(&mut self, idx: &BrdIdx) {
+        
+        if self.current.cell(self.current.cell_idx(*idx)).state != Occupied {
+            panic!("Tried to select an unoccupied or empty square");
+        } 
+
+        self.selected_piece = Some(*idx);
+        match &mut self.painter {
+            Some(p) => p.set_selected(&Some(*idx)),
+            None => {},
+        }
+    }
+
+    /// Clear currently selected piece
+    pub fn clear_selected(&mut self) {
+        self.selected_piece = None;
+        match &mut self.painter {
+            Some(p) => p.set_selected(&None),
+            None => {},
+        }
+    }
+
     /// Attempt to make a move given a source and destination index
     pub fn make_move(&mut self, from: BrdIdx, to: BrdIdx) -> Moveable {
         let able = self.current.can_move(from, to);
@@ -268,6 +322,7 @@
             current: Board::init_game(
                 Board::new(width, height, first_turn), piece_rows,
             ),
+            selected_piece: None,
             previous_boards: Vec::with_capacity(10),
             painter: None,
         }
@@ -278,6 +333,7 @@
             current: Board::init_game(
                 Board::new(width, height, first_turn), piece_rows,
             ),
+            selected_piece: None,
             previous_boards: Vec::with_capacity(10),
             painter: Some(
                 Painter::new(canvas_width, canvas_height, canvas_id)
diff --git a/doc/src/draught/paint.rs.html b/doc/src/draught/paint.rs.html
index 52f72f3..75d6699 100644
--- a/doc/src/draught/paint.rs.html
+++ b/doc/src/draught/paint.rs.html
@@ -341,6 +341,51 @@
 338
 339
 340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
 
 //! Components for painting board states onto HTML canvases
  
@@ -354,7 +399,7 @@
 use std::f64;
 
 use crate::log;
-use crate::board::{Board};
+use crate::board::{Board, BrdIdx};
 use crate::board::iter::PieceIterator;
 
 use crate::board::enums::Team::*;
@@ -376,11 +421,16 @@
 const WHITE_PIECE: &str = "#dbdbdb";
 /// Default hex colour value for black pieces
 const BLACK_PIECE: &str = "#ed0000";
+/// Default hex colour value for selected piece
+const SELECTED_PIECE: &str = "#fffd78";
 
 /// Default hex colour value for white piece outline
 const WHITE_PIECE_OUTLINE: &str = "#9c9c9c";
 /// Default hex colour value for black piece outline
 const BLACK_PIECE_OUTLINE: &str = "#a60000";
+/// Default hex colour value for selected piece outline
+// const SELECTED_PIECE_OUTLINE: &str = "#dedc73";
+const SELECTED_PIECE_OUTLINE: &str = "#d1cf45";
 /// Default hex colour value for black piece outline
 const KING_OUTLINE: &str = "#ffea00";
 /// Whether to outline pieces
@@ -397,15 +447,18 @@
 pub struct Painter {
     canvas: HtmlCanvasElement,
     context: CanvasRenderingContext2d,
+    selected_idx: Option<BrdIdx>,
 
     white_square: JsValue,
     black_square: JsValue,
 
     white_piece: JsValue,
     black_piece: JsValue,
+    selected_piece: JsValue,
 
     white_piece_line: JsValue,
     black_piece_line: JsValue,
+    selected_piece_line: JsValue,
     king_line: JsValue,
 
     piece_lines: bool,
@@ -420,6 +473,11 @@
 }
 
 impl Painter {
+    /// Set selected piece by board index
+    pub fn set_selected(&mut self, idx: &Option<BrdIdx>) {
+        self.selected_idx = *idx;
+    }
+
     /// Get a canvas by element ID
     fn get_canvas(canvas_id: &str) -> HtmlCanvasElement {
         // JS WINDOW
@@ -486,15 +544,18 @@
             canvas,
             context,
             width, height,
+            selected_idx: None,
 
             white_square: JsValue::from_str(WHITE_SQUARE),
             black_square: JsValue::from_str(BLACK_SQUARE),
             
             white_piece: JsValue::from_str(WHITE_PIECE),
             black_piece: JsValue::from_str(BLACK_PIECE),
+            selected_piece: JsValue::from_str(SELECTED_PIECE),
 
             white_piece_line: JsValue::from_str(WHITE_PIECE_OUTLINE),
             black_piece_line: JsValue::from_str(BLACK_PIECE_OUTLINE),
+            selected_piece_line: JsValue::from_str(SELECTED_PIECE_OUTLINE),
             king_line: JsValue::from_str(KING_OUTLINE),
             piece_lines: DRAW_PIECE_OUTLINES,
             piece_line_width: PIECE_OUTLINE_WIDTH,
@@ -516,15 +577,18 @@
             canvas,
             context,
             width, height,
+            selected_idx: None,
 
             white_square: JsValue::from_str(WHITE_SQUARE),
             black_square: JsValue::from_str(BLACK_SQUARE),
             
             white_piece: JsValue::from_str(WHITE_PIECE),
             black_piece: JsValue::from_str(BLACK_PIECE),
+            selected_piece: JsValue::from_str(SELECTED_PIECE),
 
             white_piece_line: JsValue::from_str(WHITE_PIECE_OUTLINE),
             black_piece_line: JsValue::from_str(BLACK_PIECE_OUTLINE),
+            selected_piece_line: JsValue::from_str(SELECTED_PIECE_OUTLINE),
             king_line: JsValue::from_str(KING_OUTLINE),
             piece_lines: DRAW_PIECE_OUTLINES,
             piece_line_width: PIECE_OUTLINE_WIDTH,
@@ -680,6 +744,32 @@
                 None => panic!("No piece found when attempting to draw, idx: {}, square: {:?}", idx, square),
             }
         }
+
+        if let Some(selected_idx) = self.selected_idx {
+            self.context.set_fill_style(&self.selected_piece);
+            self.context.set_stroke_style(&self.selected_piece_line);
+
+            let center_x: f64 = (selected_idx.col as f64 * cell_width as f64) + (cell_width as f64) / 2.0;
+            let center_y: f64 = (selected_idx.row as f64 * cell_height as f64) + (cell_height as f64) / 2.0;
+
+            self.context.begin_path();
+            match self.context.arc(
+                center_x, 
+                center_y, 
+                (cell_width as f64 / 2.0) - PIECE_MARGIN, // radius 
+                0.0, // start angle
+                f64::consts::PI * 2.0) // end angle
+            {
+                Ok(res) => res,
+                Err(err) => log!("Failed to paint selected piece, idx: {}, {:?}", selected_idx, err),
+            };
+            self.context.fill();
+
+            if self.piece_lines {
+                self.context.set_line_width(self.piece_line_width);
+                self.context.stroke()
+            }
+        }
     }
 }
diff --git a/index.html b/index.html index b725555..6ce688b 100644 --- a/index.html +++ b/index.html @@ -41,16 +41,18 @@
- Docs - + Docs +
-
+

-
+
+
+