File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments