2048: Difference between revisions

7 bytes added ,  5 years ago
m
→‎{{header|Perl 6}}: Update for recent proto requirement for overridden core subs
m (→‎{{header|REXX}}: added notations to better show the user's inputs.)
m (→‎{{header|Perl 6}}: Update for recent proto requirement for overridden core subs)
Line 4,109:
=={{header|Perl 6}}==
Uses termios to set the terminal options, so only compatible with POSIX terminals. This version does not include a specific "win" or "lose" condition. (though it would be trivial to add them.) You can continue to play this even after getting a 2048 tile; and if there is no valid move you can make, you can't do anything but quit.
{{works with|Rakudo|20172018.0305}}
<lang perl6>use Term::termios;
 
Line 4,183:
sub combine ($v is rw, $w is rw) { $v += $w; $w = ''; $score += $v; }
 
multiproto sub move ('up'|) {*};
 
multi move('up') {
map { @board[*;$_] = squash @board[*;$_] }, ^n;
}
 
multi sub move('down') {
map { @board[*;$_] = reverse squash reverse @board[*;$_] }, ^n;
}
 
multi sub move('left') {
map { @board[$_] = squash @board[$_] }, ^n;
}
 
multi sub move('right') {
map { @board[$_;*] = reverse squash reverse @board[$_;*] }, ^n;
}
 
10,333

edits