@@ -36,7 +36,7 @@ impl Point {
3636 Move :: MoveDown => Point :: new ( x, y - 1 ) ,
3737 Move :: MoveRight => Point :: new ( x + 1 , y) ,
3838 Move :: MoveLeft => Point :: new ( x - 1 , y) ,
39- _ => self ,
39+ Move :: Noop => Point :: new ( x , y ) ,
4040 }
4141 }
4242
@@ -47,7 +47,7 @@ impl Point {
4747 Move :: MoveDown => Point :: new ( x, y + 1 ) ,
4848 Move :: MoveRight => Point :: new ( x - 1 , y) ,
4949 Move :: MoveLeft => Point :: new ( x + 1 , y) ,
50- _ => unreachable ! ( ) ,
50+ Move :: Noop => Point :: new ( x , y ) ,
5151 }
5252 }
5353}
@@ -62,7 +62,15 @@ pub struct Map(pub Vec<Point>);
6262
6363impl fmt:: Display for Map {
6464 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
65- write ! ( f, "{}" , self . 0 . iter( ) . map( |p| format!( "{}" , p) ) . collect:: <Vec <_>>( ) . join( "," ) ) ?;
65+ write ! (
66+ f,
67+ "{}" ,
68+ self . 0
69+ . iter( )
70+ . map( |p| format!( "{}" , p) )
71+ . collect:: <Vec <_>>( )
72+ . join( "," )
73+ ) ?;
6674 Ok ( ( ) )
6775 }
6876}
@@ -129,6 +137,10 @@ impl Map {
129137 pub fn len ( & self ) -> usize {
130138 self . 0 . len ( )
131139 }
140+
141+ pub fn is_empty ( & self ) -> bool {
142+ self . 0 . is_empty ( )
143+ }
132144}
133145
134146#[ derive( Debug , Clone , Eq , PartialEq ) ]
@@ -186,13 +198,28 @@ impl fmt::Display for Task {
186198 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
187199 write ! ( f, "{}#" , self . map) ?;
188200 write ! ( f, "{}#" , self . initial) ?;
189- write ! ( f, "{}#" , self . obstacles. iter( ) . map( |o| format!( "{}" , o) ) . collect:: <Vec <_>>( ) . join( ";" ) ) ?;
190- write ! ( f, "{}" , self . boosters. iter( ) . map( |b| format!( "{}" , b) ) . collect:: <Vec <_>>( ) . join( ";" ) ) ?;
201+ write ! (
202+ f,
203+ "{}#" ,
204+ self . obstacles
205+ . iter( )
206+ . map( |o| format!( "{}" , o) )
207+ . collect:: <Vec <_>>( )
208+ . join( ";" )
209+ ) ?;
210+ write ! (
211+ f,
212+ "{}" ,
213+ self . boosters
214+ . iter( )
215+ . map( |b| format!( "{}" , b) )
216+ . collect:: <Vec <_>>( )
217+ . join( ";" )
218+ ) ?;
191219 Ok ( ( ) )
192220 }
193221}
194222
195-
196223#[ derive( Debug , Clone , Eq , PartialEq ) ]
197224pub enum Move {
198225 MoveUp ,
@@ -212,6 +239,7 @@ pub enum Command {
212239 Drill ,
213240 ResetBeacon ,
214241 ShiftBeacon ( Point ) ,
242+ Cloning ,
215243}
216244
217245impl fmt:: Display for Command {
@@ -224,11 +252,12 @@ impl fmt::Display for Command {
224252 Command :: Move ( Move :: Noop ) => write ! ( f, "Z" ) ,
225253 Command :: TurnRight => write ! ( f, "E" ) ,
226254 Command :: TurnLeft => write ! ( f, "Q" ) ,
227- Command :: NewHand ( p) => write ! ( f, "B({}, {})" , p. x, p. y) ,
255+ Command :: NewHand ( p) => write ! ( f, "B({},{})" , p. x, p. y) ,
228256 Command :: FastWheel => write ! ( f, "F" ) ,
229257 Command :: Drill => write ! ( f, "L" ) ,
230258 Command :: ResetBeacon => write ! ( f, "R" ) ,
231- Command :: ShiftBeacon ( p) => write ! ( f, "T({}, {})" , p. x, p. y) ,
259+ Command :: ShiftBeacon ( p) => write ! ( f, "T({},{})" , p. x, p. y) ,
260+ Command :: Cloning => write ! ( f, "C" ) ,
232261 }
233262 }
234263}
@@ -260,12 +289,26 @@ impl Commands {
260289 pub fn len ( & self ) -> usize {
261290 self . 0 [ 0 ] . len ( )
262291 }
292+ pub fn is_empty ( & self ) -> bool {
293+ self . 0 [ 0 ] . is_empty ( )
294+ }
263295}
264296
265297impl fmt:: Display for Commands {
266298 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
267- write ! ( f, "{}" , self . 0 . iter( ) . map( |cmds| {
268- cmds. iter( ) . map( |c| format!( "{}" , c) ) . collect:: <Vec <_>>( ) . join( "" )
269- } ) . collect:: <Vec <_>>( ) . join( "#" ) )
299+ write ! (
300+ f,
301+ "{}" ,
302+ self . 0
303+ . iter( )
304+ . map( |cmds| {
305+ cmds. iter( )
306+ . map( |c| format!( "{}" , c) )
307+ . collect:: <Vec <_>>( )
308+ . join( "" )
309+ } )
310+ . collect:: <Vec <_>>( )
311+ . join( "#" )
312+ )
270313 }
271314}
0 commit comments