From 741f88ab405995003eb6e9f301d3b065c1e84a4a Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 28 Jan 2022 14:44:57 +0100 Subject: Added a motus solver --- motus/js/next.ml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 motus/js/next.ml (limited to 'motus/js/next.ml') diff --git a/motus/js/next.ml b/motus/js/next.ml new file mode 100644 index 0000000..658590d --- /dev/null +++ b/motus/js/next.ml @@ -0,0 +1,36 @@ +(** Load the next proposition from the word list *) + +open StdLabels + +type t = unit + +let process : t -> State.state -> State.state = + fun () state -> + (* Add the current proposition into the validated list *) + let rules = State.get_current_rules state.current_prop in + + let rules = + Motus_lib.Criteria.merge_lists ~init:state.rules rules + |> List.sort_uniq ~cmp:Stdlib.compare + in + + (* Update the word list with the new rules *) + let analysis = + List.fold_left + ~f:(Motus_lib.Persistence.add_word rules) + ~init:(Motus_lib.Persistence.empty_data ()) + state.analysis.Motus_lib.Persistence.element + in + + let propositions = state.current_prop :: state.propositions + and current_prop = [] in + + let new_state = { state with propositions; current_prop; rules; analysis } in + + (* Get the new proposition if any *) + let current_prop = Initialize.get_proposition analysis rules in + match current_prop with + | None -> new_state + | Some prop -> + FieldList.set_with_props prop state.fields new_state.rules; + State.{ new_state with rules; current_prop = prop } -- cgit v1.2.3