File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,26 @@ impl LoggingEngine {
30
30
}
31
31
fn log_action ( env : & Env , action : & ActionItem ) {
32
32
let mut actions = Self :: actions ( env. clone ( ) ) ;
33
- actions. push_back ( * action) ;
33
+ let add_action: ActionItem ;
34
+
35
+ if let Some ( Ok ( last_action_item) ) = actions. last ( ) {
36
+ match last_action_item {
37
+ ActionItem ( Action :: Turn , _) if action. 0 == Action :: Turn => {
38
+ actions. pop_back ( ) ;
39
+ add_action = action. clone ( ) ;
40
+ }
41
+ ActionItem ( Action :: Move , _) if action. 0 == Action :: Move => {
42
+ actions. pop_back ( ) ;
43
+ add_action = ActionItem ( last_action_item. 0 , last_action_item. 1 + ( action. 1 as u32 ) ) ;
44
+
45
+ }
46
+ _ => add_action = * action,
47
+ }
48
+ } else {
49
+ add_action = * action;
50
+ }
51
+
52
+ actions. push_back ( add_action) ;
34
53
env. storage ( ) . set ( & ACTIONS , & actions) ;
35
54
}
36
55
@@ -73,7 +92,7 @@ impl LoggingEngine {
73
92
if let Err ( Ok ( e) ) = Self :: get_engine ( & env) . try_p_move ( & times) {
74
93
return Err ( e) ;
75
94
}
76
- Self :: log_action ( & env, & ActionItem ( Action :: Move , 1 ) ) ;
95
+ Self :: log_action ( & env, & ActionItem ( Action :: Move , times . unwrap_or ( 1 ) ) ) ;
77
96
Ok ( ( ) )
78
97
}
79
98
pub fn p_shoot ( env : Env ) -> Result < ( ) , game_engine:: Error > {
Original file line number Diff line number Diff line change 1
1
#![ no_std]
2
2
3
- use engine:: Client as GameEngine ;
3
+ use engine:: { Client as GameEngine , Direction } ;
4
4
use soroban_sdk:: { contractimpl, BytesN , Env } ;
5
5
6
6
pub struct Solution ;
@@ -19,6 +19,12 @@ impl Solution {
19
19
// YOUR CODE START
20
20
21
21
engine. p_shoot ( ) ;
22
+ engine. p_move ( & None ) ;
23
+ engine. p_move ( & Some ( 2 ) ) ;
24
+ engine. p_turn ( & Direction :: UpLeft ) ;
25
+ engine. p_turn ( & Direction :: Left ) ;
26
+ engine. p_move ( & Some ( 1 ) ) ;
27
+ engine. p_turn ( & Direction :: Down ) ;
22
28
// YOUR CODE END
23
29
}
24
30
}
You can’t perform that action at this time.
0 commit comments