|  |  | @ -2,13 +2,14 @@ | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | #include "group/group.h" | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | using klotski::cases::GroupPro; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | using klotski::codec::RawCode; | 
			
		
	
		
			
				
					|  |  |  | using klotski::codec::CommonCode; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | using klotski::cases::GroupPro; | 
			
		
	
		
			
				
					|  |  |  | using klotski::cases::RangesUnion; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | using klotski::cases::GROUP_PRO_SEED; | 
			
		
	
		
			
				
					|  |  |  | using klotski::cases::GROUP_SEED_MAP; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | RangesUnion GroupPro::cases() const { | 
			
		
	
		
			
				
					|  |  |  |     auto seed = CommonCode::unsafe_create(GROUP_PRO_SEED[flat_id()]); | 
			
		
	
	
		
			
				
					|  |  | @ -36,3 +37,30 @@ RangesUnion GroupPro::cases() const { | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |     return data; | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | static std::unordered_map<uint64_t, GroupPro> build_map_data() { | 
			
		
	
		
			
				
					|  |  |  |     // NOTE: using CommonCode as map key
 | 
			
		
	
		
			
				
					|  |  |  |     std::unordered_map<uint64_t, GroupPro> data; | 
			
		
	
		
			
				
					|  |  |  |     data.reserve(GROUP_SEED_MAP.size()); | 
			
		
	
		
			
				
					|  |  |  |     for (auto raw : GROUP_SEED_MAP) { | 
			
		
	
		
			
				
					|  |  |  |         uint32_t type_id = (raw >> 48) & 0b11111111; | 
			
		
	
		
			
				
					|  |  |  |         uint32_t pattern_id = (raw >> 38) & 0b1111111111; | 
			
		
	
		
			
				
					|  |  |  |         uint32_t toward = (raw >> 36) & 0b11; | 
			
		
	
		
			
				
					|  |  |  |         auto seed = CommonCode::unsafe_create(raw & (uint64_t)0xFFFFFFFFF).unwrap(); | 
			
		
	
		
			
				
					|  |  |  |         auto group = GroupPro::unsafe_create(type_id, pattern_id, toward); | 
			
		
	
		
			
				
					|  |  |  |         data.emplace(seed, group); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |     return data; | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | GroupPro GroupPro::from_raw_code(codec::RawCode raw_code) { | 
			
		
	
		
			
				
					|  |  |  |     static auto map_data = build_map_data(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     auto raw_codes = Group::extend(raw_code); | 
			
		
	
		
			
				
					|  |  |  |     auto common_codes = raw_codes | std::views::transform([](const RawCode r) { | 
			
		
	
		
			
				
					|  |  |  |         return r.to_common_code(); | 
			
		
	
		
			
				
					|  |  |  |     }) | std::ranges::to<std::vector>(); // TODO: search min_element directly
 | 
			
		
	
		
			
				
					|  |  |  |     auto seed = std::min_element(common_codes.begin(), common_codes.end()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     return map_data.at(seed->unwrap()); | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |