diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2024-02-24 11:31:28 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2024-02-24 11:31:28 +0100 |
commit | ef9beb0814c36cda979a4ed7e9175e72e69540ac (patch) | |
tree | c2852b1dd5df53f5d78e9e952f29360d50126e06 /calculette_aoo/lib/carac.ml | |
parent | 9e7f27c60a425e2baa67cd459d8509a43b1d123d (diff) |
New application: build upgrade helper for aoo
Diffstat (limited to 'calculette_aoo/lib/carac.ml')
-rw-r--r-- | calculette_aoo/lib/carac.ml | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/calculette_aoo/lib/carac.ml b/calculette_aoo/lib/carac.ml new file mode 100644 index 0000000..a48c734 --- /dev/null +++ b/calculette_aoo/lib/carac.ml @@ -0,0 +1,40 @@ +type cout_carac = int * int * int + +type t = { + value : int + ; couts : cout_carac + ; bonus : int +} + +let create : ?bonus:int -> int -> cout_carac -> t = + fun ?(bonus = 0) value couts -> { value; couts; bonus } + +let incr ?(step = 1) t = { t with bonus = t.bonus + step } + +(* +Evaluate the cost for the successives upgrades. + +I’m pretty sure this can be transformed into a linear function, but I do not see how… + + c0 * t.bonus ++ max 0 ((((t.bonus - 1) * 2) - 1) * c1) ++ ? + + *) +let cout : t -> int = + fun t -> + let c0, c1, c2 = t.couts in + let rec c acc t = + match t with + | 0 -> acc + | 1 -> acc + c0 + | 2 -> c (acc + c0 + c1) (t - 1) + | 3 -> c (acc + c0 + (c1 * 2)) (t - 1) + | n -> c (acc + c0 + (c1 * 2) + ((n - 3) * c2)) (t - 1) + in + c 0 t.bonus + +let value t = t.value + t.bonus + +let repr : Format.formatter -> t -> unit = + fun out t -> Format.fprintf out "%d (+%d)" (value t) t.bonus |