Example #1
0
void predictor_values (
    Word32 L_av1[],
    Word16 rav1[],
    Word16 *scal_rav1
)
{
    Word16 vpar[8], aav1[9];

    schur_recursion (L_av1, vpar);
    step_up (8, vpar, aav1);
    compute_rav1 (aav1, rav1, scal_rav1);

    return;
}
Example #2
0
int
movegen(struct Game* game, int move_count)
{
    U64 temp_move, temp_move2, temp_piece;
    U32 from, to, move;

    U64 free_squares = game->board[OCCUPIED][0];

    if (game->to_move == WHITE)
    {
        /***************/
        /* WHITE PAWNS */
        /***************/
        temp_move = step_up(game->board[PAWNS][WHITE]) & free_squares;
        temp_move2 = temp_move;

        /* single pushes */
        while (temp_move)
        {
            to = bit_scan_forward(temp_move);
            if (to/8 == 7)
            { /* time for a promotion */
                game->move_buffer[move_count++] = create_move(to-8,to,BISHOP_PROMO_FLAG);
                game->move_buffer[move_count++] = create_move(to-8,to,KNIGHT_PROMO_FLAG);
                game->move_buffer[move_count++] = create_move(to-8,to,ROOK_PROMO_FLAG);
                game->move_buffer[move_count++] = create_move(to-8,to,QUEEN_PROMO_FLAG);
            } else game->move_buffer[move_count++] = create_move(to-8,to,QUIET_FLAG);
            temp_move &= temp_move - 1;
        }

        /* double pushes */
        temp_move2 = step_up(temp_move2) & free_squares & rank4;
        while (temp_move2)
        {
            to = bit_scan_forward(temp_move2);
            game->move_buffer[move_count++] = create_move(to-16,to,DOUBLE_PAWN_PUSH_FLAG);
            temp_move2 &= temp_move2 - 1;
        }

        /* captures */
        /* TODO: add en passante capture */
        temp_piece = game->board[PAWNS][WHITE];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);
            temp_move = pawn_attacks[WHITE][from] & game->board[PIECES][BLACK];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                if (to/8 == 7)
                { /* time for a promotion */
                    game->move_buffer[move_count++] = create_move(from,to,BISHOP_PROMO_CAPTURE_FLAG);
                    game->move_buffer[move_count++] = create_move(from,to,KNIGHT_PROMO_CAPTURE_FLAG);
                    game->move_buffer[move_count++] = create_move(from,to,ROOK_PROMO_CAPTURE_FLAG);
                    game->move_buffer[move_count++] = create_move(from,to,QUEEN_PROMO_CAPTURE_FLAG);
                } else game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }
            temp_piece &= temp_piece - 1;
        }

        /*****************/
        /* WHITE KNIGHTS */
        /*****************/
        temp_piece = game->board[KNIGHTS][WHITE];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);

            /* quiets */
            temp_move = knight_table[from] & free_squares;
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
                temp_move &= temp_move - 1;
            }

            /* captures */
            temp_move = knight_table[from] & game->board[PIECES][BLACK];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }

            temp_piece &= temp_piece - 1;
        }

        /*****************/
        /* WHITE BISHOPS */
        /*****************/
        temp_piece = game->board[BISHOPS][WHITE];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);
            temp_move2 = get_bishop_attacks(game->board[OCCUPIED][1], from);

            /* quiets */
            temp_move = temp_move2 & free_squares;
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
                temp_move &= temp_move - 1;
            }

            /* captures */
            temp_move = temp_move2 & game->board[PIECES][BLACK];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }

            temp_piece &= temp_piece - 1;
        }

        /***************/
        /* WHITE ROOKS */
        /***************/
        temp_piece = game->board[ROOKS][WHITE];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);
            temp_move2 = get_rook_attacks(game->board[OCCUPIED][1], from);

            /* quiets */
            temp_move = temp_move2 & free_squares;
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
                temp_move &= temp_move - 1;
            }

            /* captures */
            temp_move = temp_move2 & game->board[PIECES][BLACK];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }

            temp_piece &= temp_piece - 1;
        }

        /****************/
        /* WHITE QUEENS */
        /****************/
        temp_piece = game->board[QUEENS][WHITE];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);
            temp_move2 = get_queen_attacks(game->board[OCCUPIED][1], from);

            /* quiets */
            temp_move = temp_move2 & free_squares;
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
                temp_move &= temp_move - 1;
            }

            /* captures */
            temp_move = temp_move2 & game->board[PIECES][BLACK];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }

            temp_piece &= temp_piece - 1;
        }

        /**************/
        /* WHITE KINGS */
        /**************/
        temp_piece = game->board[KINGS][WHITE];
        from = bit_scan_forward(temp_piece);

        /* quiets */
        temp_move = king_table[from] & free_squares;
        while (temp_move)
        {
            to = bit_scan_forward(temp_move);
            game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
            temp_move &= temp_move - 1;
        }

        /* captures */
        temp_move = king_table[from] & game->board[PIECES][BLACK];
        while (temp_move)
        {
            to = bit_scan_forward(temp_move);
            game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
            temp_move &= temp_move - 1;
        }

        /* TODO: add castling moves here after writing is_attacked function */

    } else { /* to_move == BLACK */
        /***************/
        /* BLACK PAWNS */
        /***************/
        temp_move = step_down(game->board[PAWNS][BLACK]) & free_squares;
        temp_move2 = temp_move;

        /* single pushes */
        while (temp_move)
        {
            to = bit_scan_forward(temp_move);
            if (to/8 == 0)
            { /* time for a promotion */
                game->move_buffer[move_count++] = create_move(to+8,to,BISHOP_PROMO_FLAG);
                game->move_buffer[move_count++] = create_move(to+8,to,KNIGHT_PROMO_FLAG);
                game->move_buffer[move_count++] = create_move(to+8,to,ROOK_PROMO_FLAG);
                game->move_buffer[move_count++] = create_move(to+8,to,QUEEN_PROMO_FLAG);
            } else game->move_buffer[move_count++] = create_move(to+8,to,QUIET_FLAG);
            temp_move &= temp_move - 1;
        }

        /* double pushes */
        temp_move2 = step_down(temp_move2) & free_squares & rank5;
        while (temp_move2)
        {
            to = bit_scan_forward(temp_move2);
            game->move_buffer[move_count++] = create_move(to+16,to,DOUBLE_PAWN_PUSH_FLAG);
            temp_move2 &= temp_move2 - 1;
        }

        /* captures */
        /* TODO: add en passante capture */
        temp_piece = game->board[PAWNS][BLACK];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);
            temp_move = pawn_attacks[BLACK][from] & game->board[PIECES][WHITE];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                if (to/8 == 7)
                { /* time for a promotion */
                    game->move_buffer[move_count++] = create_move(from,to,BISHOP_PROMO_CAPTURE_FLAG);
                    game->move_buffer[move_count++] = create_move(from,to,KNIGHT_PROMO_CAPTURE_FLAG);
                    game->move_buffer[move_count++] = create_move(from,to,ROOK_PROMO_CAPTURE_FLAG);
                    game->move_buffer[move_count++] = create_move(from,to,QUEEN_PROMO_CAPTURE_FLAG);
                } else game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }
            temp_piece &= temp_piece - 1;
        }

        /*****************/
        /* BLACK KNIGHTS */
        /*****************/
        temp_piece = game->board[KNIGHTS][BLACK];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);

            /* quiets */
            temp_move = knight_table[from] & free_squares;
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
                temp_move &= temp_move - 1;
            }

            /* captures */
            temp_move = knight_table[from] & game->board[PIECES][WHITE];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }

            temp_piece &= temp_piece - 1;
        }

        /*****************/
        /* BLACK BISHOPS */
        /*****************/
        temp_piece = game->board[BISHOPS][BLACK];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);
            temp_move2 = get_bishop_attacks(game->board[OCCUPIED][1], from);

            /* quiets */
            temp_move = temp_move2 & free_squares;
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
                temp_move &= temp_move - 1;
            }

            /* captures */
            temp_move = temp_move2 & game->board[PIECES][WHITE];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }

            temp_piece &= temp_piece - 1;
        }

        /***************/
        /* BLACK ROOKS */
        /***************/
        temp_piece = game->board[ROOKS][BLACK];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);
            temp_move2 = get_rook_attacks(game->board[OCCUPIED][1], from);

            /* quiets */
            temp_move = temp_move2 & free_squares;
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
                temp_move &= temp_move - 1;
            }

            /* captures */
            temp_move = temp_move2 & game->board[PIECES][WHITE];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }

            temp_piece &= temp_piece - 1;
        }

        /****************/
        /* BLACK QUEENS */
        /****************/
        temp_piece = game->board[QUEENS][BLACK];
        while (temp_piece)
        {
            from = bit_scan_forward(temp_piece);
            temp_move2 = get_queen_attacks(game->board[OCCUPIED][1], from);

            /* quiets */
            temp_move = temp_move2 & free_squares;
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
                temp_move &= temp_move - 1;
            }

            /* captures */
            temp_move = temp_move2 & game->board[PIECES][WHITE];
            while (temp_move)
            {
                to = bit_scan_forward(temp_move);
                game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
                temp_move &= temp_move - 1;
            }

            temp_piece &= temp_piece - 1;
        }

        /**************/
        /* BLACK KINGS */
        /**************/
        temp_piece = game->board[KINGS][BLACK];
        from = bit_scan_forward(temp_piece);

        /* quiets */
        temp_move = king_table[from] & free_squares;
        while (temp_move)
        {
            to = bit_scan_forward(temp_move);
            game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG);
            temp_move &= temp_move - 1;
        }

        /* captures */
        temp_move = king_table[from] & game->board[PIECES][WHITE];
        while (temp_move)
        {
            to = bit_scan_forward(temp_move);
            game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG);
            temp_move &= temp_move - 1;
        }

    }

    return move_count;
}
void step_up()
{
  while (!step()) step_up();
}
Example #4
0
void step_up(void){
    while (!step()) {
        step_up();
    }
}
Example #5
0
void tone_detection (
    Word16 rc[],
    Word16 *tone
)
{
    Word32 L_num, L_den, L_temp;
    Word16 temp, prederr, a[3];
    Word16 i;

    *tone = 0;                   

    /*** Calculate filter coefficients ***/

    step_up (2, rc, a);

    /*** Calculate ( a[1] * a[1] ) ***/

    temp = shl (a[1], 3);
    L_den = L_mult (temp, temp);

    /*** Calculate ( 4*a[2] - a[1]*a[1] ) ***/

    L_temp = L_shl (L_deposit_h (a[2]), 3);
    L_num = L_sub (L_temp, L_den);

    /*** Check if pole frequency is less than 385 Hz ***/

     
    if (L_num <= 0)
    {
        return;
    }
      
    if (a[1] < 0)
    {
        temp = extract_h (L_den);
        L_den = L_mult (temp, FREQTH);

        L_temp = L_sub (L_num, L_den);

         
        if (L_temp < 0)
        {
            return;
        }
    }



    /*** Calculate normalised prediction error ***/

    prederr = 0x7fff;            

    for (i = 0; i < 4; i++)
    {
        temp = mult (rc[i], rc[i]);
        temp = sub (0x7fff, temp);
        prederr = mult (prederr, temp);
    }

    /*** Test if prediction error is smaller than threshold ***/

    temp = sub (prederr, PREDTH);

     
    if (temp < 0)
    {
        *tone = 1;               
    }
    return;
}