Commit cbf3819d authored by MARCHE Claude's avatar MARCHE Claude

sudoku: cleaned

parent e1568dd2
...@@ -234,6 +234,7 @@ pvsbin/ ...@@ -234,6 +234,7 @@ pvsbin/
/examples/vstte10_max_sum/*__*.ml /examples/vstte10_max_sum/*__*.ml
/examples/euler001/*__*.ml /examples/euler001/*__*.ml
/examples/sudoku/*__*.ml /examples/sudoku/*__*.ml
/examples/sudoku/jsmain.js
/examples/gcd/*__*.ml /examples/gcd/*__*.ml
/examples/gcd/jsmain.js /examples/gcd/jsmain.js
/examples/defunctionalization/*__*.ml /examples/defunctionalization/*__*.ml
......
...@@ -16,8 +16,14 @@ let make_board () = ...@@ -16,8 +16,14 @@ let make_board () =
input##align <- Js.string "center"; input##align <- Js.string "center";
let style = input##style in let style = input##style in
style##border <- Js.string "none"; style##border <- Js.string "none";
style##padding <- Js.string "0px"; style##fontFamily <- Js.string "monospace";
style##maxWidth <- Js.string "20px"; style##fontSize <- Js.string "20px";
style##fontWeight <- Js.string "bold";
style##paddingBottom <- Js.string "5px";
style##paddingTop <- Js.string "5px";
style##paddingLeft <- Js.string "10px";
style##paddingRight <- Js.string "10px";
(* style##minWidth <- Js.string "60px"; *)
let enforce_digit _ = let enforce_digit _ =
begin begin
match Js.to_string input##value with match Js.to_string input##value with
...@@ -60,8 +66,8 @@ let make_board () = ...@@ -60,8 +66,8 @@ let make_board () =
style##borderStyle <- Js.string "solid"; style##borderStyle <- Js.string "solid";
style##borderColor <- Js.string "#000000"; style##borderColor <- Js.string "#000000";
let widths = function let widths = function
| 0 -> 2, 0 | 2 -> 1, 1 | 3 -> 1, 0 | 0 -> 3, 0 | 2 -> 1, 1 | 3 -> 1, 0
| 5 -> 1, 1 | 6 -> 1, 0 | 8 -> 1, 2 | 5 -> 1, 1 | 6 -> 1, 0 | 8 -> 1, 3
| _ -> 1, 0 in | _ -> 1, 0 in
let (top, bottom) = widths i in let (top, bottom) = widths i in
let (left, right) = widths j in let (left, right) = widths j in
...@@ -169,7 +175,16 @@ let display_sol rows a = ...@@ -169,7 +175,16 @@ let display_sol rows a =
for i=0 to 8 do for i=0 to 8 do
for j=0 to 8 do for j=0 to 8 do
let cell = rows.(i).(j) in let cell = rows.(i).(j) in
cell##value <- Js.string (Why3__BigInt.to_string a.(9*i+j)) cell##value <- Js.string (Why3__BigInt.to_string a.(9*i+j));
cell##style##backgroundColor <- Js.string "#ffffff"
done
done
let no_sol rows =
for i=0 to 8 do
for j=0 to 8 do
let cell = rows.(i).(j) in
cell##style##backgroundColor <- Js.string "#ff0000"
done done
done done
...@@ -187,8 +202,22 @@ let solve_board rows _ = ...@@ -187,8 +202,22 @@ let solve_board rows _ =
input_grid.(9*i+j) <- Why3__BigInt.of_int v input_grid.(9*i+j) <- Why3__BigInt.of_int v
done done
done; done;
let a = Sudoku__Solver.solve sudoku input_grid in begin
display_sol rows a; try
let a = Sudoku__Solver.solve sudoku input_grid in
display_sol rows a
with Sudoku__Solver.NoSolution -> no_sol rows
end;
Js._false
let reset_board rows _ =
for i=0 to 8 do
for j=0 to 8 do
let cell = rows.(i).(j) in
cell##value <- Js.string "";
cell##style##backgroundColor <- Js.string "#ffffff";
done
done;
Js._false Js._false
...@@ -200,14 +229,18 @@ let onload (_event : #Dom_html.event Js.t) : bool Js.t = ...@@ -200,14 +229,18 @@ let onload (_event : #Dom_html.event Js.t) : bool Js.t =
let solve = Js.Opt.get (d##getElementById (Js.string "solve")) let solve = Js.Opt.get (d##getElementById (Js.string "solve"))
(fun () -> assert false) in (fun () -> assert false) in
solve##onclick <- Dom_html.handler (solve_board rows); solve##onclick <- Dom_html.handler (solve_board rows);
let reset = Js.Opt.get (d##getElementById (Js.string "reset"))
(fun () -> assert false) in
reset##onclick <- Dom_html.handler (reset_board rows);
let board = Js.Opt.get (d##getElementById (Js.string "board")) let board = Js.Opt.get (d##getElementById (Js.string "board"))
(fun () -> assert false) in (fun () -> assert false) in
Dom.appendChild board table; Dom.appendChild board table;
board##style##backgroundColor <- Js.string "#00ff00"; (* board##style##backgroundColor <- Js.string "#00ff00"; *)
board##style##paddingLeft <- Js.string "40px"; board##style##padding <- Js.string "40px";
board##style##paddingRight <- Js.string "40px"; (* board##style##paddingLeft <- Js.string "40px"; *)
board##style##paddingBottom <- Js.string "40px"; (* board##style##paddingRight <- Js.string "40px"; *)
board##style##paddingTop <- Js.string "40px"; (* board##style##paddingBottom <- Js.string "40px"; *)
(* board##style##paddingTop <- Js.string "40px"; *)
Js._false Js._false
let _ = Dom_html.window##onload <- Dom_html.handler onload let _ = Dom_html.window##onload <- Dom_html.handler onload
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment