i try solve akari/light-up game in prolog . firstly want find 4 cells around cell neighbors() gives 1 cell ... after want find cells in y cell yneighbors() .... useful ..... code :
size(8,8). wall(1,6). wall(2,2). wall(2,3). wall(3,7). wall(4,1). wall(4,5). wall(5,4). wall(5,8). wall(6,2). wall(7,6). wall(7,7). wall(8,3). wallnum(1,6,1). wallnum(2,2,3). wallnum(3,7,0). wallnum(5,4,4). wallnum(5,8,0). wallnum(6,2,2). wallnum(7,6,1). light(1,2). light(1,7). light(2,1). light(2,8). light(3,2). light(4,4). light(4,6). light(5,3). light(5,5). light(6,1). light(6,4). light(7,2). light(7,8). light(8,6). cell(x,y):-x>0,x<9,y>0,y<9. neighbors(x,y,l):-cell(x,y), cell(x+1,y),x1 x + 1,y1 y ,l =[x1,y1]; cell(x-1,y),x1 x - 1,y1 y ,l=[x1,y1]; cell(x,y+1),x1 x ,y1 y + 1 ,l=[x1,y1]; cell(x,y-1),x1 x ,y1 y - 1 ,l=[x1,y1]. yneighbors(x,y,l):-cell(x,y+1),l=[x,y].
this looking for:
neighbor(x,y,nx,y):- nx x-1, cell(nx,y). neighbor(x,y,nx,y):- nx x+1, cell(nx,y). neighbor(x,y,x,ny) :- ny y-1, cell(x,ny). neighbor(x,y,x,ny) :- ny y+1, cell(x,ny). neighbors(x,y,l) :- findall(neighbor(nx,ny),neighbor(x,y,nx,ny),l).
explanation:
predicate calls cell(x+1,y)
ill-formed. equivalent cell(+(x,1),y)
. should notice x+1 term, not mathematical expression. so, not evaluated.
mathematical expressions evaluated means of is/2.
you should review prolog knowledge since code has no sense.
yneighbors(x,y,l):-cell(x,y+1),l=[x,y].
will fail.
if persist in predicate calls cell(x+y,z)
, should evaluate arguments cell/2:
cell(x,y) :- evalx x, evaly y, evaly > 0, ...
but, discourage such practice.