Sudoku basic#
This example uses the well known sudoku puzzle to showcase most basic feature of clinguin.
Usage#
$ clinguin client-server --domain-files sudoku_basic/{encoding.lp,instance.lp} --ui-files sudoku_basic/ui.lp
Domain Files#
initial(5,1,8).
initial(6,2,7).
initial(7,1,4).
initial(8,2,2).
initial(8,1,6).
initial(9,2,9).
initial(3,3,9).
initial(4,3,3).
initial(6,3,6).
initial(7,3,5).
initial(8,3,7).
initial(1,4,7).
initial(2,4,6).
initial(4,4,4).
initial(7,4,9).
initial(8,4,3).
initial(2,5,3).
initial(3,5,2).
initial(4,5,8).
initial(7,5,7).
initial(9,5,5).
initial(1,6,9).
initial(2,6,1).
initial(3,6,8).
initial(8,6,4).
initial(9,6,6).
initial(1,7,6).
initial(5,7,7).
initial(6,7,8).
#const dim = 3.
val(1..dim*dim).
pos(X,Y) :- val(X), val(Y).
subgrid(X,Y,(((X-1)/dim)*dim+((Y-1)/dim))) :- pos(X,Y).
1 { sudoku(X,Y,V) : val(V) } 1 :- pos(X,Y).
:- sudoku(X,Y,V), sudoku(X',Y,V), X != X'.
:- sudoku(X,Y,V), sudoku(X,Y',V), Y != Y'.
:- sudoku(X,Y,V), sudoku(X',Y',V), subgrid(X,Y,S), subgrid(X',Y',S), (X,Y)!=(X',Y').
sudoku(X,Y,V) :- initial(X,Y,V).
UI Files#
elem(window,window,root).
attr(window,child_layout,grid).
attr(window,class,("justify-content-start")).
elem(dd(X,Y),dropdown_menu,window):-pos(X,Y).
attr(dd(X,Y),width,50):-pos(X,Y).
attr(dd(X,Y),height,50):-pos(X,Y).
attr(dd(X,Y),grid_column,X):-pos(X,Y).
attr(dd(X,Y),grid_row,Y):-pos(X,Y).
attr(dd(X,Y),class,("border-dark";"bg-primary")):-pos(X,Y).
attr(dd(X,Y),class,"bg-opacity-50"):-subgrid(X,Y,S), S\2!=0.
attr(dd(X,Y),selected,V):-_all(sudoku(X,Y,V)).
elem(ddv(X,Y,V),dropdown_menu_item,dd(X,Y)):-_any(sudoku(X,Y,V)).
attr(ddv(X,Y,V),label,V):-_any(sudoku(X,Y,V)).
when(ddv(X,Y,V),click,call,add_assumption(sudoku(X,Y,V),true)):-_any(sudoku(X,Y,V)).