-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation.h
164 lines (135 loc) · 3.29 KB
/
operation.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef _OPERATION_H
#define _OPERATION_H
#include "config.h"
class operation{
public:
static row_t getRow(board_t b,int r){
return (b>>(48-16*r) & 0xffff);
}
static row_t getCol(board_t b,int c){
uint64_t colMask = (0xf000f000f000f000 >> (c*4) );
b = (b&colMask) << 4*c;
/*
cout << hex << b << endl;
cout << hex << getRow(b,0) << endl;
cout << hex << getRow(b,1) << endl;
cout << hex << getRow(b,2) << endl;
cout << hex << getRow(b,3) << endl;
*/
return getRow(b,0) | (getRow(b,1) >> 4) | (getRow(b,2) >> 8) | (getRow(b,3) >> 12);
}
static board_t setRow(board_t b, int r, row_t row){
board_t tempRow = row;
switch(r){
case 0:
b = b&0x0000ffffffffffff | (tempRow << 48ULL);
break;
case 1:
b = b&0xffff0000ffffffff | (tempRow << 32ULL);
break;
case 2:
b = b&0xffffffff0000ffff | (tempRow << 16ULL);
break;
case 3:
b = b&0xffffffffffff0000 | tempRow;
break;
default:
cout << "Invalid row number!" << endl;
}
return b;
}
static board_t setCol(board_t b,int c, row_t col){
board_t tempCol = col;
tempCol = (tempCol&0xf000) << 48ULL
| (tempCol&0x0f00) << 36ULL
| (tempCol&0x00f0) << 24ULL
| (tempCol&0x000f) << 12ULL;
tempCol = tempCol >> 4*c;
cout << hex << tempCol << endl;
switch(c){
case 0:
b = (b&0x0fff0fff0fff0fff) | tempCol;
break;
case 1:
b = (b&0xf0fff0fff0fff0ff) | tempCol;
break;
case 2:
b = (b&0xff0fff0fff0fff0f) | tempCol;
break;
case 3:
b = (b&0xfff0fff0fff0fff0) | tempCol;
break;
default:
cout << "Invalid col number!" << endl;
}
return b;
}
static board_t setRows(row_t* rows){
board_t tempRows[4];
board_t b = 0;
for(int i =0; i < 4; i++){
tempRows[i] = rows[i];
tempRows[i] = tempRows[i] << (3-i)*16;
b = b | tempRows[i];
}
return b;
}
static board_t setCols(row_t* cols){
board_t tempCols[4];
board_t b = 0;
for(int i =0; i < 4; i++){
tempCols[i] = cols[i];
tempCols[i] = (tempCols[i]&0xf000) << 48ULL
| (tempCols[i]&0x0f00) << 36ULL
| (tempCols[i]&0x00f0) << 24ULL
| (tempCols[i]&0x000f) << 12ULL;
tempCols[i] = tempCols[i] >> 4*i;
b = b | tempCols[i];
}
return b;
}
static row_t reverseRow(row_t r){
//cout << hex << (r&0x0f00 >> 4) << endl;
return (r&0xf000) >> 12 | (r&0x0f00) >> 4 | (r&0x00f0)<<4 | (r&0x000f) << 12;
}
/*
static int moveRight(row_t& r){
row_t rowMask = 0x000f;
int curCheck = 0;
int score = 0;
bool isMove = false;
for(int i = 1; i <= 3; i++){
int checkNum = (r>>4*curCheck)&rowMask;
int compareNum = (r >> 4*i)&rowMask;
//cout << checkNum << ' ' << compareNum << endl;
if(compareNum == 0){
continue;
}
else if(checkNum == 0){
r += compareNum << curCheck*4;
row_t mask = rowMask << i*4;
mask = ~mask;
r = r&mask;
isMove = true;
}
else if(checkNum == compareNum){
r += (0x0001 << curCheck*4);
row_t mask = rowMask << i*4;
mask = ~mask;
r = r&mask;
curCheck++;
score += configure::tile_score[checkNum+1];
isMove = true;
}
else if(checkNum != compareNum){
curCheck++;
i = curCheck;
}
//cout << curCheck << endl;
//cout << hex << r << endl;
}
if(isMove == false) return -1;
return score;
} */
};
#endif