Skip to content

Commit 7f1aa1b

Browse files
committed
refactor: Update GameState to include carrot collection logic
1 parent 2c81152 commit 7f1aa1b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/plugin/game_state.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ impl GameState {
4040
let mut new_state = self.clone();
4141
r#move.perform(&mut new_state)?;
4242
new_state.turn += 1;
43+
44+
fn update_carrots(player: &mut Hare, opponent_position: usize, board: &Board) {
45+
match board.get_field(player.position) {
46+
Some(Field::Position1) if player.position > opponent_position => {
47+
player.carrots += 10
48+
}
49+
Some(Field::Position2) if player.position > opponent_position => {
50+
player.carrots += 30
51+
}
52+
_ => {}
53+
}
54+
}
55+
56+
update_carrots(
57+
&mut new_state.player_one,
58+
new_state.player_two.position,
59+
&new_state.board,
60+
);
61+
update_carrots(
62+
&mut new_state.player_two,
63+
new_state.player_one.position,
64+
&new_state.board,
65+
);
66+
4367
Ok(new_state)
4468
}
4569

0 commit comments

Comments
 (0)