-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregion.ml
44 lines (36 loc) · 850 Bytes
/
region.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
open Yojson.Basic.Util
type regions
type name = string
type t =
{
region_name: name;
bonus: int;
territories: string list;
}
(** [get_territory_name_from_json] is the name of the territory corresponding
to [json].
Requires:
[json] is a valid json representation for a territory
*)
let get_territory_name_from_json json =
json
|> member "name"
|> to_string
let init json = {
region_name = json
|> member "name"
|> to_string;
bonus = json
|> member "bonus"
|> to_int;
territories = json
|> member "territories"
|> to_list
|> List.map get_territory_name_from_json;
}
let get_region_name region =
region.region_name
let get_bonus region =
region.bonus
let get_territories region =
region.territories