| 
						
						
							
								
							
						
						
					 | 
					@ -4,21 +4,29 @@ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					#include "fast_cal.h" | 
					 | 
					 | 
					#include "fast_cal.h" | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					#include "raw_code.h" | 
					 | 
					 | 
					#include "raw_code.h" | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					/// klotski resolved -> 2x2 block at address 13 (aka 0xD)
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					auto resolved = [](uint64_t code) { | 
					 | 
					 | 
					auto resolved = [](uint64_t code) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // check 2x2 block address
 | 
					 | 
					 | 
					    return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // check 2x2 block address
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					}; | 
					 | 
					 | 
					}; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					/// klotski resolved -> 2x2 block at address 13 (aka 0xD)
 | 
					 | 
					 | 
					RawCode FastCal::solve(const RawCode &code) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					RawCode FastCal::solve(RawCode code) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    return FastCal::target(code, resolved); | 
					 | 
					 | 
					    return FastCal::target(code, resolved); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					std::vector<RawCode> FastCal::solve_multi(RawCode code) { | 
					 | 
					 | 
					std::vector<RawCode> FastCal::solve_multi(const RawCode &code) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    return FastCal::target_multi(code, resolved); | 
					 | 
					 | 
					    return FastCal::target_multi(code, resolved); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					std::vector<RawCode> FastCal::resolve(const RawCode &start) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    return FastCal::search(start, resolved); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					std::vector<std::vector<RawCode>> FastCal::resolve_multi(const RawCode &start) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    return FastCal::search_multi(start, resolved); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					/// backtrack of FastCal tree
 | 
					 | 
					 | 
					/// backtrack of FastCal tree
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					int FastCal::step_num(RawCode code) { | 
					 | 
					 | 
					int FastCal::step_num(const RawCode &code) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    auto tmp = cases.find((uint64_t)code); | 
					 | 
					 | 
					    auto tmp = cases.find((uint64_t)code); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    if (tmp == cases.end()) { | 
					 | 
					 | 
					    if (tmp == cases.end()) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        return -1; // code not exist
 | 
					 | 
					 | 
					        return -1; // code not exist
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -46,15 +54,8 @@ std::vector<RawCode> FastCal::backtrack(const RawCode &code) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    return path; | 
					 | 
					 | 
					    return path; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					std::vector<RawCode> FastCal::resolve(RawCode start) { | 
					 | 
					 | 
					/// static BFS search functions
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    return FastCal::search(start, resolved); | 
					 | 
					 | 
					std::vector<std::vector<RawCode>> FastCal::to_furthest(const RawCode &start) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					std::vector<std::vector<RawCode>> FastCal::resolve_multi(RawCode start) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    return FastCal::search_multi(start, resolved); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					std::vector<std::vector<RawCode>> FastCal::to_furthest(RawCode start) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    auto fc = FastCal(); | 
					 | 
					 | 
					    auto fc = FastCal(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    std::vector<std::vector<RawCode>> result; | 
					 | 
					 | 
					    std::vector<std::vector<RawCode>> result; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    for (const auto &furthest : fc.furthest(start)) { | 
					 | 
					 | 
					    for (const auto &furthest : fc.furthest(start)) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -63,7 +64,7 @@ std::vector<std::vector<RawCode>> FastCal::to_furthest(RawCode start) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    return result; | 
					 | 
					 | 
					    return result; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					std::vector<RawCode> FastCal::search(RawCode start, const match_t &match) { | 
					 | 
					 | 
					std::vector<RawCode> FastCal::search(const RawCode &start, const match_t &match) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    auto fc = FastCal(); | 
					 | 
					 | 
					    auto fc = FastCal(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    auto result = fc.target(start, match); | 
					 | 
					 | 
					    auto result = fc.target(start, match); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    if (result == FC_NOT_FOUND) { | 
					 | 
					 | 
					    if (result == FC_NOT_FOUND) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -72,7 +73,7 @@ std::vector<RawCode> FastCal::search(RawCode start, const match_t &match) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    return fc.backtrack(result); // backtrack target path
 | 
					 | 
					 | 
					    return fc.backtrack(result); // backtrack target path
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					std::vector<std::vector<RawCode>> FastCal::search_multi(RawCode start, const match_t &match) { | 
					 | 
					 | 
					std::vector<std::vector<RawCode>> FastCal::search_multi(const RawCode &start, const match_t &match) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    auto fc = FastCal(); | 
					 | 
					 | 
					    auto fc = FastCal(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    std::vector<std::vector<RawCode>> result; | 
					 | 
					 | 
					    std::vector<std::vector<RawCode>> result; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    for (const auto &target : fc.target_multi(start, match)) { | 
					 | 
					 | 
					    for (const auto &target : fc.target_multi(start, match)) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |