@@ -37,10 +37,11 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
3737 let mut ip = Interpreter :: new ( ) ;
3838
3939 loop {
40- debug_print ( args. verbose , & format ! ( "{:?}" , ip. cur) ) ;
4140 let cur_codel = img. get_codel_at ( ip. cur ) ;
4241 assert ! ( !cur_codel. is_black( ) ) ;
4342 if !cur_codel. is_white ( ) {
43+ debug_print ( args. verbose , & format ! ( "{:?}" , ip. cur) ) ;
44+
4445 let iter_max = 8 ; //changes `dp` and `cc` at most 7 times
4546 for i in 0 ..iter_max {
4647 //[spec]
@@ -94,12 +95,14 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
9495 //See `White Blocks` section in the spec: https://www.dangermouse.net/esoteric/piet.html
9596
9697 let mut visited = FxHashSet :: default ( ) ;
98+
99+ //FIXME: Currently, the average number of iterations needed to find a non-white codel or wall is the size of the current white block.
100+ // Ideally it should be O(1) (like `Block::get_corner_index()`).
97101 loop {
98- let cur_codel = img. get_codel_at ( ip. cur ) ;
99- if visited. contains ( & ( cur_codel, ip. dp ) ) {
102+ if visited. contains ( & ( ip. cur , ip. dp ) ) {
100103 return Ok ( ( ) ) ;
101104 }
102- visited. insert ( ( cur_codel , ip. dp ) ) ;
105+ visited. insert ( ( ip . cur , ip. dp ) ) ;
103106
104107 let next_index = img. get_next_codel_index_in_dp_direction ( ip. cur , & ip. dp ) ;
105108 if next_index. is_none ( ) {
@@ -113,8 +116,15 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
113116 ip. dp = ip. dp . turn_right ( ) ;
114117 continue ;
115118 }
119+
120+ debug_print ( args. verbose , & format ! ( "{:?}" , ip. cur) ) ;
121+
116122 ip. cur = next_index. unwrap ( ) ;
117123
124+ if next_codel. is_white ( ) {
125+ continue ;
126+ }
127+
118128 //spec: If the transition between colour blocks occurs via a slide across a white block, no command is executed.
119129
120130 break ;
0 commit comments