str:{:[#R;ev2[x;move[x;y]'M R];*M]} / machine strategy ev2:{any@:[#i:&0evr[#x;w]'move[w:who[];*|x]'y} / nonrepeating moves menu:{{if[~_n~x;Z[x][]]}@`4:`menu,,!Z} / main menu Z.help:{`show$`.k.Help} / display help Z.size:{if[~_n~r:`4:`menu,,`$$6+!15;N::0$$r;Z.play[]]} / size menu Z.play:{N::;if[P="X";me who[]]} / play a game Z.clear:{N::} / clear game Z.save:{if[~_n~r:`4:`save`l;r 1:(N;P;I)]} / save game Z.load:{if[~_n~r:`4:`open`l;{N::x;P::y;go .'z;}. 1:r]} / load game Z.self:{N::;S::1;me who[]} / selfplay N::[0<#_i;0$*_i;6] / boardsize input T::[1<#_i;0$_i 1;30] / timeout input D..d:"weights N" / weight matrix E..d:"edges[-1_'1_'(N+2)_vs!_(N+2)^2]N+1" / edge indices M..d:"moves[N].'E" / all moves R..d:"nreps[H]M" / nonrepeats H..d:",(N,N)#\" \"" / board history I..d:"N;()" / move history W..d:"N;\" \"" / winner C..d:"N;0" / counter S..d:"N;0" / self-play O..d:"N;0" / outcome P..d:"N;piece[]" / piece N..t:"hd[];sh[]" / hide show A..d:"+$,/'I" / move history A..f:{:[x~_n;14$" ";*_i;4$x;4$_i 1]} / blank for piece A..bg:{:[~*_i;9900 990000 P=*x]} / red or green for piece A..k:"if[O;R:nreps[(2+_i 1)#H]M;B:board H 1+_i 1]" / replay if game over B..d:"board@*|H" / board = last board B..k:"if[_i _in E R;you M E?_i]" / if valid, you move B..bg:{:[_i _in E R;808080;999999 990000 9900(" ",P)?*B ._i]} / background colors B..fg:{:[_i _in E R;0;999999]} / foregound colors B..f:" " / blank cell .k..c:`form / .k is a form .k..a:,`A`B / arrangement .k..l..d:".k.over[.k.W].k.O" / signal game over .k..kl:".k.menu[]" / menu Help..e:0 / set no edit Help:("k pousse {N = boardsize} {T = timeout} " / help text "" "you are green, i am red" "click on a gray cell to push a piece onto the board" "white cells are unplayable" "" "you win if you have a surplus of straights" "you lose if you repeat one of your board-states" "" "click on a row in A to step through a game" "" "from the menu, select:" "" " 'play' for a new game" " 'self' for self-play" " 'size' resizes the board (N can be 6 to 20)" " 'save' saves the current game to file" " 'load' loads and plays a game on file" " 'clear' clears current game" "" "game-strategy devised by the j language team") hd:{`hide$`.k} / hide window sh:{`show$`.k} / show window ."\\r ",$_t / set random seed .t..t:".k.time[]" / set timer sh[] / show game \t 1 Z.play[] / start play