Connect Four
Click in a column to drop a piece into that column.
Player:
blue
blue
red
0
0
control(blue)
click(mark(X,Y)) :: control(P) & columnempty(X) ==> cell(X,1,P) click(mark(X,Y)) :: control(P) & cellopen(X,Y2) & succ(Y1,Y2) & ~cellopen(X,Y1) ==> cell(X,Y2,P) click(mark(X,Y)) :: control(blue) ==> ~control(blue) & control(red) click(mark(X,Y)) :: control(red) ==> ~control(red) & control(blue) boardopen :- cellopen(X,6) columnempty(X) :- cellopen(X,1) cellopen(X,Y) :- col(X) & row(Y) & ~cell(X,Y,blue) & ~cell(X,Y,red) line(P) :- cell(X,Y1,P) & succ(Y1,Y2) & cell(X,Y2,P) & succ(Y2,Y3) & cell(X,Y3,P) & succ(Y3,Y4) & cell(X,Y4,P) line(P) :- cell(X1,Y,P) & succ(X1,X2) & cell(X2,Y,P) & succ(X2,X3) & cell(X3,Y,P) & succ(X3,X4) & cell(X4,Y,P) line(P) :- cell(X1,Y1,P) & succ(X1,X2) & succ(Y1,Y2) & cell(X2,Y2,P) & succ(X2,X3) & succ(Y2,Y3) & cell(X3,Y3,P) & succ(X3,X4) & succ(Y3,Y4) & cell(X4,Y4,P) line(P) :- cell(X1,Y1,P) & succ(X1,X2) & succ(Y2,Y1) & cell(X2,Y2,P) & succ(X2,X3) & succ(Y3,Y2) & cell(X3,Y3,P) & succ(X3,X4) & succ(Y4,Y3) & cell(X4,Y4,P) goal(blue,100) :- line(blue) goal(blue,50) :- ~line(blue) & ~line(red) goal(blue,0) :- line(red) goal(red,100) :- line(red) goal(red,50) :- ~line(blue) & ~line(red) goal(red,0) :- line(blue) terminal :- line(blue) terminal :- line(red) terminal :- ~boardopen index(1) index(2) index(3) col(1) col(2) col(3) col(4) col(5) col(6) col(7) row(1) row(2) row(3) row(4) row(5) row(6) succ(1,2) succ(2,3) succ(3,4) succ(4,5) succ(5,6) succ(6,7) innerhtml(mark(M,N),"
") :- cell(M,N,blue) innerhtml(mark(M,N),"
") :- cell(M,N,red) innerhtml(control,W) :- control(W) innerhtml(bluereward,N) :- goal(blue,N) innerhtml(redreward,N) :- goal(red,N) attribute(mark(X,Y),"onclick","modbutton(this)") :- col(X) & row(Y) & ~terminal attribute(mark(X,Y),"onclick","true") :- col(X) & row(Y) & terminal style(mark(X,Y),"cursor","pointer") :- col(X) & row(Y) & ~terminal style(mark(X,Y),"cursor","text") :- col(X) & row(Y) & terminal style(rewards,"display","") :- terminal