2012/08/05
■ 交換値計算
ある位置に来ることが可能な駒のビットボードを求める(AttackPieces関数)
// 隣接の利き(先手) and128(attack,p->bitboard[BLACK][P_FU],pos2bb[pos+9]); // 歩 andor128(attack,p->bitboard[BLACK][P_KEI],attack_kei_w[pos]); // 桂 andor128(attack,p->bitboard[BLACK][P_GIN],attack_gin_w[pos]); // 銀 andor128(attack,p->bitboard[BLACK][P_N_FU],attack_kin_w[pos]); // と andor128(attack,p->bitboard[BLACK][P_N_KYO],attack_kin_w[pos]); // 杏 andor128(attack,p->bitboard[BLACK][P_N_KEI],attack_kin_w[pos]); // 圭 andor128(attack,p->bitboard[BLACK][P_N_GIN],attack_kin_w[pos]); // 全 andor128(attack,p->bitboard[BLACK][P_KIN],attack_kin_w[pos]); // 金 andor128(attack,p->bitboard[BLACK][P_OU],attack_ou[pos]); // 王 andor128(attack,p->bitboard[BLACK][P_N_KAKU],attack_uma[pos]); // 馬 andor128(attack,p->bitboard[BLACK][P_N_HISH],attack_ryu[pos]); // 竜 // 隣接の利き(後手) andor128(attack,p->bitboard[WHITE][P_FU],pos2bb[pos-9]); // 歩 andor128(attack,p->bitboard[WHITE][P_KEI],attack_kei_b[pos]); // 桂 andor128(attack,p->bitboard[WHITE][P_GIN],attack_gin_b[pos]); // 銀 andor128(attack,p->bitboard[WHITE][P_N_FU],attack_kin_b[pos]); // と andor128(attack,p->bitboard[WHITE][P_N_KYO],attack_kin_b[pos]); // 杏 andor128(attack,p->bitboard[WHITE][P_N_KEI],attack_kin_b[pos]); // 圭 andor128(attack,p->bitboard[WHITE][P_N_GIN],attack_kin_b[pos]); // 全 andor128(attack,p->bitboard[WHITE][P_KIN],attack_kin_b[pos]); // 金 andor128(attack,p->bitboard[WHITE][P_OU],attack_ou[pos]); // 王 andor128(attack,p->bitboard[WHITE][P_N_KAKU],attack_uma[pos]); // 馬 andor128(attack,p->bitboard[WHITE][P_N_HISH],attack_ryu[pos]); // 竜 // 飛び利きについて調べる(先手) or128(hish,p->bitboard[BLACK][P_HISH],p->bitboard[BLACK][P_N_HISH]); // 飛&竜 or128(hish_kyo,hish,p->bitboard[BLACK][P_KYO]); // 飛&竜&香 or128(kaku,p->bitboard[BLACK][P_KAKU],p->bitboard[BLACK][P_N_KAKU]); // 角&馬 slider_r(slider_n,slider_s,hish) // 飛び利き(N) slider_f(slider_s,slider_n,hish_kyo) // 飛び利き(S) slider_r(slider_e,slider_w,hish) // 飛び利き(E) slider_f(slider_w,slider_e,hish) // 飛び利き(W) slider_r(slider_ne,slider_sw,kaku) // 飛び利き(NE) slider_r(slider_nw,slider_se,kaku) // 飛び利き(NW) slider_f(slider_se,slider_nw,kaku) // 飛び利き(SE) slider_f(slider_sw,slider_ne,kaku) // 飛び利き(SW) // 飛び利きについて調べる(後手) or128(hish,p->bitboard[WHITE][P_HISH],p->bitboard[WHITE][P_N_HISH]); // 飛&竜 or128(hish_kyo,hish,p->bitboard[WHITE][P_KYO]); // 飛&竜&香 or128(kaku,p->bitboard[WHITE][P_KAKU],p->bitboard[WHITE][P_N_KAKU]); // 角&馬 slider_r(slider_n,slider_s,hish_kyo) // 飛び利き(N) slider_f(slider_s,slider_n,hish) // 飛び利き(S) slider_r(slider_e,slider_w,hish) // 飛び利き(E) slider_f(slider_w,slider_e,hish) // 飛び利き(W) slider_r(slider_ne,slider_sw,kaku) // 飛び利き(NE) slider_r(slider_nw,slider_se,kaku) // 飛び利き(NW) slider_f(slider_se,slider_nw,kaku) // 飛び利き(SE) slider_f(slider_sw,slider_ne,kaku) // 飛び利き(SW) return attack;
交換値を求める
attacker=AttackPieces(to); // toに来る駒のリスト if ( !test128(attacker) ) return 0; // 来る駒がないなら終了 turn=( piece & B_BIT ) ? WHITE : BLACK; // toにいる駒の反対の手番 piece=PIECE_TYPE(piece); v=piece_value[piece]; list[0]=0; from=to; for ( depth=0; depth < 18; ) { // 八方+角2枚+飛2枚+香4枚+桂2枚+=18 from=SQUARES; toに来れるもっとも価値の低い駒(from)を探す 駒がなくなったら打ち切り 王を取られる手なら打ち切り list[depth+1]=-list[depth]+v; // 交換値のリスト v=toにいる駒の価値 depth++; 成れる駒は成っておく 動いた駒があるときはその方向に飛び利きを伸ばしtoに来る駒のリストに追加 turn^=1; // 手番変更 } listから最大の値を返す