Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/15-puzzle-game/Mathematica/15-puzzle-game.math
Normal file
13
Task/15-puzzle-game/Mathematica/15-puzzle-game.math
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
grid = MapThread[{#1,#2} &, {Range @ 16, Range @ 16}]
|
||||
|
||||
Move[x_] := (empty = Select[grid, #[[1]]==16 &][[1,2]];
|
||||
If[(empty == x+4) || (empty == x-4) ||
|
||||
(Mod[empty,4] != 0 && empty == x-1) ||
|
||||
(Mod[empty,4] != 1 && empty == x+1),
|
||||
oldEmpty = grid[[empty]][[1]];
|
||||
grid[[empty]][[1]] = grid[[x]][[1]];
|
||||
grid[[x]][[1]] = oldEmpty])
|
||||
|
||||
CButton[{x_,loc_}] := If[x==16, Null, Button[x,Move @ loc]]
|
||||
|
||||
Dynamic @ Grid @ Partition[CButton /@ grid,4]
|
||||
Loading…
Add table
Add a link
Reference in a new issue