mirror of https://github.com/dnomd343/klotski.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
2 years ago
|
#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
|