mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 years ago
5 changed files with 109 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||
cmake_minimum_required(VERSION 3.0) |
|||
|
|||
add_library(group OBJECT group.cc) |
@ -0,0 +1,49 @@ |
|||
#include <iostream> |
|||
#include "group.h" |
|||
#include "common.h" |
|||
|
|||
namespace klotski { |
|||
|
|||
using Common::range_reverse; |
|||
|
|||
Group::block_num_t Group::block_num(const RawCode &raw_code) { |
|||
block_num_t result; |
|||
auto tmp = raw_code.unwrap(); |
|||
for (int addr = 0; addr < 20; ++addr, tmp >>= 3) { |
|||
switch (tmp & 0b111) { |
|||
case B_1x1: |
|||
++result.n_1x1; |
|||
continue; |
|||
case B_1x2: |
|||
++result.n_1x2; |
|||
continue; |
|||
case B_2x1: |
|||
++result.n_2x1; |
|||
continue; |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
Group::block_num_t Group::block_num(const CommonCode &common_code) { |
|||
block_num_t result; |
|||
auto range = range_reverse((uint32_t)common_code.unwrap()); |
|||
for (; range; range >>= 2) { |
|||
switch (range & 0b11) { |
|||
case 0b01: /// 1x2 block
|
|||
++result.n_1x2; |
|||
continue; |
|||
case 0b10: /// 2x1 block
|
|||
++result.n_2x1; |
|||
continue; |
|||
case 0b11: /// 1x1 block
|
|||
++result.n_1x1; |
|||
continue; |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
|
|||
} // namespace klotski
|
@ -0,0 +1,23 @@ |
|||
#pragma once |
|||
|
|||
#include <cstdint> |
|||
#include "raw_code.h" |
|||
#include "common_code.h" |
|||
|
|||
namespace klotski { |
|||
|
|||
class Group { |
|||
public: |
|||
|
|||
struct block_num_t { |
|||
uint8_t n_1x1 = 0; |
|||
uint8_t n_1x2 = 0; |
|||
uint8_t n_2x1 = 0; |
|||
}; |
|||
|
|||
static block_num_t block_num(const RawCode &raw_code); |
|||
static block_num_t block_num(const CommonCode &common_code); |
|||
|
|||
}; |
|||
|
|||
} |
Loading…
Reference in new issue