-
Notifications
You must be signed in to change notification settings - Fork 0
/
territory.ml
64 lines (48 loc) · 1.22 KB
/
territory.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
open Yojson.Basic.Util
type territory_name = string
type territory_owner = string
type troop_count = int
type territory_neighbors = territory_name list
type t =
{
terr_name: territory_name;
mutable owner: territory_owner;
mutable troops: troop_count;
neighbors: territory_neighbors;
}
let init json =
{
terr_name = json
|> member "name"
|> to_string;
owner = "None";
troops = 0;
neighbors = json
|> member "neighbors"
|> to_list
|> List.map to_string;
}
let get_name territory =
territory.terr_name
let get_owner territory =
territory.owner
let get_count territory =
territory.troops
let get_neighbors territory =
territory.neighbors
let set_owner territory new_owner =
{
territory with owner = new_owner
}
let set_owner_unit territory new_owner =
territory.owner <- new_owner
let set_count territory count =
{
territory with troops = count
}
let set_count_unit territory count =
territory.troops <- count
let add_count territory add_troops =
territory.troops <- add_troops + territory.troops
let sub_count territory sub_troops =
territory.troops <- territory.troops - sub_troops