diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2024-03-04 21:07:51 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2024-03-04 21:07:51 +0100 |
commit | fe13ea5ce39b24b2d49b43c384ed01b013d683db (patch) | |
tree | 92b4a01e97c22318b376c2b576ca783af4a9db9e /calculette_aoo/js | |
parent | ef9beb0814c36cda979a4ed7e9175e72e69540ac (diff) |
calculette_aoo: now evaluate the exact frequency, some corrections
Diffstat (limited to 'calculette_aoo/js')
-rw-r--r-- | calculette_aoo/js/dune | 1 | ||||
-rw-r--r-- | calculette_aoo/js/main.ml | 77 |
2 files changed, 77 insertions, 1 deletions
diff --git a/calculette_aoo/js/dune b/calculette_aoo/js/dune index 8732ae0..b2ece9c 100644 --- a/calculette_aoo/js/dune +++ b/calculette_aoo/js/dune @@ -3,6 +3,7 @@ (libraries brr note.brr + zarith_stubs_js application aoo ) diff --git a/calculette_aoo/js/main.ml b/calculette_aoo/js/main.ml index 9a63d12..3106041 100644 --- a/calculette_aoo/js/main.ml +++ b/calculette_aoo/js/main.ml @@ -1,4 +1,5 @@ open Brr +open StdLabels let ( let=? ) : 'a option -> ('a -> unit) -> unit = fun f opt -> Option.iter opt f @@ -18,6 +19,12 @@ let cout_fm = (100, 50, 30) let get_element_by_id id = Jstr.of_string id |> Brr.Document.find_el_by_id Brr.G.document +let distance_table fm = + Array.init 4 ~f:(fun i -> + Array.init 7 ~f:(fun i -> max 1 ((i + 4) * 4)) + |> Aoo.Roll.against (fm + i) + |> Array.map ~f:(fun v -> Q.to_float v *. 100.)) + let get_int_element id = Jstr.of_string id |> Brr.Document.find_el_by_id Brr.G.document @@ -51,7 +58,7 @@ let eval _ = let env : Aoo.Build.env = { cost_max = get_int_element "xp" + cost - ; max_tours = float (get_int_element "tours") + ; max_tours = get_int_element "tours" ; cout_sort = get_int_element "cost" ; degat_sort = get_int_element "dammage" ; fm_oponent @@ -77,6 +84,74 @@ let eval _ = let=? result_element = get_element_by_id "result" in El.set_children result_element [ El.txt' result ]; + + (* Update the oposition table *) + let=? div_table = get_element_by_id "tables_div" in + let difficulties = + let fm = fm_element + fm_bonus in + let table = distance_table fm in + Brr.El.tr + [ + Brr.El.th [ Brr.El.txt' "Distance" ] + ; Brr.El.th + [ + Brr.El.txt' "% de toucher (FM" + ; Brr.El.txt @@ Jstr.of_int @@ fm + ; Brr.El.txt' ")" + ] + ; Brr.El.th + [ + Brr.El.txt' "% de toucher (FM" + ; Brr.El.txt @@ Jstr.of_int @@ (fm + 1) + ; Brr.El.txt' ")" + ] + ; Brr.El.th + [ + Brr.El.txt' "% de toucher (FM" + ; Brr.El.txt @@ Jstr.of_int @@ (fm + 2) + ; Brr.El.txt' ")" + ] + ; Brr.El.th + [ + Brr.El.txt' "% de toucher (FM" + ; Brr.El.txt @@ Jstr.of_int @@ (fm + 3) + ; Brr.El.txt' ")" + ] + ] + :: List.init ~len:7 ~f:(fun i -> + Brr.El.tr + (Brr.El.td [ Brr.El.txt (Jstr.of_int (i + 5)) ] + :: List.init ~len:4 ~f:(fun j -> + let cell = + Jstr.of_float ~frac:2 table.(j).(i) |> Brr.El.txt + in + Brr.El.td [ cell ]))) + in + + let table_opposition = + Brr.El.table + @@ Brr.El.tr + [ + Brr.El.th [ Brr.El.txt' "FM" ] + ; Brr.El.th + [ + Brr.El.txt' "% de toucher l’adversaire" + ; Brr.El.txt' " (FM " + ; Brr.El.txt @@ Jstr.of_int env.fm_oponent + ; Brr.El.txt' ")" + ] + ] + :: List.map env.frequencies ~f:(fun (v, value) -> + Brr.El.tr + [ + Brr.El.td [ Brr.El.txt (Jstr.of_int v) ] + ; Brr.El.td + [ Brr.El.txt (Jstr.of_float ~frac:3 (value *. 100.)) ] + ]) + and table_distance = Brr.El.table difficulties in + + El.set_children div_table [ table_opposition; table_distance ]; + () let main () = |