PieceNumber Position::make_list_drop(Piece piece, Square to) { // 持ち駒の中で一番駒番号の多い駒を打ちます。 const int count = handcount[piece]; const int handIndex0 = NanohaTbl::HandIndex0[piece] + count; const PieceNumber kn = listkn[handIndex0]; // maxの駒番号 assert(handIndex0 < fe_hand_end); // knをセーブ st->oldlist[0] = list0[kn]; st->oldlist[1] = list1[kn]; listkn[handIndex0] = PIECENUMBER_NONE; // 駒番号の一番大きい持ち駒を消去 handcount[piece]--; // 打つので1枚減らす // 打った駒の情報 const int sq = conv_z2sq(to); list0[kn] = NanohaTbl::KppIndex0[piece] + sq; list1[kn] = NanohaTbl::KppIndex1[piece] + Inv(sq); #if defined(EVAL_DIFF) st->newlist[0] = list0[kn]; st->newlist[1] = list1[kn]; #endif return kn; }
void Position::init_make_list() { memset(list0, 0, sizeof(list0)); memset(list1, 0, sizeof(list1)); memset(listkn, 0, sizeof(listkn)); memset(handcount, 0, sizeof(handcount)); for (PieceNumber kn = PIECENUMBER_MIN; kn <= PIECENUMBER_MAX; ++kn){ const int kpos = knpos[kn]; const Piece piece = Piece(knkind[kn]); int count, sq; switch (kpos) { case 0: break; case 1: // 先手持駒 case 2: // 後手持駒 count = ++handcount[piece]; list0[kn] = NanohaTbl::HandIndex0[piece] + count; list1[kn] = NanohaTbl::HandIndex1[piece] + count; listkn[list0[kn]] = kn; break; default: if ((SFU <= piece && piece <= SRY && piece != SOU) || (GFU <= piece && piece <= GRY && piece != GOU)) { sq = conv_z2sq(kpos); list0[kn] = NanohaTbl::KppIndex0[piece] + sq; list1[kn] = NanohaTbl::KppIndex1[piece] + Inv(sq); } break; } } }
//int Position::make_list_apery(int list0[NLIST], int list1[NLIST], int nlist) const int Position::make_list_apery(int list0[], int list1[], int nlist) const { static const struct { int f_pt, e_pt; } base_tbl[] = { {-1 , -1 }, // 0:--- {f_pawn , e_pawn }, // 1:SFU {f_lance , e_lance }, // 2:SKY {f_knight, e_knight}, // 3:SKE {f_silver, e_silver}, // 4:SGI {f_gold , e_gold }, // 5:SKI {f_bishop, e_bishop}, // 6:SKA {f_rook , e_rook }, // 7:SHI {-1 , -1 }, // 8:SOU {f_gold , e_gold }, // 9:STO {f_gold , e_gold }, // 10:SNY {f_gold , e_gold }, // 11:SNK {f_gold , e_gold }, // 12:SNG {-1 , -1 }, // 13:-- {f_horse , e_horse }, // 14:SUM {f_dragon, e_dragon}, // 15:SRY {-1 , -1 }, // 16:--- {e_pawn , f_pawn }, // 17:GFU {e_lance , f_lance }, // 18:GKY {e_knight, f_knight}, // 19:GKE {e_silver, f_silver}, // 20:GGI {e_gold , f_gold }, // 21:GKI {e_bishop, f_bishop}, // 22:GKA {e_rook , f_rook }, // 23:GHI {-1 , -1 }, // 24:GOU {e_gold , f_gold }, // 25:GTO {e_gold , f_gold }, // 26:GNY {e_gold , f_gold }, // 27:GNK {e_gold , f_gold }, // 28:GNG {-1 , -1 }, // 29:--- {e_horse , f_horse }, // 30:GUM {e_dragon, f_dragon} // 31:GRY }; int sq; // 駒番号:1〜2が玉、3〜40が玉以外 for (int kn = 3; kn <= 40; kn++) { const int z = knpos[kn]; if (z < 0x11) continue; // 持ち駒除く int piece = knkind[kn]; sq = conv_z2sq(z); assert(piece <= GRY && sq < nsquare); assert(base_tbl[piece].f_pt != -1); list0[nlist] = base_tbl[piece].f_pt + sq; list1[nlist] = base_tbl[piece].e_pt + Inv(sq); nlist++; } assert( nlist == NLIST ); return nlist; }
void Position::make_list_move(PieceNumber kn, Piece piece, Square to) { if (kn < PIECENUMBER_MIN) { #if defined(EVAL_DIFF) st->changeType = 0; #endif return; } st->oldlist[0] = list0[kn]; st->oldlist[1] = list1[kn]; const int sq = conv_z2sq(to); list0[kn] = NanohaTbl::KppIndex0[piece] + sq; list1[kn] = NanohaTbl::KppIndex1[piece] + Inv(sq); #if defined(EVAL_DIFF) st->newlist[0] = list0[kn]; st->newlist[1] = list1[kn]; #endif }