0

I'm a complete beginner at ASP.

adj(c11,c12). adj(c12,c13). adj(c13,c14).
adj(c21,c22). adj(c22,c23). adj(c23,c24).
adj(c31,c32). adj(c32,c33). adj(c33,c34).

adj(c11,c21). adj(c12,c22). adj(c13,c23). adj(c14,c24).
adj(c21,c31). adj(c22,c32). adj(c23,c33). adj(c24,c34).

adj(c11,c22). adj(c12,c21). adj(c12,c23). adj(c13,c22). adj(c13,c24). adj(c14,c23).
adj(c21,c32). adj(c22,c31). adj(c22,c33). adj(c23,c32). adj(c23,c34). adj(c24,c33).

{mine(F)} <= 1 :- adj(F,C).
:- #count {mine(F) : adj(F,X)} <= 2.

So I am generating a minesweeper game. At the moment I have the mines generated into different cells. However my #Count is not working, how do I limit each mine to be <= 2 in each answer set?

Martin Dawson
  • 7,455
  • 6
  • 49
  • 92

1 Answers1

0

Answer to question

The current definition of mines is:

{mine(F)} <= 1 :- adj(F,C).   % generation
:- #count {mine(F) : adj(F,X)} <= 2.   % restriction

The generation is saying: for all tiles found in first argument of atom F, there is one or zero mine. The restriction is saying: for all tiles found in first argument of atom F, there is one or zero mine, which is always true because if there is either a mine or not a mine.

The count constraint should be write as:

:- #count{F: mine(F)} > 2.

Or, more simply:

:- {mine(_)} > 2.

Alternative (simpler) way

In order to get between m and n mines in the field, we should then yield between m and n atoms mine(F) where F is one tile name. (like c12). This can be done with generation without restriction:

% tile(T) holds for all identifier used in adj/2 atoms.
tile(T):- adj(T,_).
tile(T):- adj(_,T).

% yield between m and n mines (with m=0 and n=2)
0 {mine(F): tile(F)} 2.

This will output the 79 models that contains 0, 1 or 2 mines.

aluriak
  • 5,559
  • 2
  • 26
  • 39