15 puzzle game: Difference between revisions

m
→‎{{header|Perl 6}}: Update for recent proto requirement for overridden core subs
(→‎{{header|Go}}: Replace with a more idiomatic solution.)
m (→‎{{header|Perl 6}}: Update for recent proto requirement for overridden core subs)
Line 3,727:
 
=={{header|Perl 6}}==
{{works with|Rakudo|20172018.0306}}
Most of this is interface code. Reused substantial portions from the [[2048#Perl_6|2048]] task. Use the arrow keys to slide tiles, press 'q' to quit or 'n' for a new puzzle. Requires a POSIX termios aware terminal. Ensures that the puzzle is solvable by shuffling the board with an even number of swaps, then checking for even taxicab parity for the empty space.
<lang perl6>use Term::termios;
Line 3,816:
}
 
multiproto sub move ('up'|) {*};
 
multi move('up') {
map { @board[*;$_] = reverse slide reverse @board[*;$_] }, ^n;
}
 
multi sub move('down') {
map { @board[*;$_] = slide @board[*;$_] }, ^n;
}
 
multi sub move('left') {
map { @board[$_] = reverse slide reverse @board[$_] }, ^n;
}
 
multi sub move('right') {
map { @board[$_] = slide @board[$_] }, ^n;
}
10,333

edits