user
This task is about making a clone of the game "GREED" by Matthew Day.

This game is played on a grid of   **79**   column by   **22**   rows of random numbers from   **1**   to   **9**   (inclusive).

The player location is signified by the   **@**   symbol.

The object of Greed is to erase as much of the screen as possible by moving around   (all 8 directions are allowed in this grid).

When you move in a direction,   **N**   number of grid squares are erased ("eaten") in that direction,   **N**   being the first number in that direction.

Your score reflects the total number of squares "eaten".

You may not make a move that places you off the grid or over a previously eaten square.

The game is over if there is no more valid moves.

Video on YouTube
assistant
**Translation of**: Phix

```
# 20200913 added Raku programming solution

srand 123456;

my @board = [ (1..9).roll xx my \w = 79 ] xx my \h = 22 ;
my \X = $ = w.rand.Int ; my \Y = $ = h.rand.Int;
@board[Y;X] = '@';
my \score = $ = 0;

sub execute (\y,\x) {
   my \i = $ = @board[Y+y;X+x];
   if countSteps(i, x, y) {
      score += i;
      @board[ Y +  y*$_ ; X +  x*$_ ] = ' ' for ^i;
      @board[ Y += y*i  ; X += x*i  ] = '@';
   }
}

sub countSteps(\i, \x, \y) {
   my \tX = $ = X ; my \tY = $ = Y;
   for ^i {
      tX += x; tY += y;
      return False if tX < 0 or tY < 0 or tX ≥ w or tY ≥ h or @board[tY;tX] eq ' ' 
   }
   return True;
}

sub existsMoves {
   for (-1 .. 1) X (-1 .. 1) -> (\x,\y) {
      next if x == 0 and y == 0;
      next if X+x < 0 or X+x > w or Y+y < 0 or Y+y > h ;
      my \i = @board[Y+y;X+x];
      return True if ( i ne ' ' and countSteps(i, x, y) )
   }
   return False;
}

loop {
   for @board { .join.print ; print "\r\n" } ;
   { say "Game over." and last } unless existsMoves();
   print "Current score : ", score, "\r\n";
   given my $c = $*IN.getc {
      when 'q' { say "So long." and last}
      when 'e' { execute(-1,-1) if X > 0 and Y > 0 } # North-West
      when 'r' { execute(-1, 0) if           Y > 0 } # North
      when 't' { execute(-1, 1) if X < w and Y > 0 } # North-East
      when 'd' { execute( 0,-1) if X > 0           } # West
      when 'g' { execute( 0, 1) if X < w           } # East
      when 'x' { execute( 1,-1) if X > 0 and Y < h } # South-West
      when 'c' { execute( 1, 0) if           Y < h } # South
      when 'v' { execute( 1, 1) if X < w and Y < h } # South-East
   }
}

```