2048: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) m →{{header|Perl 6}}: refactor a bit, style tweaks |
Thundergnat (talk | contribs) m →{{header|Perl 6}}: some more refactoring, DRY |
||
Line 1,805: | Line 1,805: | ||
multi sub squash ('left', @c) { |
multi sub squash ('left', @c) { |
||
my @ |
my @t = grep { .chars }, @c; |
||
⚫ | |||
⚫ | |||
@ |
@t = grep { .chars }, @t; |
||
⚫ | |||
⚫ | |||
} |
} |
||
multi sub squash ('right', @c) { |
multi sub squash ('right', @c) { |
||
my @ |
my @t = reverse grep { .chars }, @c; |
||
⚫ | |||
⚫ | |||
@ |
@t = grep { .chars }, @t; |
||
⚫ | |||
reverse @t; |
|||
} |
} |
||
Line 1,819: | Line 1,823: | ||
multi sub move('up') { |
multi sub move('up') { |
||
⚫ | |||
for 0 .. 3 -> $y { |
|||
my @col = squash left, @board[*]»[$y]; |
|||
for 0 .. 2 -> $x { |
|||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
} |
} |
||
multi sub move('down') { |
multi sub move('down') { |
||
⚫ | |||
for 0 .. 3 -> $y { |
|||
my @col = squash right, @board[*]»[$y]; |
|||
for 3 ... 1 -> $x { |
|||
combine(@col[$x], @col[$x-1]) if @col[$x] && @col[$x-1] == @col[$x] |
|||
} |
|||
⚫ | |||
} |
|||
} |
} |
||
multi sub move('left') { |
multi sub move('left') { |
||
⚫ | |||
for 0 .. 3 -> $y { |
|||
⚫ | |||
for 0 .. 2 -> $x { |
|||
⚫ | |||
} |
|||
⚫ | |||
} |
|||
} |
} |
||
multi sub move('right') { |
multi sub move('right') { |
||
⚫ | |||
for 0 .. 3 -> $y { |
|||
my @row = squash right, flat @board[$y]»[*]; |
|||
for 3 ... 1 -> $x { |
|||
combine(@row[$x], @row[$x-1]) if @row[$x] && @row[$x-1] == @row[$x] |
|||
} |
|||
@board[$y] = squash right, @row; |
|||
} |
|||
} |
} |
||