Skip to content

Instantly share code, notes, and snippets.

@Anniepoo
Created February 21, 2020 10:14
Show Gist options
  • Save Anniepoo/a8743299de7f246709a3f9fdff96eb36 to your computer and use it in GitHub Desktop.
Save Anniepoo/a8743299de7f246709a3f9fdff96eb36 to your computer and use it in GitHub Desktop.
:- module(clpfdwsc, [go/1]).
:-use_module(library(clpfd)).
go(M) :-
wsc([[0,0,0,0]], M),
flatten(M, FM),
label(FM).
wsc([[1,1,1,1]|R], [[1,1,1,1]|R]).
wsc([[F,W,S,C]|R], M) :-
[NF, NW, NS, NC] = NM,
NM ins 0..1,
NF #\= F, % move the farmer
% move max one thing
NW #= W #/\ NS #= S #\/
NS #= S #/\ NC #= C #\/
NW #= W #/\ NC #= C,
% game rules
NS #= NC #==> NF #= NS,
NW #= NS #==> NF #= NW,
wsc([NM, [F,W,S,C] | R], M).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment