Ejemplo n.º 1
0
Archivo: mips.c Proyecto: mzd/cmmc
void mips_loop(ICNode *irnode) {
    ICNode *cur_node = NULL, *arg_node = NULL;
    MipsInsNodePtr cur_ins = NULL;
    assert(NULL != irnode);

    if (FALSE == mips_init_regs()) {
        PLN("[mips]Fail to initialize Registers");
        exit(-1);
    }
    
    output_read_write();

    cur_node = irnode;
    while (NULL != cur_node) {
        assert(NULL != cur_node->code);
        // if the ir_code is arg, get the sp
        // if the ir_code is function_def, get the next function_def
        arg_node = cur_node;
        while (0 == mips_args_total && IR_ARG == arg_node->code->kind) {
            mips_args_total ++;
            arg_node = arg_node->next;
        }

        cur_ins = generate_mips(cur_node->code);
        while (NULL != cur_ins) {
            assert(NULL != cur_ins->ins);
            output_mips_ins(cur_ins->ins);
            cur_ins = cur_ins->next;
        }
        cur_node = cur_node->next;
    }
}
Ejemplo n.º 2
0
static int evaluate_endgame()
{
  int sq;
  int score[2];
  sq_t king_square[2];
  state_t *state = &board->state;
  
  //clearing data:
  score[W] = 0; score[B] = 0;
  
  ///pawn evaluation:
  eval_pawn_struct_endgame(&score[0]);

  ///piece evaluation
  //kings
  king_square[W] = King_Square(W);
  king_square[B] = King_Square(B);
  score[W] += endgame_king_psq[W][king_square[W]];
  score[B] += endgame_king_psq[B][king_square[B]];
  
  if(state->material)
  {
    //queens:
    for(sq = PLS(WQ); sq <= H8; sq = PLN(sq))
    { score[W] += psq_table[WQ][sq];
      if(calc_rank(sq) == RANK_7
      && calc_rank(king_square[BLACK]) == RANK_8)
        score[W] += QUEEN_ON_7TH_REWARD;
    }
    for(sq = PLS(BQ); sq <= H8; sq = PLN(sq))
    { score[B] += psq_table[BQ][sq];
      if(calc_rank(sq) == RANK_2
      && calc_rank(king_square[WHITE]) == RANK_1)
        score[B] += QUEEN_ON_7TH_REWARD;
    }
    
    //rooks:
    for(sq = PLS(WR); sq <= H8; sq = PLN(sq))
    { score[W] += psq_table[WR][sq];
      score[W] += eval_white_rook(sq);
    }
    for(sq = PLS(BR); sq <= H8; sq = PLN(sq))
    { score[B] += psq_table[BR][sq];
      score[B] += eval_black_rook(sq);
    }
    
    //bishops:
    for(sq = PLS(WB); sq <= H8; sq = PLN(sq))
    { score[W] += psq_table[WB][sq];
      score[W] += eval_white_bishop(sq);
    
      //outposts
      if(!((1ULL << rsz[sq]) & pawn_attacks[B]))
      { if(psq_outposts[W][sq])
        { score[W] += (psq_outposts[W][sq]) / 2;
          if((1ULL << rsz[sq]) & pawn_attacks[W])
            score[W] += (psq_outposts[W][sq]) / 2;				
        }
      }
    }
    for(sq = PLS(BB); sq <= H8; sq = PLN(sq))
    { score[B] += psq_table[BB][sq];
      score[B] += eval_black_bishop(sq);
    
      //outposts:
      if(!((1ULL << rsz[sq]) & pawn_attacks[W]))
      { if(psq_outposts[B][sq])
        { score[B] += (psq_outposts[B][sq]) / 2;
          if((1ULL << rsz[sq]) & pawn_attacks[B])
            score[B] += (psq_outposts[B][sq]) / 2;
        }
      }
    }
    
    //knights:
    for(sq = PLS(WN); sq <= H8; sq = PLN(sq))
    { score[W] += psq_table[WN][sq];
    
      //outposts:
      if(!((1ULL << rsz[sq]) & pawn_attacks[B]))
      { if(psq_outposts[W][sq])
        { score[W] += psq_outposts[W][sq];
          if((1ULL << rsz[sq]) & pawn_attacks[W])
            score[W] += psq_outposts[W][sq];				
        }
      }
    }
    for(sq = PLS(BN); sq <= H8; sq = PLN(sq))
    { score[B] += psq_table[BN][sq];
    
      //outposts:
      if(!((1ULL << rsz[sq]) & pawn_attacks[W]))
      { if(psq_outposts[B][sq])
        { score[B] += psq_outposts[B][sq];
          if((1ULL << rsz[sq]) & pawn_attacks[B])
            score[B] += psq_outposts[B][sq];
        }
      }
    }
  
    //bishop pair bonus depending on pawns on board:
    if(Bishops(W) >= 2) score[W] += BISHOP_PAIR_REWARD - state->pawns;
    if(Bishops(B) >= 2) score[B] += BISHOP_PAIR_REWARD - state->pawns;
  
    //calculate basic knight and rook material imbalances:
    score[W] += Rooks(W)   * rook_imbalance[Pawns(W)];
    score[W] += Knights(W) * knight_imbalance[Pawns(W)];
    score[B] += Rooks(B)   * rook_imbalance[Pawns(B)];
    score[B] += Knights(B) * knight_imbalance[Pawns(B)];
    
    //a piece of code to encourage exchanges
    //in case of material advantage:
    if(state->material_value[W] > state->material_value[B]
    || state->pawn_value[W] > state->pawn_value[B])
      score[W] -= (state->piece_count[W] + state->piece_count[B]) * 2;
  
    if(state->material_value[B] > state->material_value[W]
    || state->pawn_value[B] > state->pawn_value[W])
      score[B] -= (state->piece_count[B] + state->piece_count[W]) * 2;
  }		
  return endeval(&score[0]);
}
Ejemplo n.º 3
0
int main()
{
    fs_hash_init(FS_HASH_UMAC);

    int passes = 0;
    int fails = 0;

#if 1
#define DUMP(t) printf("%lld %s\n", fs_c.xsd_##t, #t);
    DUMP(double);
    DUMP(float);
    DUMP(decimal);
    DUMP(integer);
    DUMP(boolean);
#endif

#define TEST1(f, a, x) printf("[%s] ", fs_value_equal(f(NULL, a), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(") = "); fs_value_print(f(NULL, a)); printf("\n"); if (!fs_value_equal(f(NULL, a), x)) { fails++; printf("       should have been "); fs_value_print(x); printf("\n"); } else { passes++; }
#define TEST2(f, a, b, x) printf("[%s] ", fs_value_equal(f(NULL, a, b), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(", "); fs_value_print(b); printf(") = "); fs_value_print(f(NULL, a, b)); printf("\n"); if (!fs_value_equal(f(NULL, a, b), x)) { fails++; printf("       should have been "); fs_value_print(x); printf("\n"); } else { passes++; }
#define TEST3(f, a, b, c, x) printf("[%s] ", fs_value_equal(f(NULL, a, b, c), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(", "); fs_value_print(b); printf(", "); fs_value_print(c); printf(") = "); fs_value_print(f(NULL, a, b, c)); printf("\n"); if (!fs_value_equal(f(NULL, a, b, c), x)) { fails++; printf("       should have been "); fs_value_print(x); printf("\n"); } else { passes++; }
#define URI(x) fs_value_uri(x)
#define RID(x) fs_value_rid(x)
#define BND(x) fs_value_rid(0x8000000000000000LL | x)
#define STR(x) fs_value_string(x)
#define PLN(x) fs_value_plain(x)
#define PLN_L(x, l) fs_value_plain_with_lang(x, l)
#define DBL(x) fs_value_double(x)
#define FLT(x) fs_value_float(x)
#define DEC(x) fs_value_decimal(x)
#define INT(x) fs_value_integer(x)
#define BLN(x) fs_value_boolean(x)
#define DAT(x) fs_value_datetime(x)
#define DAT_S(x) fs_value_datetime_from_string(x)
#define ERR() fs_value_error(FS_ERROR_INVALID_TYPE, NULL)
#define BLK() fs_value_blank()

    TEST2(fn_numeric_add, BLK(), BLK(), ERR());
    TEST2(fn_numeric_add, INT(1), URI("test:"), ERR());
    TEST2(fn_numeric_add, STR("2"), INT(3), ERR());
    TEST2(fn_numeric_add, INT(2), INT(3), INT(5));
    TEST2(fn_numeric_add, DEC(2.5), DEC(-1), DEC(1.5));
    TEST2(fn_numeric_add, DEC(-2.5), DEC(-1.5), DEC(-4));
    TEST2(fn_numeric_subtract, INT(2), INT(3), INT(-1));
    TEST2(fn_numeric_add, DBL(1), INT(2), DBL(3));
    TEST2(fn_numeric_add, FLT(17000), INT(2), FLT(17002));
    TEST2(fn_numeric_subtract, FLT(17000), INT(2), FLT(16998));
    TEST2(fn_numeric_subtract, DEC(17000.5), INT(2), DEC(16998.5));
    TEST2(fn_numeric_multiply, URI("http://example.com/"), INT(2), ERR());
    TEST2(fn_numeric_multiply, DEC(3.5), INT(2), DEC(7));
    TEST2(fn_numeric_multiply, DEC(35), DBL(-0.1), DBL(-3.5));
    TEST2(fn_numeric_multiply, INT(1), FLT(23), FLT(23));
    TEST2(fn_numeric_multiply, INT(10), INT(23), INT(230));
    TEST2(fn_numeric_divide, INT(9), URI("http://example.org/"), ERR());
    TEST2(fn_numeric_divide, INT(9), INT(2), DEC(4.5));
    TEST2(fn_numeric_divide, INT(-9), INT(2), DEC(-4.5));
    TEST2(fn_numeric_divide, INT(-9), INT(-2), DEC(4.5));
    TEST2(fn_numeric_divide, DBL(90), FLT(10), DBL(9));
    TEST2(fn_numeric_divide, FLT(99), FLT(-10), FLT(-9.9));
    TEST2(fn_equal, URI("http://example.com/"), DEC(23), BLN(0));
    TEST2(fn_equal, URI("http://example.com/"), URI("http://example.com/"), BLN(1));
    TEST2(fn_equal, INT(23), DEC(23), BLN(1));
    TEST2(fn_equal, fs_value_decimal_from_string("-23.0"), DEC(-23), BLN(1));
    TEST2(fn_equal, STR("foo"), PLN("foo"), BLN(0));
    TEST2(fn_equal, PLN("foo"), PLN("foo"), BLN(1));
    TEST2(fn_equal, BLN(0), BLN(0), BLN(1));
    TEST2(fn_greater_than, STR("BBB"), STR("AAA"), BLN(1));
    TEST2(fn_greater_than, PLN("BBB"), PLN("AAA"), BLN(1));
    TEST2(fn_greater_than, PLN("AAA"), PLN("BBB"), BLN(0));
    TEST2(fn_less_than, PLN("BBB"), PLN("AAA"), BLN(0));
    TEST2(fn_less_than, PLN("AAA"), PLN("BBB"), BLN(1));
    TEST2(fn_less_than, INT(20), INT(15), BLN(0));
    TEST2(fn_numeric_equal, INT(23), INT(23), BLN(1));
    TEST2(fn_numeric_equal, INT(23), DEC(23), BLN(1));
    TEST2(fn_numeric_equal, INT(23), FLT(23), BLN(1));
    TEST2(fn_numeric_equal, INT(23), DBL(23), BLN(1));
    TEST2(fn_numeric_equal, fn_minus(NULL, INT(23)), DBL(-23), BLN(1));
    TEST2(fn_datetime_equal, DAT(1000), DAT(1000), BLN(1));
    TEST2(fn_datetime_equal, DAT(time(NULL)), DAT(1000), BLN(0));
    TEST2(fn_numeric_less_than, INT(0), DBL(23), BLN(1));
    TEST2(fn_numeric_less_than, INT(23), DBL(23), BLN(0));
    TEST2(fn_numeric_less_than, DBL(22.99999), INT(23), BLN(1));
    TEST2(fn_numeric_less_than, DEC(-18.51), DEC(-18.5), BLN(1));
    TEST2(fn_numeric_less_than, DBL(-18.51), DBL(-18.5), BLN(1));
    TEST2(fn_numeric_less_than, DEC(-18.5), DEC(-18.51), BLN(0));
    TEST2(fn_numeric_less_than, DBL(-18.5), DBL(-18.51), BLN(0));
    TEST2(fn_numeric_greater_than, DEC(-121.98882), DEC(-121.739856), BLN(0));
    TEST2(fn_numeric_greater_than, DEC(37.67473), DEC(37.677954), BLN(0));
    TEST2(fn_numeric_greater_than, INT(0), DBL(23), BLN(0));
    TEST2(fn_numeric_greater_than, INT(23), DBL(23), BLN(0));
    TEST2(fn_numeric_greater_than, DBL(22.99999), INT(23), BLN(0));
    TEST2(fn_numeric_greater_than, DEC(-18.51), DEC(-18.5), BLN(0));
    TEST2(fn_numeric_greater_than, DBL(-18.51), DBL(-18.5), BLN(0));
    TEST2(fn_numeric_greater_than, DEC(-18.5), DEC(-18.51), BLN(1));
    TEST2(fn_numeric_greater_than, DBL(-18.5), DBL(-18.51), BLN(1));
    TEST2(fn_logical_and, BLN(1), BLN(0), BLN(0));
    TEST2(fn_logical_and, BLN(1), BLN(1), BLN(1));
    TEST2(fn_logical_and, INT(0), INT(1), BLN(0));
    TEST2(fn_logical_and, INT(1), INT(1), BLN(1));
    TEST2(fn_logical_and, STR("true"), INT(1), BLN(1));
    TEST2(fn_logical_and, STR("false"), INT(1), BLN(1));
    TEST2(fn_logical_and, INT(1), ERR(), ERR());
    TEST2(fn_logical_and, ERR(), INT(1), ERR());
    TEST2(fn_logical_and, INT(0), ERR(), BLN(0));
    TEST2(fn_logical_and, ERR(), INT(0), BLN(0));
    TEST2(fn_logical_and, ERR(), ERR(), ERR());
    TEST2(fn_logical_or, BLN(1), BLN(0), BLN(1));
    TEST2(fn_logical_or, BLN(1), BLN(1), BLN(1));
    TEST2(fn_logical_or, INT(0), INT(1), BLN(1));
    TEST2(fn_logical_or, INT(1), INT(1), BLN(1));
    TEST2(fn_logical_or, STR("true"), INT(32), BLN(1));
    TEST2(fn_logical_or, STR("false"), INT(1), BLN(1));
    TEST2(fn_logical_or, INT(1), ERR(), BLN(1));
    TEST2(fn_logical_or, ERR(), INT(1), BLN(1));
    TEST2(fn_logical_or, INT(0), ERR(), ERR());
    TEST2(fn_logical_or, ERR(), INT(0), ERR());
    TEST2(fn_logical_or, ERR(), ERR(), ERR());
    TEST2(fn_compare, STR("AAA"), STR("BBB"), INT(-1));
    TEST2(fn_compare, STR("BBB"), STR("BBB"), INT(0));
    TEST2(fn_compare, STR("BBB"), STR("AAA"), INT(1));
    TEST2(fn_compare, PLN("BBB"), PLN("AAA"), INT(1));
    TEST2(fn_compare, STR("BBB"), PLN("BBB"), ERR());
    TEST2(fn_compare, STR("http://example.com/"), URI("http://example.com/"), ERR());
    TEST2(fn_compare, URI("http://example.com/"), URI("http://example.com/"), ERR());
    TEST2(fn_compare, INT(1), PLN("BBB"), ERR());
    TEST3(fn_matches, PLN("foobar"), PLN("foo"), BLK(), BLN(1));
    TEST3(fn_matches, PLN("foobar"), PLN("^foo"), BLK(), BLN(1));
    TEST3(fn_matches, PLN("foobar"), PLN("bar$"), BLK(), BLN(1));
    TEST3(fn_matches, PLN("foobar"), PLN("BAR"), STR("i"), BLN(1));
    TEST3(fn_matches, PLN("foobar"), PLN("^FOOB[AO]R$"), STR("i"), BLN(1));
    TEST3(fn_matches, PLN("foobar"), PLN("^bar"), BLK(), BLN(0));
    TEST3(fn_matches, PLN("foobar"), PLN("^foo$"), BLK(), BLN(0));
    TEST3(fn_matches, PLN("foobar"), PLN("foo bar"), PLN("x"), BLN(1));
    TEST3(fn_matches, INT(23), PLN("foo bar"), PLN("x"), ERR());
    TEST3(fn_matches, PLN("foobar"), DAT(1000), PLN("x"), ERR());
    TEST1(fn_bound, URI("http://example.com/"), BLN(1));
    TEST1(fn_bound, STR("http"), BLN(1));
    TEST1(fn_bound, PLN(""), BLN(1));
    TEST1(fn_bound, BND(100), BLN(1));
    TEST1(fn_bound, RID(FS_RID_NULL), BLN(0));
    TEST1(fn_is_blank, URI("http://example.com/"), BLN(0));
    TEST1(fn_is_blank, STR("http"), BLN(0));
    TEST1(fn_is_blank, PLN(""), BLN(0));
    TEST1(fn_is_blank, BND(100), BLN(1));
    TEST1(fn_is_blank, RID(FS_RID_NULL), BLN(0));
    TEST1(fn_is_iri, URI("http://example.com/"), BLN(1));
    TEST1(fn_is_iri, STR("http"), BLN(0));
    TEST1(fn_is_iri, PLN(""), BLN(0));
    TEST1(fn_is_iri, BND(100), BLN(0));
    TEST1(fn_is_iri, RID(FS_RID_NULL), BLN(0));
    TEST1(fn_is_literal, URI("http://example.com/"), BLN(0));
    TEST1(fn_is_literal, STR("http"), BLN(1));
    TEST1(fn_is_literal, PLN(""), BLN(1));
    TEST1(fn_is_literal, BND(100), BLN(0));
    TEST1(fn_is_literal, RID(FS_RID_NULL), BLN(0));
    TEST1(fn_str, URI("http://example.com/"), PLN("http://example.com/"));
    TEST1(fn_str, STR("http"), PLN("http"));
    TEST1(fn_str, PLN(""), PLN(""));
    TEST1(fn_str, BLN(1), PLN("true"));
    TEST1(fn_str, INT(1), PLN("1"));
    TEST1(fn_str, FLT(11.1), PLN("11.100000"));
    TEST1(fn_str, DBL(11.1), PLN("11.100000"));
    TEST1(fn_str, DEC(23), PLN("23.000000"));
    TEST1(fn_str, DAT(1000), PLN("1970-01-01T00:16:40"));
    TEST1(fn_str, BND(100), ERR());
    TEST1(fn_str, RID(FS_RID_NULL), ERR());
    TEST1(fn_lang, PLN("foo"), PLN(""));
    TEST1(fn_lang, STR("foo"), PLN(""));
    TEST1(fn_lang, PLN_L("foo", "en"), PLN("en"));
    TEST1(fn_lang, PLN_L("foo", ""), PLN(""));
    TEST1(fn_lang, BLN(1), PLN(""));
    TEST1(fn_lang, INT(1), PLN(""));
    TEST1(fn_lang, DEC(1.1), PLN(""));
    TEST1(fn_lang, FLT(1.1), PLN(""));
    TEST1(fn_lang, DBL(1.1), PLN(""));
    TEST1(fn_lang, URI("http://example.org/"), ERR());
    TEST1(fn_datatype, PLN("foo"), ERR());
    TEST1(fn_datatype, STR("foo"), URI(XSD_STRING));
    TEST1(fn_datatype, PLN_L("foo", "en"), ERR());
    TEST1(fn_datatype, PLN_L("foo", ""), ERR());
    TEST1(fn_datatype, BLN(1), URI(XSD_BOOLEAN));
    TEST1(fn_datatype, INT(1), URI(XSD_INTEGER));
    TEST1(fn_datatype, DEC(1.1), URI(XSD_DECIMAL));
    TEST1(fn_datatype, FLT(1.1), URI(XSD_FLOAT));
    TEST1(fn_datatype, DBL(1.1), URI(XSD_DOUBLE));
    TEST1(fn_datatype, DAT(1000), URI(XSD_DATETIME));
    TEST1(fn_datatype, URI("http://example.org/"), ERR());
    TEST2(fn_equal, DAT_S("1975-01-07"), DAT(158284800), BLN(1));
    TEST2(fn_equal, DAT_S("1975-01-07T00:00:01"), DAT(158284801), BLN(1));
    TEST2(fn_equal, DAT_S("1975-01-07T01:00:01+0000"), DAT(158288401), BLN(1));
    TEST2(fn_equal, DAT_S("1975-01-07T01:00:01-0900"), DAT(158320801), BLN(1));
    TEST2(fn_cast, DBL(2.1), URI(XSD_INTEGER), INT(2));
    TEST2(fn_cast, PLN("2.23"), URI(XSD_DOUBLE), DBL(2.23));
    TEST2(fn_cast, PLN_L("2.23", "en"), URI(XSD_DOUBLE), DBL(2.23));
    TEST2(fn_cast, STR("2.23"), URI(XSD_DOUBLE), DBL(2.23));
    TEST2(fn_cast, URI("http://example.com/"), URI(XSD_STRING), ERR());
    TEST2(fn_cast, DAT(1000), URI(XSD_STRING), STR("1970-01-01T00:16:40"));
    TEST2(fn_cast, STR("1975-01-07T01:00:01-0900"), URI(XSD_DATETIME), DAT(158320801));

    printf("\n=== pass %d, fail %d\n", passes, fails);

    if (fails) {
	return 1;
    }

    return 0;
}
Ejemplo n.º 4
0
static int evaluate()
{
  int sq;
  int score[2];
  sq_t king_square[2];
  state_t *state = &board->state;
  
  //clearing data:
  score[W] = 0; score[B] = 0;

  ///pawn evaluation:
  eval_pawn_struct(&score[0]);
  
  ///piece evaluation
  //kings
  king_square[W] = King_Square(W);
  king_square[B] = King_Square(B);
  score[W] += psq_table[WK][king_square[W]];
  score[W] += eval_white_king(king_square[W]);
  score[B] += psq_table[BK][king_square[B]];
  score[B] += eval_black_king(king_square[B]);
  
  //queens:
  for(sq = PLS(WQ); sq <= H8; sq = PLN(sq))
  { score[W] += psq_table[WQ][sq];
    if(calc_rank(sq) == RANK_7
    && calc_rank(king_square[BLACK]) == RANK_8)
      score[W] += QUEEN_ON_7TH_REWARD;
    score[W] += eval_q_mobility(sq,W);
  }
  for(sq = PLS(BQ); sq <= H8; sq = PLN(sq))
  { score[B] += psq_table[BQ][sq];
    if(calc_rank(sq) == RANK_2
    && calc_rank(king_square[WHITE]) == RANK_1)
      score[B] += QUEEN_ON_7TH_REWARD;
    score[B] += eval_q_mobility(sq,B);
  }
  
  //rooks:
  for(sq = PLS(WR); sq <= H8; sq = PLN(sq))
  { score[W] += psq_table[WR][sq];
    score[W] += eval_white_rook(sq);
    score[W] += eval_r_mobility(sq,W);
  }
  for(sq = PLS(BR); sq <= H8; sq = PLN(sq))
  { score[B] += psq_table[BR][sq];
    score[B] += eval_black_rook(sq);
    score[B] += eval_r_mobility(sq,B);
  }
  
  //bishops:
  for(sq = PLS(WB); sq <= H8; sq = PLN(sq))
  { score[W] += psq_table[WB][sq];
    score[W] += eval_white_bishop(sq);
    score[W] += eval_b_mobility(sq,W);
    
    //outposts - twice as low than a knight outpost:
    if(!((1ULL << rsz[sq]) & pawn_attacks[B]))
    { if(psq_outposts[W][sq])
      { //if not attacked by an opponent's pawn,
        //this could be a weak square that matters,
        //in accordance with the outposts table:
        score[W] += (psq_outposts[W][sq]) / 2;
        
        //additional bonus if it's reinforced by own pawns:
        if((1ULL << rsz[sq]) & pawn_attacks[W])
          score[W] += (psq_outposts[W][sq]) / 2;				
      }
    }
  }
  for(sq = PLS(BB); sq <= H8; sq = PLN(sq))
  { score[B] += psq_table[BB][sq];
    score[B] += eval_black_bishop(sq);
    score[B] += eval_b_mobility(sq,B);
    
    //outposts:
    if(!((1ULL << rsz[sq]) & pawn_attacks[W]))
    { if(psq_outposts[B][sq])
      { score[B] += (psq_outposts[B][sq]) / 2;
        if((1ULL << rsz[sq]) & pawn_attacks[B])
          score[B] += (psq_outposts[B][sq]) / 2;
      }
    }
  }
  
  //knights:
  for(sq = PLS(WN); sq <= H8; sq = PLN(sq))
  { score[W] += psq_table[WN][sq];
    score[W] += eval_n_mobility(sq,W);
    
    //outposts:
    if(!((1ULL << rsz[sq]) & pawn_attacks[B]))
    { if(psq_outposts[W][sq])
      { score[W] += psq_outposts[W][sq];
        if((1ULL << rsz[sq]) & pawn_attacks[W])
          score[W] += psq_outposts[W][sq];				
      }
    }
  }
  for(sq = PLS(BN); sq <= H8; sq = PLN(sq))
  { score[B] += psq_table[BN][sq];
    score[B] += eval_n_mobility(sq,B);
    
    //outposts:
    if(!((1ULL << rsz[sq]) & pawn_attacks[W]))
    { if(psq_outposts[B][sq])
      { score[B] += psq_outposts[B][sq];
        if((1ULL << rsz[sq]) & pawn_attacks[B])
          score[B] += psq_outposts[B][sq];
      }
    }
  }
  
  //bishop pair bonus depending on pawns on board:
  if(Bishops(W) >= 2) score[W] += BISHOP_PAIR_REWARD - state->pawns;
  if(Bishops(B) >= 2) score[B] += BISHOP_PAIR_REWARD - state->pawns;
  
  //calculate basic knight and rook material imbalances:
  /**********************************************************
      quote from GM L.Kaufman:
   "A further refinement would be to raise the knight's value 
   by 1/16 and lower the rook's value by 1/8 for each pawn 
   above five of the side being valued, with the opposite 
   adjustment for each pawn short of five".
  ***********************************************************/	
  score[W] += Rooks(W)   * rook_imbalance[Pawns(W)];
  score[W] += Knights(W) * knight_imbalance[Pawns(W)];
  score[B] += Rooks(B)   * rook_imbalance[Pawns(B)];
  score[B] += Knights(B) * knight_imbalance[Pawns(B)];
    
  if(opening)
  { score[W] += eval_white_opening();
    score[B] += eval_black_opening();
  }

  ///final results:
  score[W] += state->material_value[WHITE] + \
    state->pawn_value[WHITE];
  score[B] += state->material_value[BLACK] + \
    state->pawn_value[BLACK];
  
  if(board->side == W) return (score[W]-score[B]);
  else return -(score[W]-score[B]);
}
Ejemplo n.º 5
0
uint64 perft(int depth)
{ 
  int i,move_count;
  move_t ms[MOVE_STACK];
  uint64 nodes;
  uint64 val;
  #ifdef EVASIONS
  char strbuff[256];
  move_t ms_test[MOVE_STACK];
  #endif
  #ifdef BITS
  bitboard_t bb;
  #endif
  
  if(depth == 0) return 1;
  if((val = probe_hash(depth)) != 0) 
    return val;

  nodes = 0;
  val = 0;
    
  #ifdef BITS
  bb = 0;
  for(i = PLS(WP); i <= H8; i = PLN(i))
    bitset(&bb, rsz[i]);
  if(bb != board->bb_pawns[W])
    printf("pawn_error\n");
  bb = 0;
  for(i = PLS(BP); i <= H8; i = PLN(i))
    bitset(&bb, rsz[i]);
  if(bb != board->bb_pawns[B])
    printf("pawn_error\n");
  #endif
  
  #ifdef EVASIONS
  if(is_in_check(board->side))
  { move_count = move_gen_evasions(&ms[0]);
    if(move_count != move_gen_legal(&ms_test[0]))
    { board_to_fen(&strbuff[0]);
      printf("error: \n %s \n",strbuff);
    }
  }
  else
  { move_count = move_gen(&ms[0]);
  }
  #else
  move_count = move_gen(&ms[0]);
  #endif
    
  for(i = 0; i < move_count; i++)
  { if(!move_make(ms[i])) continue;
    if(depth == 1)
      nodes++;
    else
      nodes += perft(depth - 1);

    move_undo();
  }
  record_hash(depth,nodes);
  return (nodes);
}