set(arithmetic).
assign(domain_size,6).                  %5x5 grid
assign(max_models,-1).

formulas(utils).
  ds1 = domain_size + -1.
  ds2 = ds1 + -1.
  x < ds2 -> s(x) = x +  1.    s(ds2) = p(ds2).      s(ds1) = ds1. 
  x > 0   -> p(x) = x + -1.    p(0)   = s(0).    
end_of_list.

formulas(tents_and_trees).
  all x all y (x < ds1 & y < ds1 ->  
     (f(x,y) < 2) &                      
     (f(x,0) + f(x,1) + f(x,2) + f(x,3) + f(x,4) = f(x,ds1)) & 
     (f(0,y) + f(1,y) + f(2,y) + f(3,y) + f(4,y) = f(ds1,y))).
  f(ds1,ds1) = 0.

  t(x,y) -> f(x,y)=0.                %no tent in the cell with a tree
 
  %no tent can stand directly next to another one, not even diagonally.
  all x all y ((x < ds1 & y < ds1 & f(x,y) = 1) -> 
      (f(x,s(y)) = 0 & f(x,p(y)) = 0 & f(s(x),y) = 0 & f(p(x),y) = 0 &  
       f(p(x),p(y)) = 0 & f(p(x),s(y)) = 0 & 
       f(s(x),p(y)) = 0 & f(s(x),s(y)) = 0)).  
end_of_list.

formulas(trees_map).
  all y (-t(0,y) & -t(2,y) & -t(ds1,y)).               
  all x -t(x,ds1).
  t(1,0) & -t(1,1) &  t(1,2) &  t(1,3) &  t(1,4).     
 -t(3,0) &  t(3,1) & -t(3,2) & -t(3,3) & -t(3,4).     
  t(4,0) & -t(4,1) & -t(4,2) &  t(4,3) & -t(4,4).     
end_of_list.

formulas(sample_puzzle).
  f(0,ds1) = 3 & f(1,ds1) = 0 & f(2,ds1) = 2 & f(3,ds1) = 0 & f(4,ds1)=2.  
  f(ds1,0) = 1 & f(ds1,1) = 2 & f(ds1,2) = 1 & f(ds1,3) = 1 & f(ds1,4)=2. 
end_of_list.
