[m-users.] [Beginner] Optimally representing a diamond-shaped grid

Razetime rraghu.11502 at gmail.com
Sat Oct 15 21:00:37 AEDT 2022


I have a grid like follows:

    1
  2 3 4
5 6 7 8 9
  A B C
    D

for a pointer that spawns on any position on this grid, the possible
options are up, down, left and right, which move 1 step in each of
those directions. If a direction is given and there is no spot in that
direction, the point should remain in place.

My first idea is exhaustively defining all the possible moves like so:

:- type dir ---> u;d;l;r.

:- pred(character:in,dir::in,character::out) is det.
move('5',u,'5').
move('5',d,'5').
move('5',l,'5').
move('5',r,'6').
% and so on.

What could be a more idiomatic method to accomplish this movement in Mercury?


More information about the users mailing list