diff options
Diffstat (limited to 'calculette_aoo/lib/build.ml')
-rw-r--r-- | calculette_aoo/lib/build.ml | 58 |
1 files changed, 21 insertions, 37 deletions
diff --git a/calculette_aoo/lib/build.ml b/calculette_aoo/lib/build.ml index ddefe67..5c2ac0b 100644 --- a/calculette_aoo/lib/build.ml +++ b/calculette_aoo/lib/build.ml @@ -9,54 +9,41 @@ type build = { type env = { cout_sort : int ; degat_sort : int - ; max_tours : float + ; max_tours : int ; fm_oponent : int ; cost_max : int ; frequencies : (int * float) list } -let roll_and_accumulate dices = - Seq.repeat () |> Seq.take dices - |> Seq.fold_left (fun res _ -> res + (1 + Random.int 3)) 0 - -let delta_carac level thresold = - Seq.repeat () |> Seq.take 10000 - |> Seq.fold_left - (fun acc _ -> - if roll_and_accumulate thresold > roll_and_accumulate level then acc - else acc + 1) - 0 - let get_chance : env -> int -> float = fun env delta -> match List.assoc_opt delta env.frequencies with - | None -> 1.0 + | None -> 1. | Some v -> v (** Build a list with the differents percentages to hit *) let buil_freq_table from thresold = - let () = Random.self_init () in - List.init 6 (fun i -> - (from - thresold + i, float (delta_carac (from + i) thresold) /. 10000.)) + List.init 10 (fun i -> + (from + i, Roll.compare (from + i) thresold |> Q.to_float)) -let eval : build -> env -> float * float = +let eval : build -> env -> float * int = fun { a; m; rm; pm; fm } env -> - let cout_tour = (Carac.value a * env.cout_sort) - Carac.value rm in - let nb_tour = - if cout_tour > 0 then - float (Carac.value pm) /. float cout_tour |> Float.min env.max_tours - else env.max_tours + let mp_available = Carac.value pm + ((env.max_tours - 1) * Carac.value rm) in + + (* How many attacks can be done using this cost ? (rounded down) *) + let nb_attacks = + min (env.max_tours * Carac.value a) (mp_available / env.cout_sort) in let degats = - float (Carac.value a * (env.degat_sort + Carac.value m - 5)) - *. get_chance env (Carac.value fm - env.fm_oponent) + float (nb_attacks * (env.degat_sort + Carac.value m - 5)) + *. get_chance env (Carac.value fm) in - (degats, nb_tour) + (degats, nb_attacks) let repr_degats : env -> Format.formatter -> build -> unit = fun env out build -> - let delta = get_chance env (Carac.value build.fm - env.fm_oponent) in + let delta = get_chance env (Carac.value build.fm) in Format.fprintf out "%d A × (%d du sorts + %d M - %d M) × %.2f %%" (Carac.value build.a) env.degat_sort (Carac.value build.m) 5 (delta *. 100.); let sum = env.degat_sort + Carac.value build.m - 5 in @@ -71,7 +58,7 @@ let cost : build -> int = let repr : env -> Format.formatter -> build -> unit = fun env formatter build -> - let degats, nb_tour = eval build env in + let degats, nb_attacks = eval build env in Format.fprintf formatter {|Caractéristiques retenues : @@ -84,18 +71,17 @@ let repr : env -> Format.formatter -> build -> unit = Carac.repr build.a Carac.repr build.m Carac.repr build.fm Carac.repr build.rm Carac.repr build.pm; Format.fprintf formatter - "@[Le magicien fera %.2f degats par tour pour un total de %d sur %.2f \ - tours@;\ + "@[Le magicien fera %.2f degats par attaque pour un total de %.2f (via %d \ + attaques)@;\ (@[<v 2>%a@])@;" - degats - (int_of_float (nb_tour *. degats)) - nb_tour (repr_degats env) build; + (degats /. float_of_int nb_attacks) + degats nb_attacks (repr_degats env) build; Format.fprintf formatter "Le cout de ce build est de %d@]@." (cost build) let score : env -> build -> float = fun env build -> let d, v = eval build env in - d *. v + d (* Upgrade each caracteristic and keep only the values in range *) let upgrade : env -> build -> build list = @@ -125,9 +111,7 @@ let rec traverse env (last_cost, last_score) = function upgrade env hd |> List.filter (fun build -> List.for_all - (fun element -> - cost build > cost element - || score env build > score env element) + (fun element -> score env build > score env element) tl) in |