diff options
Diffstat (limited to 'motus/js')
-rw-r--r-- | motus/js/fieldList.ml | 20 | ||||
-rw-r--r-- | motus/js/initialize.ml | 22 | ||||
-rw-r--r-- | motus/js/motus.ml | 5 | ||||
-rw-r--r-- | motus/js/next.ml | 6 | ||||
-rw-r--r-- | motus/js/reload.ml | 4 | ||||
-rw-r--r-- | motus/js/state.ml | 23 | ||||
-rw-r--r-- | motus/js/updateProposition.ml | 2 |
7 files changed, 30 insertions, 52 deletions
diff --git a/motus/js/fieldList.ml b/motus/js/fieldList.ml index 85755aa..428f364 100644 --- a/motus/js/fieldList.ml +++ b/motus/js/fieldList.ml @@ -10,13 +10,13 @@ type elements = Brr.El.t list If no class is specified, consider the letter is at the right position. *) -let get_validity_from_element : El.t -> State.letter_validity = +let get_validity_from_element : El.t -> Motus_lib.Validity.t = fun el -> if El.class' (Jstr.v "missing") el - then State.Missing + then Missing else if El.class' (Jstr.v "misplaced") el - then State.Misplaced - else State.Wellplaced + then Misplaced + else Wellplaced let get_rules : elements -> State.proposition = @@ -32,14 +32,14 @@ let get_rules : elements -> State.proposition = t -let get_class : State.letter_validity -> Jstr.t = function +let get_class : Motus_lib.Validity.t -> Jstr.t = function | Wellplaced -> Jstr.v "wellplaced" | Misplaced -> Jstr.v "misplaced" | _ -> Jstr.v "missing" (** Create the field list modifiied by the user *) -let make : int -> (int * Jstr.t * State.letter_validity) E.send -> elements = +let make : int -> (int * Jstr.t * Motus_lib.Validity.t) E.send -> elements = fun len change_sender -> List.init ~len ~f:(fun i -> let input = @@ -66,9 +66,9 @@ let make : int -> (int * Jstr.t * State.letter_validity) E.send -> elements = (fun _ -> let validity = match get_validity_from_element input with - | State.Missing -> State.Misplaced - | State.Misplaced -> State.Wellplaced - | State.Wellplaced -> State.Missing + | Missing -> Motus_lib.Validity.Misplaced + | Misplaced -> Motus_lib.Validity.Wellplaced + | Wellplaced -> Motus_lib.Validity.Missing in change_sender (i, El.prop El.Prop.value input, validity) ) (El.as_target input); @@ -139,7 +139,7 @@ let build : El.t -> int S.t -> State.proposition S.t = if Jstr.equal Jstr.empty value then (i, None) else - let validity = State.Wellplaced in + let validity = Motus_lib.Validity.Wellplaced in (i, Some (Jstr.uppercased value, validity)) ) input ) elements diff --git a/motus/js/initialize.ml b/motus/js/initialize.ml index 7dd7544..82f1288 100644 --- a/motus/js/initialize.ml +++ b/motus/js/initialize.ml @@ -6,7 +6,7 @@ open Brr type t = { length : int ; content : (int * Jstr.t, Jv.Error.t) result - ; sender : (int * Jstr.t * State.letter_validity) E.send + ; sender : (int * Jstr.t * Validity.t) E.send ; proposition : State.proposition } @@ -16,16 +16,12 @@ type t = which can be edited by the user. The rule list is used to identify the letter already fixed by the previous - results. - - *) -let get_proposition : - Persistence.t -> Criteria.t list -> State.proposition option = + results. *) +let get_proposition : Wordlist.t -> Criteria.t list -> State.proposition option + = fun analysis rules -> let word = - Persistence.extract_freq analysis - |> Persistence.pick_next_word analysis - |> fst + Wordlist.extract_freq analysis |> Wordlist.pick_next_word analysis |> fst in match String.equal String.empty word with | true -> None @@ -44,8 +40,8 @@ let get_proposition : incr i; let validity = match wellplaced with - | true -> State.Wellplaced - | _ -> State.Missing + | true -> Validity.Wellplaced + | _ -> Validity.Missing in Some (Jstr.of_char c, validity) ) @@ -65,8 +61,8 @@ let process { sender; length; content; proposition } state = List.fold_left ~f:(fun a w -> let upper = Jstr.uppercased w in - Persistence.add_word rules a (Jstr.to_string upper) ) - ~init:(Persistence.empty_data ()) + Wordlist.add_word rules a (Jstr.to_string upper) ) + ~init:(Wordlist.empty_data ()) words in let current_prop = get_proposition analysis rules diff --git a/motus/js/motus.ml b/motus/js/motus.ml index a2bcbd3..402e14a 100644 --- a/motus/js/motus.ml +++ b/motus/js/motus.ml @@ -150,7 +150,7 @@ let main List.map props ~f:(fun proposition -> List.map proposition ~f:(fun prop -> let letter, validity = - Option.value ~default:(Jstr.empty, State.Missing) prop + Option.value ~default:(Jstr.empty, Validity.Missing) prop in let input = El.input @@ -173,8 +173,7 @@ let main S.map (fun ev -> match - ( ev.State.current_prop - , Motus_lib.Persistence.list_size ev.State.analysis ) + (ev.State.current_prop, Motus_lib.Wordlist.list_size ev.State.analysis) with | [], _ | _, 1 -> Some (Jstr.v "true") | _, _ -> None ) diff --git a/motus/js/next.ml b/motus/js/next.ml index 5f24883..72db9e4 100644 --- a/motus/js/next.ml +++ b/motus/js/next.ml @@ -17,9 +17,9 @@ let process : t -> State.state -> State.state = (* 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 ()) - (Motus_lib.Persistence.words state.analysis) + ~f:(Motus_lib.Wordlist.add_word rules) + ~init:(Motus_lib.Wordlist.empty_data ()) + (Motus_lib.Wordlist.words state.analysis) in let propositions = state.current_prop :: state.propositions diff --git a/motus/js/reload.ml b/motus/js/reload.ml index cfdfa2a..2756b74 100644 --- a/motus/js/reload.ml +++ b/motus/js/reload.ml @@ -18,9 +18,7 @@ let process : t -> State.state -> State.state = in let new_state = - { state with - analysis = Motus_lib.Persistence.remove_word state.analysis word - } + { state with analysis = Motus_lib.Wordlist.remove_word state.analysis word } in (* Get the new proposition if any *) let current_prop = diff --git a/motus/js/state.ml b/motus/js/state.ml index 57a3794..cbab14f 100644 --- a/motus/js/state.ml +++ b/motus/js/state.ml @@ -1,15 +1,10 @@ open StdLabels open Motus_lib -type letter_validity = - | Wellplaced - | Misplaced - | Missing - -type proposition = (Jstr.t * letter_validity) option list +type proposition = (Jstr.t * Validity.t) option list type state = - { analysis : Persistence.t + { analysis : Wordlist.t ; rules : Criteria.t list ; length : int ; propositions : proposition list @@ -18,7 +13,7 @@ type state = } let init () = - { analysis = Persistence.empty_data () + { analysis = Wordlist.empty_data () ; rules = [] ; length = 0 ; propositions = [] @@ -42,17 +37,7 @@ let get_current_rules : proposition -> Criteria.t list = then () else let char = String.get (Jstr.to_string letter) 0 in - - match validity with - | Missing -> - rules := Criteria.add (Criteria.NotContain (char, None)) !rules - | Misplaced -> - rules := - Criteria.add (Criteria.NotContain (char, Some i)) !rules; - rules := Criteria.add (Criteria.Contain (char, None)) !rules - | Wellplaced -> - rules := Criteria.add (Criteria.Contain (char, Some i)) !rules - ) + rules := Validity.to_criteria char i validity !rules ) prop ); List.rev !rules diff --git a/motus/js/updateProposition.ml b/motus/js/updateProposition.ml index ab10db3..7a4608f 100644 --- a/motus/js/updateProposition.ml +++ b/motus/js/updateProposition.ml @@ -7,7 +7,7 @@ open StdLabels type t = { position : int ; letter : Jstr.t - ; validity : State.letter_validity + ; validity : Motus_lib.Validity.t } let process { position; letter; validity } state = |