-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.h
More file actions
114 lines (87 loc) · 2.1 KB
/
player.h
File metadata and controls
114 lines (87 loc) · 2.1 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Created by dpoole on 6/24/24.
//
#ifndef MONOP_PLAYER_H
#define MONOP_PLAYER_H
#include "board.h"
#include "dice.h"
struct PlayerStats
{
// counters;
uint moves;
uint passed_go;
uint properties_purchased;
uint money_spent;
uint doubles;
uint rent_paid;
uint rent_earned;
uint taxes_paid;
int go_to_jail;
};
class Player
{
public:
explicit Player(std::string name, int cash) :
name{std::move(name)},
cash{cash},
stats{{}}
{};
std::pair<uint,uint> roll()
{
die1 = roll_die();
die2 = roll_die();
if (die1 == die2) {
stats.doubles += 1;
}
return std::make_pair(die1,die2);
}
void sanity_check() const
{
// sanity check as the game continues
if (cash < 0) {
std::string msg = fmt::format("error! player {} has negative cash={}\n", name, cash);
throw std::runtime_error(msg);
}
}
uint move();
void add_money(int new_money) { cash += new_money; }
[[nodiscard]] bool passed_go() const { return _passed_go; }
const std::string name{};
bool buys(const Property &property);
bool buys(const Railroad &rr);
[[nodiscard]] uint railroads_owned() const { return _railroads_owned; }
std::string get_stats();
[[nodiscard]] std::vector<uint>::const_iterator owned_cbegin() const {
return property_owned.cbegin();
}
[[nodiscard]] std::vector<uint>::const_iterator owned_cend() const {
return property_owned.cend();
}
uint pay_rent(uint rent);
void pay_tax(uint tax);
void earn_rent(uint rent) {
add_money(rent);
stats.rent_earned += rent;
}
void go_to_jail();
[[nodiscard]] bool in_jail() const { return jail_counter > 0; };
void leave_jail() { jail_counter = 0; };
[[nodiscard]] bool do_jail_turn()
{
// TODO add option for $50 bail
return ++jail_counter > 3;
};
private:
// note signed integer so can detect negative
int cash {0};
// where I am on the board (index)
uint position {0};
uint die1 {0}, die2 {0};
bool _passed_go {false};
uint jail_counter {0};
std::vector<uint> property_owned {};
uint _railroads_owned {0};
struct PlayerStats stats {};
bool buy_something(const std::string & name, uint price);
};
#endif //MONOP_PLAYER_H