add code for 84 (WIP)

This commit is contained in:
Dr. Matthias Ratajczak
2022-09-27 18:17:24 +02:00
parent 86e7811a16
commit 64c5cc1aae
2 changed files with 30 additions and 5 deletions
+29 -4
View File
@@ -56,6 +56,20 @@ pub enum Squares {
enum CommunityChest {
AdvanceToGo,
GoToJail,
DoNothing1,
DoNothing2,
DoNothing3,
DoNothing4,
DoNothing5,
DoNothing6,
DoNothing7,
DoNothing8,
DoNothing9,
DoNothing10,
DoNothing11,
DoNothing12,
DoNothing13,
DoNothing14,
}
#[derive(Debug, EnumIter, Clone)]
@@ -70,6 +84,12 @@ enum Chance {
GoToNextRAgain,
GoToNextU,
GoBack3Squares,
DoNothing1,
DoNothing2,
DoNothing3,
DoNothing4,
DoNothing5,
DoNothing6,
}
#[derive(Debug)]
@@ -143,8 +163,11 @@ impl Monopoly {
let square = self.board.nth(distance).unwrap();
match square {
Squares::G2J => self.go_to_jail(),
Squares::CC1 | Squares::CC2 | Squares::CC3 => self.handle_community_chest(),
Squares::CH1 | Squares::CH2 => self.handle_chance(),
Squares::CC1 => self.handle_community_chest(Squares::CC1),
Squares::CC2 => self.handle_community_chest(Squares::CC2),
Squares::CC3 => self.handle_community_chest(Squares::CC3),
Squares::CH1 => self.handle_chance(Squares::CH1),
Squares::CH2 => self.handle_chance(Squares::CH2),
_ => square,
}
}
@@ -154,7 +177,7 @@ impl Monopoly {
Squares::Jail
}
fn handle_chance(&mut self) -> Squares {
fn handle_chance(&mut self, square: Squares) -> Squares {
let card = self.draw_from_chance_pile_and_put_at_bottom();
// dbg!(card);
match card {
@@ -167,6 +190,7 @@ impl Monopoly {
Chance::GoToNextR | Chance::GoToNextRAgain => self.go_to_railway(),
Chance::GoToNextU => self.go_to_utility(),
Chance::GoBack3Squares => self.go_back_3_squares(),
_ => square,
}
}
@@ -181,11 +205,12 @@ impl Monopoly {
result
}
fn handle_community_chest(&mut self) -> Squares {
fn handle_community_chest(&mut self, square: Squares) -> Squares {
let card = self.draw_from_community_chest_pile_and_put_at_bottom();
match card {
CommunityChest::AdvanceToGo => self.advance_to_go(),
CommunityChest::GoToJail => self.go_to_jail(),
_ => square,
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ mod lib;
fn main() {
let monopoly = lib::Monopoly::new();
let mut statistics = lib::Statistics::new(monopoly, 100_000);
let mut statistics = lib::Statistics::new(monopoly, 10_000_000);
statistics.run();
statistics.show();
}