I am trying to make a game similar to minesweeper and i am trying to count the number of bombs near a point on a map but it only enters in one countneighbour and it stops, how can I make it enter the other countneighbor predicates?
checkneighbours(X,Y) :- nb_setval(vecini,0),
X1 is X-1,
X2 is X+1,
Y1 is Y-1,
Y2 is Y+1,
countneighbours(X1,Y),
countneighbours(X1,Y1),
countneighbours(X1,Y2),
countneighbours(X,Y1),
countneighbours(X,Y2),
countneighbours(X2,Y1),
countneighbours(X2,Y),
countneighbours(X2,Y2),
nb_getval(V,vecini),
write(V).
countneighbours(X,Y) :- map(X,Y,Z),
( Z=:= "O"
-> nb_getval(V,vecini),
V1 is V+1,
nb_setval(vecini,V1)
).
map
predicate? And really, a global variable? – user1812457