Beispiel #1
0
bool is_attacked(Board* board, int index, bool white_attacking) {
    if (white_attacking) {
        if (black_pawn_attacks[index] & board->white_pawns)
            return true;
        if (knight_movelocs[index] & board->white_knights)
            return true;
        if (Bmagic(index, board->all_pieces) & (board->white_bishops | board->white_queens))
            return true;
        if (Rmagic(index, board->all_pieces) & (board->white_rooks | board->white_queens))
            return true;
        if (king_movelocs[index] & board->white_king)
            return true;
        return false;
    } else {
        if (white_pawn_attacks[index] & board->black_pawns)
            return true;
        if (knight_movelocs[index] & board->black_knights)
            return true;
        if (Bmagic(index, board->all_pieces) & (board->black_bishops | board->black_queens))
            return true;
        if (Rmagic(index, board->all_pieces) & (board->black_rooks | board->black_queens))
            return true;
        if (king_movelocs[index] & board->black_king)
            return true;
        return false;
    }
}
Beispiel #2
0
Score EvaluateBishops(uint64_t bb, Phase phase, uint64_t safeDestinations, uint64_t occupancy)
{
	Score ret = 0;

	if (PopCount(bb) >= 2)
	{
		ret += ScalePhase(BISHOP_PAIR_BONUS[0], BISHOP_PAIR_BONUS[1], phase);
	}

	while (bb)
	{
		uint32_t idx = Extract(bb);

		uint32_t mobility = PopCount(Bmagic(idx, occupancy) & safeDestinations);

		ret += ScalePhase(BISHOP_MOBILITY[0][mobility] * MOBILITY_MULTIPLIERS[0],
						  BISHOP_MOBILITY[1][mobility] * MOBILITY_MULTIPLIERS[1], phase);

		if (COLOR == BLACK)
		{
			idx = FLIP[idx];
		}

		ret += ScalePhase(BISHOP_PCSQ[0][idx], BISHOP_PCSQ[1][idx], phase);
	}

	return ret;
}
Beispiel #3
0
static int atak(lua_State *L) {
    int piece, square, colour;
    U64 *ret = NULL;
    U64 *occupancy = NULL;

    /* Get function arguments */
    piece = luaL_checkinteger(L, 1);
    if (piece < PAWN || piece > KING)
        return luaL_argerror(L, 1, "invalid piece");
    square = luaL_checkinteger(L, 2);
    if (square < 0 || square > 63)
        return luaL_argerror(L, 2, "invalid square");
    if (!lua_isnoneornil(L, 3)) {
        colour = luaL_checkinteger(L, 3);
        if (colour < WHITE || colour > BLACK)
            return luaL_argerror(L, 3, "invalid colour");
    }
    else colour = NOCOLOUR;
    if (!lua_isnoneornil(L, 4))
        occupancy = luaL_checkudata(L, 4, BITBOARD_T);

    ret = (U64 *)lua_newuserdata(L, sizeof(U64));
    luaL_getmetatable(L, BITBOARD_T);
    lua_setmetatable(L, -2);

    switch (piece) {
        case PAWN:
            if (colour == NOCOLOUR)
                return luaL_argerror(L, 3, "invalid colour");
            *ret = PAWN_ATTACKS[colour - 1][square];
            break;
        case KNIGHT:
            *ret = KNIGHT_ATTACKS[square];
            break;
        case KING:
            *ret = KING_ATTACKS[square];
            break;
        case BISHOP: case ROOK: case QUEEN:
            if (occupancy == NULL)
                return luaL_argerror(L, 4, "invalid occupancy");
            switch (piece) {
                case BISHOP:
                    *ret = Bmagic(square, *occupancy);
                    break;
                case ROOK:
                    *ret = Rmagic(square, *occupancy);
                    break;
                case QUEEN:
                    *ret = Qmagic(square, *occupancy);
                    break;
            }
            break;
    }
    return 1;
}
bool White_Is_Legal(Position* position, Move move)
{
	position->Make_Move(move);
    int h = lsb(position->White_King);
    Bitboard BAttacks = Bmagic(h, (position->White_Pieces | position->Black_Pieces));
    Bitboard RAttacks = Rmagic(h, (position->White_Pieces | position->Black_Pieces));
    Bitboard QAttacks = BAttacks | RAttacks;
    if(QAttacks & (position->Black_Queens))
        {
    	position->Undo_Move(move);
    	return false;
    	}
    if(BAttacks & (position->Black_Bishops))
    {
    	position->Undo_Move(move);
    	return false;
    }
    if(Knight_Lookup_Table[h] & position->Black_Knights)
        {
    	position->Undo_Move(move);
    	return false;
    	}
    Bitboard Spare = position->Black_Pawns;
    Spare |= H_Pawn_Mask;
    Spare ^= H_Pawn_Mask;
    if((Spare >> 7) & position->White_King)
    	{
    	position->Undo_Move(move);
    	return false;
    	}
    Spare = position->Black_Pawns;
    Spare |= A_Pawn_Mask;
    Spare ^= A_Pawn_Mask;
    if((Spare >> 9) & position->White_King)
        {
    	position->Undo_Move(move);
        return false;
    	}
    if(RAttacks & (position->Black_Rooks))
    	{
    	position->Undo_Move(move);
    	return false;
    	}
    if(King_Lookup_Table[h] & position->Black_King)
        {
    	position->Undo_Move(move);
    	return false;
    	}
    position->Undo_Move(move);
    return true;
}