-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxiJumpSequenceFinder.cpp
62 lines (49 loc) · 2.16 KB
/
MaxiJumpSequenceFinder.cpp
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
#include "MaxiJumpSequenceFinder.h"
void MaxiJumpSequenceFinder::solvePawn(PawnState state){
if(dp.count(state) > 0)
return;
dp[state] = 0;
std::vector<std::pair<int,int> > cells = {{1,1},{-1,1},{-1,-1},{1,-1}};
for(int i=0;i<cells.size();i++){
int ex = cells[i].first, ey = cells[i].second;
if(canJumpOver(state.x+ex,state.y+ey,ex,ey)){
PawnState newState = state;
newState.x += ex*2;
newState.y += ey*2;
newState.pawnMask |= (1<<pawnPositionToId[state.x+ex][state.y+ey]);
Checker backedUp = board[state.x+ex][state.y+ey];
board[state.x+ex][state.y+ey] = Checker::jumped_over;
solvePawn(newState);
dp[state] = std::max(dp[state],dp[newState]+1);
maxi = std::max(maxi,dp[state]);
board[state.x+ex][state.y+ey] = backedUp;
}
}
}
void MaxiJumpSequenceFinder::solveQueen(PawnState state){
if(dp.count(state) != 0)
return;
dp[state] = 0;
std::vector<std::pair<int,int> > cells = {{1,1},{-1,1},{-1,-1},{1,-1}};
for(int i=0;i<cells.size();i++){
int ex = cells[i].first, ey = cells[i].second;
int j = 1;
while(isInBoard(state.x + j*ex, state.y + j*ey) && board[state.x + j*ex][state.y + j*ey] == Checker::empty)
j++;
if(isInBoard(state.x + j*ex, state.y + j*ey) && isEnemyChecker(whiteOnTurn,board[state.x + j*ex][state.y + j*ey])){
int j2 = j+1;
while(isInBoard(state.x + j2*ex, state.y + j2*ey) && board[state.x + j2*ex][state.y + j2*ey] == Checker::empty){
PawnState newState = state;
newState.x += j2*ex;
newState.y += j2*ey;
newState.pawnMask |= (1<<pawnPositionToId[state.x+j*ex][state.y+j*ey]);
Checker backedUp = board[state.x + j*ex][state.y + j*ey];
board[state.x + j*ex][state.y + j*ey] = Checker::jumped_over;
solveQueen(newState);
dp[state] = std::max(dp[state],dp[newState]+1);
board[state.x + j*ex][state.y + j*ey] = backedUp;
j2++;
}
}
}
}