-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.ml
67 lines (50 loc) · 1.31 KB
/
player.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
65
66
67
type player_name = string
type player_style = ANSITerminal.style list
type troop_count = int
type territories = Territory.t list
type t =
{
name: player_name;
mutable troops: troop_count;
mutable territories: territories;
styles: player_style;
mutable cards: int;
}
let init name bg_color =
{
name = name;
troops = 0;
territories = [];
styles = [Bold; bg_color];
cards = 0;
}
let get_name player =
player.name
let get_count player =
player.troops
let get_territories player =
player.territories
let get_styles player =
player.styles
let get_cards player =
player.cards
let add_troops troops_add player =
{
player with troops = player.troops + troops_add
}
let update_troops player =
player.troops <- List.fold_left (fun x terr ->
x + Territory.get_count terr) 0 player.territories
let add_territory territory_add player =
{
player with territories = territory_add :: player.territories
}
let add_territory_unit territory_add player =
player.territories <- territory_add :: player.territories
let del_territory_unit territory_del player =
player.territories <- List.filter (fun terr ->
terr <> territory_del) player.territories
let add_card player =
player.cards <- player.cards + 1
let set_cards player num =
player.cards <- num