Move MoveGen::next() { Move res; loop: switch( *phPtr ) { case mpHash: res = killer->hashMove; phPtr++; if ( !res || !(board.inCheck() ? board.isLegal<1,0>( res, pins() ) : board.isLegal<0,0>( res, pins() ) ) ) goto loop; genMoves[ genMoveCount++ ] = res; break; case mpKiller1: res = killer->killers[0]; phPtr++; if ( !res || alreadyGenerated(res) || !(board.inCheck() ? board.isLegal<1,1>( res, pins() ) : board.isLegal<0,1>( res, pins() ) ) ) goto loop; genMoves[ genMoveCount++ ] = res; break; case mpKiller2: res = killer->killers[1]; phPtr++; if ( !res || alreadyGenerated(res) || !(board.inCheck() ? board.isLegal<1,1>( res, pins() ) : board.isLegal<0,1>( res, pins() ) ) ) goto loop; genMoves[ genMoveCount++ ] = res; break; case mpCapNoSort: count = generateCaptures( board, moveBuf ); index = 0; phPtr++; goto loop; break; case mpCap: count = generateCaptures( board, moveBuf ); index = badCapCount = 0; scoreCaptures(); phPtr++; goto loop; break; case mpBadCap: index = 0; phPtr++; goto loop; break; case mpQCap: count = generateCaptures( board, moveBuf, 0 ); index = 0; scoreCaptures(); phPtr++; goto loop; break; case mpQChecks: count = board.turn() == ctWhite ? generateChecks< ctWhite >( moveBuf ) : generateChecks< ctBlack >( moveBuf ); scoreChecks(); index = 0; phPtr++; goto loop; break; case mpCastling: assert( board.canCastle() ); index = 0; count = board.turn() == ctWhite ? generateCastling< ctWhite >( board, moveBuf ) : generateCastling< ctBlack >( board, moveBuf ); phPtr++; goto loop; break; case mpQuietNoSort: count = generateQuiet( board, moveBuf ); index = 0; phPtr++; goto loop; break; case mpQuiet: count = generateQuiet( board, moveBuf ); scoreQuiet(); index = 0; phPtr++; goto loop; break; case mpEvasNoSort: count = generateEvasions( board, moveBuf ); index = 0; phPtr++; goto loop; break; case mpEvas: count = generateEvasions( board, moveBuf ); scoreEvasions(); index = 0; phPtr++; goto loop; break; case mpCapBuffer: // here we'll ocassionally move to badcaps so it's different do { loopcap: if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; if ( alreadyGenerated(res) ) goto loopcap; // do fast(sign) see if ( board.see<1>(res) < 0 ) { // bad capture detected assert( badCapCount < maxCaptures ); badCaps[ badCapCount++ ] = res; goto loopcap; } } while( !board.pseudoIsLegal<0>( res, pin ) ); break; case mpQCapBuffer: // here we'll ocassionally move to badcaps so it's different do { qloopcap: if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; if ( alreadyGenerated(res) ) goto qloopcap; // do fast(sign) see if ( board.see<1>( res ) < 0 ) // bad capture detected goto qloopcap; } while( !board.pseudoIsLegal<0>( res, pin ) ); break; case mpCastlingBuffer: if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; if ( alreadyGenerated(res) ) goto loop; break; case mpCastlingBufferLegal: if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; break; case mpEvasBuffer: do { if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; } while ( alreadyGenerated(res) || !board.pseudoIsLegal<1>( res, pin ) ); break; case mpEvasBufferLegal: do { if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; } while ( !board.pseudoIsLegal<1>( res, pin ) ); break; case mpBufferLegal: do { if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; } while ( !board.pseudoIsLegal<0>( res, pin ) ); break; case mpQuietBuffer: do { if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; } while ( alreadyGenerated(res) || !board.pseudoIsLegal<0>( res, pin ) ); break; case mpQChecksBuffer: do { checksloop: if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; if ( alreadyGenerated(res) ) goto checksloop; if ( MovePack::isCastling(res) ) break; if ( board.see<1>( res ) < 0 ) continue; // skip bad see checks } while ( !board.pseudoIsLegal<0>( res, pin ) ); assert( board.isCheck( res, dcMask ) ); break; case mpBadCapBuffer: do { if ( index >= badCapCount ) { phPtr++; goto loop; } res = badCaps[ index++ ]; } while( alreadyGenerated(res) || !board.pseudoIsLegal<0>( res, pin ) ); break; default: //case mpDone: res = mcNone; break; } return res & mmNoScore; // remove score }
Move MoveGen::next() { Move res; loop: switch( *phPtr ) { case mpCapNoSort: count = generateCaptures( board, moveBuf ); index = 0; phPtr++; goto loop; break; case mpCastling: assert( board.canCastle() ); index = 0; count = board.turn() == ctWhite ? generateCastling< ctWhite >( board, moveBuf ) : generateCastling< ctBlack >( board, moveBuf ); phPtr++; goto loop; break; case mpQuietNoSort: count = generateQuiet( board, moveBuf ); index = 0; phPtr++; goto loop; break; case mpEvasNoSort: count = generateEvasions( board, moveBuf ); index = 0; phPtr++; goto loop; break; case mpCastlingBuffer: if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; break; case mpEvasBuffer: do { if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; } while ( !board.pseudoIsLegal<1>( res, pin ) ); break; case mpCapBufferNoSort: case mpQuietBuffer: do { if ( index >= count ) { phPtr++; goto loop; } res = moveBuf[ index++ ]; } while ( !board.pseudoIsLegal<0>( res, pin ) ); break; default: //case mpDone: res = mcNone; break; } return res & mmNoScore; // remove score }