28 for (Square sq2 = b.getAndClearFirstSetBit(); \ 30 sq2 = b.getAndClearFirstSetBit()) \ 33 BoardState newState = state; \ 34 newState.move( Move(sq.col, sq.row, sq2.col, sq2.row), toPlay, Queen ); \ 35 long tmpHeuristic = doSearch(side, curDepth+1, !isMaximising, maxDepth, newState, tmpList); \ 37 if ( (isMaximising && tmpHeuristic > accumulator) || \ 38 (!isMaximising && tmpHeuristic < accumulator) ) \ 40 accumulator = tmpHeuristic; \ 42 moveList.push_front(Move(sq.col, sq.row, sq2.col, sq2.row)); \ 46 Minimax::Minimax(
volatile bool *keepGoing) :
55 long Minimax::search(Side side,
int maxDepth,
BoardState state, MoveList &moveList)
58 return doSearch(side, 0,
true, maxDepth, state, moveList);
61 long Minimax::doSearch(Side side,
int curDepth,
bool isMaximising,
int maxDepth,
BoardState state, MoveList &moveList)
63 if (*m_KeepGoing ==
false)
70 if ( (side == White && isMaximising) || (side == Black && !isMaximising) )
76 if (state.
load(maxDepth-curDepth, toPlay, moveList, h))
83 if (curDepth == maxDepth)
103 long accumulator = (isMaximising) ? -10000000 : 10000000;
107 sq = state.nextPawn(toPlay, &b))
111 for (sq = state.firstKnight(toPlay, &b);
113 sq = state.nextKnight(toPlay, &b))
117 for (sq = state.firstRook(toPlay, &b);
119 sq = state.nextRook(toPlay, &b))
123 for (sq = state.firstBishop(toPlay, &b);
125 sq = state.nextBishop(toPlay, &b))
129 for (sq = state.firstQueen(toPlay, &b);
131 sq = state.nextQueen(toPlay, &b))
135 sq = state.firstKing(toPlay, &b);
139 state.
save(maxDepth-curDepth, toPlay, accumulator, moveList); \
bool load(int minPly, Side toPlay, MoveList &ml, long &h)
Square firstPawn(Side s, Bitboard *b=NULL)
long heuristic(Side side)
void save(int ply, Side toPlay, long h, MoveList &ml)