-
Notifications
You must be signed in to change notification settings - Fork 37
/
block.h
89 lines (69 loc) · 1.66 KB
/
block.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef _BLOCK_H_
#define _BLOCK_H_
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
typedef unsigned char byte;
#ifndef _BIT_WRITE_
#define _BV(n) (0x01U << (n))
#define _LV(n) (~_BV(n))
#define bitRead(x, n) ((x) & _BV(n))
#define bitSet(x, n) ((x) |= _BV(n))
#define bitClear(x, n) ((x) &= _LV(n))
#define bitWrite(x, n, b) ((b)? bitSet((x),(n)) : bitClear((x), (n)))
#endif
static const char REVERSE[] =
{
0x00, 0x08, 0x04, 0x0c,
0x02, 0x0a, 0x06, 0x0e,
0x01, 0x09, 0x05, 0x0d,
0x03, 0x0b, 0x07, 0x0f,
};
static const unsigned char c_on[] =
{ 0xe2, 0x96, 0xa0, 0x20 };
static const unsigned char c_off[] =
{ 0xe2, 0x96, 0xa1, 0x20 };
class Block
{
public:
Block(char *p, int length, int byte_in_row);
virtual ~Block();
bool isSquare();
void flipInRow();
void flipInCol();
void flipInDiag();
void flipInByte();
enum Direction
{
BIT_IN_COL_NEGA,
BIT_IN_COL_POSI,
BIT_IN_ROW_NEGA,
BIT_IN_ROW_POSI,
};
enum Rotation
{
R0, R90, R180, R270
};
void move(bool recycle = false);
void setMoveDirection(Direction d);
void rotate(Rotation r);
void opposite();
static byte flipByte(byte c);
static std::string byteStringPure(unsigned char c);
static std::string byteString(unsigned char c);
std::string getVarString(int var_per_row = 8);
std::string getPatternString();
private:
byte * const _p;
const int _length;
const int _byte_in_row;
const int _row_count;
void reverseArrayInBit(byte *destination, byte *source, int length);
void moveBitInColNega(bool recycle);
void moveBitInColPosi(bool recycle);
void moveBitInRowNega(bool recycle);
void moveBitInRowPosi(bool recycle);
void (Block::*_move)(bool);
};
#endif