The easiest would be to "scan" your board left-to-right, top-to-bottom (as this is how we output to a console), and see if there is anything to be shown for this particular square. Assuming that you are using format
for writing (easier to control the formatting of the output), and assuming that you know in advance the size of your board, and your x and y coordinates start at the top left corner, you need to:
- for each row of the board:
- for each position on the row
- see if there is something to draw on that square, and draw it
- for each position on the row
Or, in code:
show_board(Rows, Cols) :-
show_rows(1, Rows, Cols).
show_rows(R, Rows, Cols) :-
( R =< Rows
-> show_row(R, 1, Cols),
R1 is R + 1,
show_rows(R1, Rows, Cols)
; true
).
show_row(R, C, Cols) :-
( C =< Cols
-> show_square(R, C) % or maybe show_square(C, R)?
C1 is C + 1,
show_row(R, C1, Cols)
; true
).
% show_square should always succeed!
show_square(R, C) :-
( square(R, C, Obj /* additional arguments? */)
-> draw(Obj /* additional arguments */)
; draw_not_visible
).
This could be a starting point. It could be done more "fancy" but this is a perfectly valid approach. Drawing an object depends on what your object is, and drawing the boundary around the grid is trivial.