diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2022-02-25 19:15:29 +0100 | 
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-25 19:15:29 +0100 | 
| commit | 4eff667b92ff7ef4c3542650509c03fb0de5cbce (patch) | |
| tree | 6a6180d355d0ab78626ad5988c5203ee20344187 /motus/js | |
| parent | 95432043550bd4a41b4466395502bc3b748e6746 (diff) | |
Added an another engine for motus, using entropy instead of frequencies only
Diffstat (limited to 'motus/js')
| -rw-r--r-- | motus/js/initialize.ml | 16 | ||||
| -rw-r--r-- | motus/js/next.ml | 10 | ||||
| -rw-r--r-- | motus/js/reload.ml | 2 | 
3 files changed, 17 insertions, 11 deletions
| diff --git a/motus/js/initialize.ml b/motus/js/initialize.ml index a088a0e..9d07a85 100644 --- a/motus/js/initialize.ml +++ b/motus/js/initialize.ml @@ -17,11 +17,17 @@ type t =      The rule list is used to identify the letter already fixed by the previous      results. *) -let get_proposition : Wordlist.t -> Criteria.t list -> State.proposition option -    = - fun analysis rules -> +let get_proposition : +    int -> Wordlist.t -> Criteria.t list -> State.proposition option = + fun length wordlist rules -> +  Printf.printf "Number of elements : %d\n" (Wordlist.list_size wordlist); +    let word = -    Freq_analysis.analyse analysis |> Freq_analysis.pick_next_word analysis +    if Wordlist.list_size wordlist > 2000 +    then Freq_analysis.analyse wordlist |> Freq_analysis.pick_next_word wordlist +    else +      let _, word = Entropy.analyse length wordlist in +      word    in    match String.equal String.empty word with    | true -> None @@ -63,7 +69,7 @@ let process { sender; length; content; proposition } state =          |> Wordlist.add_words rules        in -      let current_prop = get_proposition analysis rules +      let current_prop = get_proposition length analysis rules        and fields = FieldList.make length sender in        ( match current_prop with        | None -> state diff --git a/motus/js/next.ml b/motus/js/next.ml index 104b3e6..f3bb2fe 100644 --- a/motus/js/next.ml +++ b/motus/js/next.ml @@ -6,24 +6,24 @@ type t = unit  let process : t -> State.state -> State.state =   fun () state -> -  (* Add the current proposition into the validated list *) +  (* Get the news rules (and match the words only against the new ones )*)    let rules = State.get_current_rules state.current_prop in +  (* Update the word list with the new rules *) +  let analysis = Motus_lib.Wordlist.filter rules state.analysis 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 = Motus_lib.Wordlist.filter rules state.analysis 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 +  let current_prop = Initialize.get_proposition state.length analysis rules in    match current_prop with    | None -> new_state    | Some prop -> diff --git a/motus/js/reload.ml b/motus/js/reload.ml index 2756b74..f0b581f 100644 --- a/motus/js/reload.ml +++ b/motus/js/reload.ml @@ -22,7 +22,7 @@ let process : t -> State.state -> State.state =    in    (* Get the new proposition if any *)    let current_prop = -    Initialize.get_proposition new_state.analysis state.rules +    Initialize.get_proposition state.length new_state.analysis state.rules    in    match current_prop with    | None -> new_state | 
