# [mercury-users] Modes for partly uninstantiated list

Tom Breton (Tehom) tehom at panix.com
Sun Feb 4 06:27:08 AEDT 2007

```> Hi,
>
> I've been doing a little thing about a game called tick-tack-toe in
> prolog. Now I'd like to try the same in mercury.
>
> The predicate I am having trouble with is:
>
> win([A,B,C,_,_,_,_,_,_]) :- atom(A), atom(B), atom(C), A=B, B=C.
> win([_,_,_,A,B,C,_,_,_]) :- atom(A), atom(B), atom(C), A=B, B=C.
> win([_,_,_,_,_,_,A,B,C]) :- atom(A), atom(B), atom(C), A=B, B=C.
>
> win([A,_,_,B,_,_,C,_,_]) :- atom(A), atom(B), atom(C), A=B, B=C.
> win([_,A,_,_,B,_,_,C,_]) :- atom(A), atom(B), atom(C), A=B, B=C.
> win([_,_,A,_,_,B,_,_,C]) :- atom(A), atom(B), atom(C), A=B, B=C.
>
> win([A,_,_,_,B,_,_,_,C]) :- atom(A), atom(B), atom(C), A=B, B=C.
> win([_,_,A,_,B,_,C,_,_]) :- atom(A), atom(B), atom(C), A=B, B=C.

I assume that you've represented uncommitted cells as vars.  That's neat
for updating them but causes you problems here, because an uncommitted
cell is not really a free variable.  Think about it: the game initial
state should not have models where player x or player o are in a winning
state.  Right?

ISTM you have to actually update the game state, not just further
constrain it.  Then win/1 will be trivial, I think.

> I've tried different things in mercury but didn't succeed. My
> test-code looks like the following:
>
>
> :- pred win(list(character)).
> :- mode win(list_skel >> list_skel) is semidet.
>
> win([A,B,C,_,_,_,_,_,_]) :- A=B, B=C.

But it's not really a list_skel, is it?  IIUC, a list_skel only knows how
long it is; everything inside it is unbound.  But you want to take
something like [x,x,x,_,_ ... ], where some elements are bound.

> main(!IO) :-
> 	L = [x,x,x,_,_,_,_,_,_],
> 	(if win(L)
> 		then write_string("win", !IO)
> 		else write_string("not(win)", !IO)),
> 	nl(!IO).
>
>
> - c. heppner
>

HTH

Tom

--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------

```