My Project
majorPiece.cc
Go to the documentation of this file.
3#include <algorithm>
4using osl::MultiInt;
5
6template <bool Opening, osl::Ptype MajorBasic>
9
10template <bool Opening, osl::Ptype MajorBasic>
13{
14 for (size_t i = 0; i < weights.dimension(); ++i)
15 {
16 table[i] = weights.value(i);
17 }
18}
19
20
21template <bool Opening>
23
24template <bool Opening>
27{
28 weight = weights.value(0);
29}
31template <bool Opening>
33{
34 int result = 0;
35 for (int i = PtypeTraits<ROOK>::indexMin;
36 i < PtypeTraits<ROOK>::indexLimit;
37 ++i)
38 {
39 const Piece piece = state.pieceOf(i);
40 if (piece.isOnBoard() && !piece.square().canPromote(piece.owner()) &&
41 !state.isPawnMaskSet(piece.owner(), piece.square().x()))
42 {
43 if (piece.owner() == BLACK)
44 result += weight;
45 else
46 result -= weight;
47 }
48 }
49 return result;
50}
51
52
58
60RookPawnYX::setUp(const Weights &weights)
61{
62 for (int i = 0; i < ONE_DIM; ++i)
63 {
64 for (int s=0; s<NStages; ++s)
65 {
66 RookPawnY::y_attack_table[i][s] = weights.value(i + ONE_DIM * 2 * s);
67 RookPawnY::y_defense_table[i][s] = weights.value(i + ONE_DIM * 2 * s + ONE_DIM);
68 }
69 }
71
72
74RookPawnY::setUp(const Weights &weights)
75{
76 for (int i = 0; i < ONE_DIM; ++i)
77 {
78 for (int s=0; s<NStages; ++s)
79 table[i][s] = weights.value(i + ONE_DIM*s);
80 }
81}
82
85 const CArray2d<int, 2, 9> &pawns)
86{
87 MultiInt result;
88 const CArray<Square,2> kings = {
89 state.kingSquare<BLACK>(),
90 state.kingSquare<WHITE>(),
91 };
92 for (int i = PtypeTraits<ROOK>::indexMin;
93 i < PtypeTraits<ROOK>::indexLimit;
94 ++i)
95 {
96 const Piece piece = state.pieceOf(i);
97 if (piece.isOnBoard())
98 {
99 if (piece.owner() == BLACK)
100 {
101 const int pawn_y =
102 pawns[BLACK][piece.square().x() - 1];
103 result +=
104 table[index(piece, pawn_y)] +
105 y_attack_table[indexY(kings[WHITE], piece, pawn_y)] +
106 y_defense_table[indexY(kings[BLACK], piece, pawn_y)];
107 }
108 else
109 {
110 int y = pawns[WHITE][piece.square().x() - 1];
111 if (y != 0)
112 y = 10 - y;
113 result -=
114 table[index(piece, y)] +
115 y_attack_table[indexY(kings[BLACK], piece, y)] +
116 y_defense_table[indexY(kings[WHITE], piece, y)];
117 }
118 }
119 }
120 return result;
121}
122
123
125
127AllMajor::setUp(const Weights &weights,int stage)
128{
129 weight[stage] = weights.value(0);
130}
131
132
133template <bool Opening>
135
136template <bool Opening>
140 for (size_t i = 0; i < weights.dimension(); ++i)
142 table[i] = weights.value(i);
144}
145
146template <bool Opening>
149 const NumEffectState &state, Piece piece)
150{
151 return piece.ptype() + (state.turn() == piece.owner() ? 0 : PTYPE_SIZE);
152}
153
154template <bool Opening>
155template <osl::Ptype PTYPE>
158{
159 int result = 0;
160 for (int i = PtypeTraits<PTYPE>::indexMin;
161 i < PtypeTraits<PTYPE>::indexLimit;
162 ++i)
163 {
164 const Piece piece = state.pieceOf(i);
165 if (piece.isOnBoard() &&
166 state.hasEffectAt(alt(piece.owner()), piece.square()))
167 {
168 const int weight = table[index(state, piece)];
169 if (piece.owner() == BLACK)
170 result += weight;
171 else
172 result -= weight;
173 }
174 }
175 return result;
176}
177
178template <bool Opening>
181{
182 int result = 0;
183 result += evalOne<ROOK>(state);
184 result += evalOne<BISHOP>(state);
185 result += evalOne<GOLD>(state);
186 result += evalOne<SILVER>(state);
187
188 return result;
189}
190
194
205
206
207template<osl::Player P>
208inline
210 const NumEffectState& state,
211 Square rook,
212 Square myKing,
213 Square opKing,
214 Square up,
215 Square dp,
216 Square rp,
217 Square lp,
218 bool isP)
219{
220 MultiInt result;
221 PtypeO uPtypeO=state.pieceAt(up).ptypeO();
222 PtypeO dPtypeO=state.pieceAt(dp).ptypeO();
223 PtypeO rPtypeO=state.pieceAt(rp).ptypeO();
224 PtypeO lPtypeO=state.pieceAt(lp).ptypeO();
225 if(P==WHITE){
226 uPtypeO=(PtypeO)(static_cast<int>(uPtypeO)^(~15));
227 dPtypeO=(PtypeO)(static_cast<int>(dPtypeO)^(~15));
228 rPtypeO=(PtypeO)(static_cast<int>(rPtypeO)^(~15));
229 lPtypeO=(PtypeO)(static_cast<int>(lPtypeO)^(~15));
230 up=up.rotate180EdgeOK();
231 dp=dp.rotate180EdgeOK();
232 rp=rp.rotate180EdgeOK();
233 lp=lp.rotate180EdgeOK();
234 rook=rook.rotate180();
235 myKing=myKing.rotate180();
236 opKing=opKing.rotate180();
237 }
238 assert((myKing.y()-dp.y())<(myKing.y()-up.y()));
239 assert((myKing.x()-lp.x())<(myKing.x()-rp.x()));
240 result+=attack_u[index1(opKing,up,uPtypeO,isP)]+
241 attack_d[index1(opKing,dp,dPtypeO,isP)]+
242 attack_l[index1(opKing,lp,lPtypeO,isP)]+
243 attack_r[index1(opKing,rp,rPtypeO,isP)]+
244 defense_u[index1(myKing,up,uPtypeO,isP)]+
245 defense_d[index1(myKing,dp,dPtypeO,isP)]+
246 defense_l[index1(myKing,lp,lPtypeO,isP)]+
247 defense_r[index1(myKing,rp,rPtypeO,isP)]+
248 attack_nospace[index2(opKing,rook,isP)]+
249 defense_nospace[index2(myKing,rook,isP)];
250 return result;
251}
252
255{
256 const CArray<Square,2> kings = {
257 state.kingSquare(BLACK),
258 state.kingSquare(WHITE),
259 };
260 MultiInt result;
261 for (int i = PtypeTraits<ROOK>::indexMin; i < PtypeTraits<ROOK>::indexLimit;
262 ++i)
263 {
264 const Piece p = state.pieceOf(i);
265 if (! p.isOnBoard()) continue;
266 const Square pos=p.square();
267 Square up=state.mobilityOf(U,i);
268 Square dp=state.mobilityOf(D,i);
269 Square lp=state.mobilityOf(L,i);
270 Square rp=state.mobilityOf(R,i);
271 const bool isP=p.isPromoted();
272 if(p.owner()==BLACK)
273 result+=evalOne<BLACK>(state,pos,kings[0],kings[1],up,dp,rp,lp,isP);
274 else
275 result-=evalOne<WHITE>(state,pos,kings[1],kings[0],dp,up,lp,rp,isP);
276 }
277 return result;
278}
279
280void osl::eval::ml::RookEffect::setUp(const Weights &weights,int stage)
281{
282 for (size_t i = 0; i < ONE_DIM; ++i)
283 {
284 attack_table[i][stage] = weights.value(i);
285 defense_table[i][stage] = weights.value(i + ONE_DIM);
286 }
287}
288
290{
291 for (size_t i = 0; i < 32; ++i)
292 {
293 for (int s=0; s<NStages; ++s)
294 RookEffectBase::piece_table[i][s] = weights.value(i + 32*s);
295 }
296}
297
300{
301 CArray<MultiInt, 19584> piece_attack_table;
302 CArray<MultiInt, 19584> piece_defense_table;
303 for (size_t i = 0; i < ONE_DIM; ++i)
304 {
305 for (int s=0; s<NStages; ++s)
306 {
307 piece_attack_table[i][s] = weights.value(i + ONE_DIM*2*s);
308 piece_defense_table[i][s] = weights.value(i + ONE_DIM*2*s + ONE_DIM);
309 }
310 }
311 for(int isP=0;isP<2;isP++)
312 for(int y_diff=-9;y_diff<=9;y_diff++)
313 for(int x_diff= -9;x_diff<=9;x_diff++){
314 int i2=index2(x_diff,y_diff,isP);
315 if(abs(x_diff)<9 && abs(y_diff)<9){
316 attack_nospace[i2]=
317 -(attack_table[index(abs(x_diff),y_diff,true,isP)]+
318 attack_table[index(abs(x_diff),y_diff,false,isP)]);
319 defense_nospace[i2]=
320 -(defense_table[index(abs(x_diff),y_diff,true,isP)]+
321 defense_table[index(abs(x_diff),y_diff,false,isP)]);
322 }
323 for(int ptypeo= PTYPEO_MIN;ptypeo<=PTYPEO_MAX;ptypeo++){
324 if(getPtype((PtypeO)ptypeo)==(int)PTYPE_EMPTY) continue;
325 int i1=index1(x_diff,y_diff,(PtypeO)ptypeo,isP);
326 int indexPieceH,indexPieceV;
327 int table_ptypeo=ptypeo;
328 if(getPtype((PtypeO)ptypeo)==PTYPE_EDGE) table_ptypeo=PTYPEO_EDGE;
329 if(getPtype((PtypeO)ptypeo)==PTYPE_EDGE || abs(x_diff)==9 || abs(y_diff)==9){
330 indexPieceH= 0+0+(PTYPEO_EDGE-PTYPEO_MIN)*17*9+4896+isP*9792;
331 indexPieceV= 0+0+(PTYPEO_EDGE-PTYPEO_MIN)*17*9+ isP*9792;
332 }
333 else{
334 indexPieceH= index0(abs(x_diff),-y_diff,(PtypeO)ptypeo,true,isP);
335 indexPieceV= index0(abs(x_diff),-y_diff,(PtypeO)ptypeo,false,isP);
336 }
337 attack_u[i1]=piece_attack_table[indexPieceV]+piece_table[table_ptypeo-PTYPEO_MIN];
338 defense_u[i1]=piece_defense_table[indexPieceV];
339 attack_d[i1]=piece_attack_table[indexPieceV]+piece_table[table_ptypeo-PTYPEO_MIN];
340 defense_d[i1]=piece_defense_table[indexPieceV];
341 if(abs(x_diff)<=8){
342 for(int y_diff_1=y_diff+1;y_diff_1<=8;y_diff_1++){
343 int i=index(abs(x_diff),y_diff_1,false,isP);
344 attack_u[i1]+=attack_table[i];
345 defense_u[i1]+=defense_table[i];
346 }
347 for(int y_diff_1=std::max(-8,y_diff);y_diff_1<=8;y_diff_1++){
348 int i=index(abs(x_diff),y_diff_1,false,isP);
349 attack_d[i1]-=attack_table[i];
350 defense_d[i1]-=defense_table[i];
351 }
352 }
353 attack_l[i1]=piece_attack_table[indexPieceH]+piece_table[table_ptypeo-PTYPEO_MIN];
354 defense_l[i1]=piece_defense_table[indexPieceH];
355 attack_r[i1]=piece_attack_table[indexPieceH]+piece_table[table_ptypeo-PTYPEO_MIN];
356 defense_r[i1]=piece_defense_table[indexPieceH];
357 if(abs(y_diff)<=8){
358 for(int x_diff_1=x_diff+1;x_diff_1<=8;x_diff_1++){
359 int i=index(abs(x_diff_1),y_diff,true,isP);
360 attack_r[i1]+=attack_table[i];
361 defense_r[i1]+=defense_table[i];
362 }
363 for(int x_diff_1=std::max(-8,x_diff);x_diff_1<=8;x_diff_1++){
364 int i=index(abs(x_diff_1),y_diff,true,isP);
365 attack_l[i1]-=attack_table[i];
366 defense_l[i1]-=defense_table[i];
367 }
368 }
369 }
370 }
371}
372
373
374
377
379{
380 for (size_t i = 0; i < ONE_DIM; ++i)
381 {
382 for (int s=0; s<NStages; ++s)
383 promote_defense_table[i][s] = weights.value(i + ONE_DIM*s);
384 }
385}
386
388{
389 for (size_t i = 0; i < ONE_DIM; ++i)
390 {
391 for (int s=0; s<NStages; ++s)
393 weights.value(i + ONE_DIM*s);
394 }
395}
396
399{
400 MultiInt result;
401 for (int i = PtypeTraits<ROOK>::indexMin;
402 i < PtypeTraits<ROOK>::indexLimit;
403 ++i){
404 const Piece rook = state.pieceOf(i);
405 if(rook.isOnBoardNotPromoted()){
406 if(rook.owner()==BLACK){
407 Square rookPos=rook.square();
408 if(rookPos.y()>=4){
409 Square pos=state.mobilityOf(U,i);
410 const Piece attacked = state.pieceAt(pos);
411 if (attacked.canMoveOn<BLACK>()){
412 const NumBitmapEffect effect = state.effectSetAt(pos);
413 if (effect.countEffect(WHITE) == 1){
414 PieceMask mask = effect & state.piecesOnBoard(WHITE);
415 const Piece effect_piece = state.pieceOf(mask.takeOneBit());
416 const int index = attacked.ptype() * 16 + effect_piece.ptype();
417 result += promote_defense_table[index];
418 if (effect_piece.ptype() == ROOK &&
419 effect_piece.square().x() != rookPos.x())
420 {
421 result +=
422 promote_defense_rook_table[
423 attacked.ptype() * 9 +
424 mobility::RookMobility::countHorizontalAll<BLACK>(state,
425 rook)];
426 }
427 }
428 }
429 }
430 }
431 else{
432 Square rookPos=rook.square();
433 if(rookPos.y()<=6){
434 Square pos=state.mobilityOf(D,i);
435 const Piece attacked = state.pieceAt(pos);
436 if (attacked.canMoveOn<WHITE>()){
437 const NumBitmapEffect effect = state.effectSetAt(pos);
438 if (effect.countEffect(BLACK) == 1){
439 PieceMask mask = effect & state.piecesOnBoard(BLACK);
440 const Piece effect_piece = state.pieceOf(mask.takeOneBit());
441 const int index = attacked.ptype() * 16 + effect_piece.ptype();
442 result -= promote_defense_table[index];
443 if (effect_piece.ptype() == ROOK &&
444 effect_piece.square().x() != rookPos.x())
445 {
446 result -=
447 promote_defense_rook_table[
448 attacked.ptype() * 9 +
449 mobility::RookMobility::countHorizontalAll<WHITE>(state,
450 rook)];
451 }
452 }
453 }
454 }
455 }
456 }
457 }
458 return result;
459}
460
461
462
476
477
478template<osl::Player P>
479inline
481 const NumEffectState& state,
482 Square bishop,
483 Square myKing,
484 Square opKing,
485 Square ulp,
486 Square urp,
487 Square dlp,
488 Square drp,
489 bool isP)
490{
491 MultiInt result;
492 PtypeO ulPtypeO=state.pieceAt(ulp).ptypeO();
493 PtypeO urPtypeO=state.pieceAt(urp).ptypeO();
494 PtypeO dlPtypeO=state.pieceAt(dlp).ptypeO();
495 PtypeO drPtypeO=state.pieceAt(drp).ptypeO();
496 if(P==WHITE){
497 ulPtypeO=(PtypeO)(static_cast<int>(ulPtypeO)^(~15));
498 urPtypeO=(PtypeO)(static_cast<int>(urPtypeO)^(~15));
499 dlPtypeO=(PtypeO)(static_cast<int>(dlPtypeO)^(~15));
500 drPtypeO=(PtypeO)(static_cast<int>(drPtypeO)^(~15));
501 ulp=ulp.rotate180EdgeOK();
502 urp=urp.rotate180EdgeOK();
503 dlp=dlp.rotate180EdgeOK();
504 drp=drp.rotate180EdgeOK();
505 bishop=bishop.rotate180();
506 myKing=myKing.rotate180();
507 opKing=opKing.rotate180();
508 }
509 result+=attack_ul[index1(opKing,ulp,ulPtypeO,isP)]+
510 attack_ur[index1(opKing,urp,urPtypeO,isP)]+
511 attack_dl[index1(opKing,dlp,dlPtypeO,isP)]+
512 attack_dr[index1(opKing,drp,drPtypeO,isP)]+
513 defense_ul[index1(myKing,ulp,ulPtypeO,isP)]+
514 defense_ur[index1(myKing,urp,urPtypeO,isP)]+
515 defense_dl[index1(myKing,dlp,dlPtypeO,isP)]+
516 defense_dr[index1(myKing,drp,drPtypeO,isP)]+
517 attack_nospace[index2(opKing,bishop,isP)]+
518 defense_nospace[index2(myKing,bishop,isP)];
519 return result;
520}
521
524{
525 const CArray<Square,2> kings = {{
526 state.kingSquare(BLACK),
527 state.kingSquare(WHITE),
528 }};
529
530 MultiInt result;
531 for (int i = PtypeTraits<BISHOP>::indexMin; i < PtypeTraits<BISHOP>::indexLimit;
532 ++i)
533 {
534 const Piece p = state.pieceOf(i);
535 if (! p.isOnBoard()) continue;
536 const Square pos=p.square();
537 Square ulp=state.mobilityOf(UL,i);
538 Square urp=state.mobilityOf(UR,i);
539 Square dlp=state.mobilityOf(DL,i);
540 Square drp=state.mobilityOf(DR,i);
541 const bool isP=p.isPromoted();
542 if(p.owner()==BLACK)
543 result+=evalOne<BLACK>(state,pos,kings[0],kings[1],ulp,urp,dlp,drp,isP);
544 else
545 result-=evalOne<WHITE>(state,pos,kings[1],kings[0],drp,dlp,urp,ulp,isP);
546 }
547 return result;
548}
549
550void osl::eval::ml::BishopEffect::setUp(const Weights &weights,int stage)
551{
552 for (size_t i = 0; i < ONE_DIM; ++i)
553 {
554 attack_table[i][stage] = weights.value(i);
555 defense_table[i][stage] = weights.value(i + ONE_DIM);
556 }
557}
558
560{
561 for (size_t i = 0; i < 32; ++i)
562 {
563 for (int s=0; s<NStages; ++s)
564 BishopEffectBase::piece_table[i][s] = weights.value(i + 32*s);
565 }
566}
567
568
571{
572 CArray<MultiInt, 19584> piece_attack_table;
573 CArray<MultiInt, 19584> piece_defense_table;
574 for (size_t i = 0; i < ONE_DIM; ++i)
575 {
576 for (int s=0; s<NStages; ++s)
577 {
578 piece_attack_table[i][s] = weights.value(i + ONE_DIM * 2 * s);
579 piece_defense_table[i][s] = weights.value(i + ONE_DIM * 2 * s + ONE_DIM);
580 }
581 }
582 for(int isP=0;isP<2;isP++)
583 for(int y_diff=-9;y_diff<=9;y_diff++)
584 for(int x_diff= -9;x_diff<=9;x_diff++){
585 int i2=index2(x_diff,y_diff,isP);
586 if(abs(x_diff)<9 && abs(y_diff)<9){
587 attack_nospace[i2]=
588 -(attack_table[index(x_diff,y_diff,true,isP)]+
589 attack_table[index(x_diff,y_diff,false,isP)]);
590 defense_nospace[i2]=
591 -(defense_table[index(x_diff,y_diff,true,isP)]+
592 defense_table[index(x_diff,y_diff,false,isP)]);
593 }
594 for(int ptypeo= PTYPEO_MIN;ptypeo<=PTYPEO_MAX;ptypeo++){
595 if(getPtype((PtypeO)ptypeo)==(int)PTYPE_EMPTY) continue;
596 int i1=index1(x_diff,y_diff,(PtypeO)ptypeo,isP);
597 int indexPieceUR,indexPieceUL;
598 int table_ptypeo=ptypeo;
599 if(getPtype((PtypeO)ptypeo)==PTYPE_EDGE) table_ptypeo=PTYPEO_EDGE;
600 if(getPtype((PtypeO)ptypeo)==PTYPE_EDGE || abs(x_diff)==9 || abs(y_diff)==9){
601 indexPieceUR= 0+0+(PTYPEO_EDGE-PTYPEO_MIN)*17*9+4896+isP*9792;
602 indexPieceUL= 0+0+(PTYPEO_EDGE-PTYPEO_MIN)*17*9+ isP*9792;
603 }
604 else{
605 indexPieceUR= index0(x_diff,y_diff,(PtypeO)ptypeo,true,isP);
606 indexPieceUL= index0(x_diff,y_diff,(PtypeO)ptypeo,false,isP);
607 }
608 attack_ul[i1]=piece_attack_table[indexPieceUL]+piece_table[table_ptypeo-PTYPEO_MIN];
609 defense_ul[i1]=piece_defense_table[indexPieceUL];
610 attack_dr[i1]=piece_attack_table[indexPieceUL]+piece_table[table_ptypeo-PTYPEO_MIN];
611 defense_dr[i1]=piece_defense_table[indexPieceUL];
612 {
613 int y_diff_1=y_diff+1, x_diff_1=x_diff-1;
614 for(;y_diff_1<=8 && x_diff_1>=-8;y_diff_1++,x_diff_1--){
615 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
616 int i=index(x_diff_1,y_diff_1,false,isP);
617 attack_ul[i1]+=attack_table[i];
618 defense_ul[i1]+=defense_table[i];
619 }
620 }
621 }
622 {
623 int y_diff_1=y_diff, x_diff_1=x_diff;
624 for(;y_diff_1<=8 && x_diff_1>=-8;y_diff_1++,x_diff_1--){
625 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
626 int i=index(x_diff_1,y_diff_1,false,isP);
627 attack_dr[i1]-=attack_table[i];
628 defense_dr[i1]-=defense_table[i];
629 }
630 }
631 }
632 attack_ur[i1]=piece_attack_table[indexPieceUR]+piece_table[table_ptypeo-PTYPEO_MIN];
633 defense_ur[i1]=piece_defense_table[indexPieceUR];
634 attack_dl[i1]=piece_attack_table[indexPieceUR]+piece_table[table_ptypeo-PTYPEO_MIN];
635 defense_dl[i1]=piece_defense_table[indexPieceUR];
636 {
637 int y_diff_1=y_diff+1, x_diff_1=x_diff+1;
638 for(;y_diff_1<=8 && x_diff_1<=8;y_diff_1++,x_diff_1++){
639 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
640 int i=index(x_diff_1,y_diff_1,true,isP);
641 attack_ur[i1]+=attack_table[i];
642 defense_ur[i1]+=defense_table[i];
643 }
644 }
645 }
646 {
647 int y_diff_1=y_diff, x_diff_1=x_diff;
648 for(;y_diff_1<=8 && x_diff_1<=8;y_diff_1++,x_diff_1++){
649 if(std::abs(x_diff_1)<=8 && std::abs(y_diff_1)<=8){
650 int i=index(x_diff_1,y_diff_1,true,isP);
651 attack_dl[i1]-=attack_table[i];
652 defense_dl[i1]-=defense_table[i];
653 }
654 }
655 }
656 }
657 }
658}
659
663
665{
666 for (size_t i = 0; i < ONE_DIM; ++i)
667 {
668 for (int s=0; s<NStages; ++s)
669 table[i][s] = weights.value(i + ONE_DIM*s);
670 }
671}
672
675{
676 for (size_t i = 0; i < ONE_DIM; ++i)
677 {
678 for (int s=0; s<NStages; ++s)
679 BishopHead::king_table[i][s] = weights.value(i + ONE_DIM*s);
680 }
681 for(int x_diff=0;x_diff<=8;x_diff++)
682 for(int y_diff=-8;y_diff<=8;y_diff++){
683 for(int i=0;i<32;i++)
684 BishopHead::king_table[(i*9+x_diff)*17+y_diff+8]+=BishopHead::table[i];
685 }
686 const PtypeO PTYPEO_EMPTY_R=newPtypeO(WHITE,PTYPE_EMPTY);
687 const PtypeO PTYPEO_EDGE_R=newPtypeO(BLACK,PTYPE_EDGE);
688 for(int x_diff=0;x_diff<=8;x_diff++)
689 for(int y_diff=-8;y_diff<=8;y_diff++){
690 BishopHead::king_table[(ptypeOIndex(PTYPEO_EMPTY_R)*9+x_diff)*17+y_diff+8]=
691 BishopHead::king_table[(ptypeOIndex(PTYPEO_EMPTY)*9+x_diff)*17+y_diff+8];
692 BishopHead::king_table[(ptypeOIndex(PTYPEO_EDGE_R)*9+x_diff)*17+y_diff+8]=
693 BishopHead::king_table[(ptypeOIndex(PTYPEO_EDGE)*9+x_diff)*17+y_diff+8];
694 }
695}
696
698{
699 for (size_t i = 0; i < ONE_DIM; ++i)
700 {
701 for (int s=0; s<NStages; ++s)
702 BishopHead::x_table[i][s] = weights.value(i + ONE_DIM*s);
703 }
704}
705
708{
709 MultiInt result;
711 i < PtypeTraits<BISHOP>::indexLimit;
712 ++i){
713 const Piece p = state.pieceOf(i);
714 if (p.isOnBoardNotPromoted()){
715 const Square pos=p.square();
716 if (p.owner() == BLACK){
717 if(pos.y()>=2){
719 if (!state.hasEffectAt(BLACK, up)){
720 const Square king = state.kingSquare(BLACK);
721 const PtypeO ptypeo = state.pieceAt(up).ptypeO();
722 const int index_k = indexK(BLACK, ptypeo,
723 std::abs(pos.x() - king.x()),
724 pos.y() - king.y());
725 result += king_table[index_k];
726 result += x_table[indexX<BLACK>(ptypeo, pos.x())];
727 }
728 }
729 }
730 else if(pos.y()<=8) {
732 if (!state.hasEffectAt(WHITE, up)){
733 const Square king = state.kingSquare(WHITE);
734 const PtypeO ptypeo = state.pieceAt(up).ptypeO();
735 const int index_k = indexK(WHITE, ptypeo,
736 std::abs(pos.x() - king.x()),
737 pos.y() - king.y());
738 result -= king_table[index_k];
739 result -= x_table[indexX<WHITE>(ptypeo, pos.x())];
740 }
741 }
742 }
743 }
744 return result;
745}
746
747
749
751{
752 for (size_t i = 0; i < ONE_DIM; ++i)
753 {
754 for (int s=0; s<NStages; ++s)
755 table[i][s] = weights.value(i + ONE_DIM*s);
756 }
757}
758
759template<osl::Player P>
762{
763 const Square king=state.kingSquare(P);
764 MultiInt result;
765 for (int i = PtypeTraits<ROOK>::indexMin;
766 i < PtypeTraits<ROOK>::indexLimit;
767 ++i)
768 {
769 const Piece rook = state.pieceOf(i);
770 if (!rook.isOnBoard())
771 {
772 continue;
773 }
775 j < PtypeTraits<BISHOP>::indexLimit;
776 ++j)
777 {
778 const Piece bishop = state.pieceOf(j);
779 if (!bishop.isOnBoard())
780 {
781 continue;
782 }
783 result += table[index<P>(king, rook, bishop)];
784 }
785 }
786 return result;
787}
788
791{
792 return evalOne<BLACK>(state)-evalOne<WHITE>(state);
793}
794
795
799
802{
803 for (size_t i = 0; i < ONE_DIM; ++i)
804 {
805 for (int s=0; s<NStages; ++s)
807 weights.value(i + ONE_DIM*s);
808 }
809}
810
813{
814 for (size_t i = 0; i < ONE_DIM; ++i)
815 {
816 for (int s=0; s<NStages; ++s)
818 weights.value(i + ONE_DIM*s);
819 }
820}
821
824{
825 for (size_t i = 0; i < ONE_DIM; ++i)
826 {
827 for (int s=0; s<NStages; ++s)
829 weights.value(i + ONE_DIM*s);
830 }
831}
832
835{
836 MultiInt result;
838 i < PtypeTraits<BISHOP>::indexLimit;
839 ++i)
840 {
841 const Piece bishop = state.pieceOf(i);
842 if (!bishop.isOnBoard())
843 {
844 continue;
845 }
846 int self, opp, all;
847 countBetween(state,
848 state.kingSquare(alt(bishop.owner())),
849 bishop, self, opp, all);
850 if (bishop.owner() == BLACK)
851 {
852 result += (self_table[self] + opp_table[opp] + all_table[all]);
853 }
854 else
855 {
856 result -= (self_table[self] + opp_table[opp] + all_table[all]);
857 }
858 }
859 return result;
860}
861
864 const NumEffectState &state, Square king, Piece bishop,
865 int &self_count, int &opp_count, int &total_count)
866{
867 assert(bishop.isOnBoard());
868 if ((king.x() + king.y() != bishop.square().x() + bishop.square().y()) &&
869 (king.x() - king.y() != bishop.square().x() - bishop.square().y()))
870 {
871 self_count = opp_count = total_count = 8;
872 return;
873 }
874 Direction dir;
875 assert(king.x() != bishop.square().x());
876 assert(king.y() != bishop.square().y());
877 if (king.x() < bishop.square().x())
878 {
879 if (king.y() < bishop.square().y())
880 {
881 dir = UR;
882 }
883 else
884 {
885 dir = DR;
886 }
887 }
888 else
889 {
890 if (king.y() < bishop.square().y())
891 {
892 dir = UL;
893 }
894 else
895 {
896 dir = DL;
897 }
898 }
899 const Player player = bishop.owner();
900 const Direction move_dir = (player == BLACK ? dir : inverse(dir));
901 self_count = opp_count = total_count = 0;
902 for (Square pos = state.mobilityOf(dir, bishop.number());
903 pos != king; pos = Board_Table.nextSquare(player, pos, move_dir))
904 {
905 assert(pos.isOnBoard());
906 const Piece piece = state.pieceAt(pos);
907 if (!piece.isEmpty())
908 {
909 ++total_count;
910 if (piece.owner() == player)
911 ++self_count;
912 else
913 ++opp_count;
914 }
915 }
916}
917
918
921
923BishopBishopPiece::setUp(const Weights &weights)
924{
925 for (size_t i = 0; i < ONE_DIM; ++i)
926 {
927 for (int s=0; s<NStages; ++s)
928 table[i][s] = weights.value(i + ONE_DIM*s);
929 }
930}
931
934{
935 MultiInt result;
936 const Piece bishop1 = state.pieceOf(PtypeTraits<BISHOP>::indexMin);
937 const Piece bishop2 = state.pieceOf(PtypeTraits<BISHOP>::indexMin + 1);
938 if (!bishop1.isOnBoard() || !bishop2.isOnBoard() ||
939 bishop1.owner() == bishop2.owner())
940 return result;
941 if (bishop1.square().x() + bishop1.square().y() !=
942 bishop2.square().x() + bishop2.square().y() &&
943 bishop1.square().x() - bishop1.square().y() !=
944 bishop2.square().x() - bishop2.square().y())
945 return result;
946
947 if (state.hasEffectByPtype<BISHOP>(bishop2.owner(), bishop1.square()))
948 return result;
949
950 Direction dir;
951 if (bishop1.square().x() < bishop2.square().x())
952 {
953 if (bishop1.square().y() < bishop2.square().y())
954 {
955 dir = UR;
956 }
957 else
958 {
959 dir = DR;
960 }
961 }
962 else
963 {
964 if (bishop1.square().y() < bishop2.square().y())
965 {
966 dir = UL;
967 }
968 else
969 {
970 dir = DL;
971 }
972 }
973 Square p1 = state.mobilityOf(inverse(dir), bishop1.number());
974 Square p2 = state.mobilityOf(dir, bishop2.number());
975 if (p1 == p2)
976 {
977 const Piece p = state.pieceAt(p1);
978 const bool black_with_support =
979 state.hasEffectAt<BLACK>(bishop1.owner() == BLACK ?
980 bishop1.square() : bishop2.square());
981 const bool white_with_support =
982 state.hasEffectAt<WHITE>(bishop1.owner() == WHITE ?
983 bishop1.square() : bishop2.square());
984 if (p.owner() == BLACK)
985 {
986 result += table[index(p.ptype(), black_with_support,
987 white_with_support)];
988 }
989 else
990 {
991 result -= table[index(p.ptype(), white_with_support,
992 black_with_support)];
993 }
994 }
995 return result;
996}
997
1000
1002RookRook::setUp(const Weights &weights)
1003{
1004 CArray<MultiInt, 800> orig_table;
1005 for (size_t i = 0; i < ONE_DIM; ++i)
1006 {
1007 for (int s=0; s<NStages; ++s)
1008 orig_table[i][s] = weights.value(i + ONE_DIM*s);
1009 }
1010 for (int owner = 0; owner < 2; ++owner)
1011 {
1012 const bool same_player = (owner == 0);
1013 for (int y1 = 0; y1 < 10; ++y1)
1014 {
1015 for (int y2 = 0; y2 < 10; ++y2)
1016 {
1017 for (int promoted1 = 0; promoted1 < 2; ++promoted1)
1018 {
1019 for (int promoted2 = 0; promoted2 < 2; ++promoted2)
1020 {
1021 if (same_player)
1022 {
1023 int y1p = y1;
1024 int y2p = y2;
1025 int promoted1p = promoted1;
1026 int promoted2p = promoted2;
1027 if (y1 > y2 || (y1 == y2 && !promoted1 && promoted2))
1028 {
1029 std::swap(y1p, y2p);
1030 std::swap(promoted1p, promoted2p);
1031 }
1032 table[index(same_player, promoted1, promoted2,
1033 y1, y2)] =
1034 orig_table[index(same_player, promoted1p, promoted2p,
1035 y1p, y2p)];
1036 }
1037 else
1038 {
1039 if (y1 + y2 > 10 || y1 == 0 ||
1040 (y1 + y2 == 10 && promoted1))
1041 {
1042 const int idx = index(same_player, promoted1, promoted2,
1043 y1, y2);
1044 table[idx] = orig_table[idx];
1045 }
1046 else
1047 {
1048 table[index(same_player, promoted1, promoted2,
1049 y1, y2)] =
1050 -orig_table[index(same_player, promoted2, promoted1,
1051 (10 - y2) % 10, (10 - y1) % 10)];
1052 }
1053 }
1054 }
1055 }
1056 }
1057 }
1058 }
1059}
1060
1062RookRook::eval(const NumEffectState &state)
1063{
1064 MultiInt result;
1066 Piece rook2 = state.pieceOf(PtypeTraits<ROOK>::indexMin + 1);
1067 if (rook1.owner() == rook2.owner())
1068 {
1069 if (rook1.owner() == BLACK)
1070 {
1071 result += table[index<true, BLACK>(rook1, rook2)];
1072 }
1073 else
1074 {
1075 result -= table[index<true, WHITE>(rook1, rook2)];
1076 }
1077 }
1078 else
1079 {
1080 if (rook1.owner() != BLACK)
1081 {
1082 std::swap(rook1, rook2);
1083 }
1084 result += table[index<false, BLACK>(rook1, rook2)];
1085 }
1086 return result;
1087}
1088
1089
1092
1094RookRookPiece::setUp(const Weights &weights)
1095{
1096 for (size_t i = 0; i < ONE_DIM; ++i)
1097 {
1098 for (int s=0; s<NStages; ++s)
1099 table[i][s] = weights.value(i + ONE_DIM*s);
1100 }
1101}
1102
1105{
1106 MultiInt result;
1107 const Piece rook1 = state.pieceOf(PtypeTraits<ROOK>::indexMin);
1108 const Piece rook2 = state.pieceOf(PtypeTraits<ROOK>::indexMin + 1);
1109 if (!rook1.isOnBoard() || !rook2.isOnBoard() ||
1110 rook1.owner() == rook2.owner())
1111 return result;
1112
1113 if (state.hasEffectByPtype<ROOK>(rook2.owner(), rook1.square()))
1114 return result;
1115
1116 Direction dir;
1117 bool vertical = false;
1118 if (rook1.square().x() == rook2.square().x())
1119 {
1120 vertical = true;
1121 if (rook1.square().y() < rook2.square().y())
1122 {
1123 dir = D;
1124 }
1125 else
1126 {
1127 dir = U;
1128 }
1129 }
1130 else if (rook1.square().y() == rook2.square().y())
1131 {
1132 if (rook1.square().x() < rook2.square().x())
1133 {
1134 dir = L;
1135 }
1136 else
1137 {
1138 dir = R;
1139 }
1140 }
1141 else
1142 {
1143 return result;
1144 }
1145
1146 Square p1 = state.mobilityOf(dir, rook1.number());
1147 Square p2 = state.mobilityOf(inverse(dir), rook2.number());
1148 assert(p1.isOnBoard() && p2.isOnBoard());
1149 if (p1 == p2)
1150 {
1151 const Piece p = state.pieceAt(p1);
1152 const bool black_with_support =
1153 state.hasEffectAt<BLACK>(rook1.owner() == BLACK ?
1154 rook1.square() : rook2.square());
1155 const bool white_with_support =
1156 state.hasEffectAt<WHITE>(rook1.owner() == WHITE ?
1157 rook1.square() : rook2.square());
1158 if (p.owner() == BLACK)
1159 {
1160 result += table[index(p.ptype(), black_with_support,
1161 white_with_support, vertical)];
1162 }
1163 else
1164 {
1165 result -= table[index(p.ptype(), white_with_support,
1166 black_with_support, vertical)];
1167 }
1168 }
1169 return result;
1170}
1171
1172
1175
1177BishopStandFile5::setUp(const Weights &weights)
1178{
1179 for (size_t i = 0; i < ONE_DIM; ++i)
1180 {
1181 for (int s=0; s<NStages; ++s)
1182 table[i][s] = weights.value(i + ONE_DIM*s);
1183 }
1184}
1185
1188{
1189 MultiInt result;
1190 if (state.hasPieceOnStand<BISHOP>(BLACK))
1191 {
1192 result += table[ptypeOIndex(state.pieceAt(Square(5, 3)).ptypeO())];
1193 }
1194 if (state.hasPieceOnStand<BISHOP>(WHITE))
1195 {
1196 PtypeO ptypeO = state.pieceAt(Square(5, 7)).ptypeO();
1197 ptypeO = altIfPiece(ptypeO);
1198 result -= table[ptypeOIndex(ptypeO)];
1199 }
1200 return result;
1201}
1202
1203
1204
1207
1210{
1211 for (size_t i = 0; i < ONE_DIM; ++i)
1212 {
1213 for (int s=0; s<NStages; ++s)
1214 table[i][s] = weights.value(i + ONE_DIM*s);
1215 }
1216}
1217
1218template <osl::Player Owner>
1221{
1222 const Square king = state.kingSquare(Owner);
1223 PieceMask pieces = state.effectedMask(alt(Owner));
1224 pieces &= state.piecesOnBoard(Owner);
1225 pieces &= ~state.effectedMask(Owner);
1226 MultiInt sum;
1227 while (pieces.any()) {
1228 const Piece p = state.pieceOf(pieces.takeOneBit());
1229 const Square sq = p.square();
1230 if (state.hasLongEffectAt<ROOK>(alt(Owner), sq)
1231 && state.hasEffectIf(newPtypeO(BLACK,ROOK), sq, king)) {
1232 if (Owner == BLACK)
1233 sum += table[index(p.ptype(), true, sq.canPromote(alt(Owner)))];
1234 else
1235 sum -= table[index(p.ptype(), true, sq.canPromote(alt(Owner)))];
1236 }
1237 if (state.hasLongEffectAt<BISHOP>(alt(Owner), sq)
1238 && state.hasEffectIf(newPtypeO(BLACK,BISHOP), sq, king)) {
1239 if (Owner == BLACK)
1240 sum += table[index(p.ptype(), false, sq.canPromote(alt(Owner)))];
1241 else
1242 sum -= table[index(p.ptype(), false, sq.canPromote(alt(Owner)))];
1243 }
1244 }
1245 return sum;
1246}
1247
1250{
1251 return addOne<BLACK>(state) + addOne<WHITE>(state);
1252}
1253
1254
1257
1259RookSilverKnight::setUp(const Weights &weights)
1260{
1261 for (size_t i = 0; i < ONE_DIM; ++i)
1262 {
1263 for (int s=0; s<NStages; ++s)
1264 table[i][s] = weights.value(i + ONE_DIM*s);
1265 }
1266}
1267
1270{
1271 MultiInt result;
1272 for (int i = PtypeTraits<ROOK>::indexMin;
1273 i < PtypeTraits<ROOK>::indexLimit;
1274 ++i)
1275 {
1276 const Piece rook = state.pieceOf(i);
1277 if (!rook.isOnBoard())
1278 {
1279 continue;
1280 }
1281 for (int i = PtypeTraits<SILVER>::indexMin;
1282 i < PtypeTraits<SILVER>::indexLimit;
1283 ++i)
1284 {
1285 const Piece silver = state.pieceOf(i);
1286 if (!silver.isOnBoard() || silver.isPromoted() ||
1287 silver.owner() != rook.owner())
1288 {
1289 continue;
1290 }
1291 for (int i = PtypeTraits<KNIGHT>::indexMin;
1292 i < PtypeTraits<KNIGHT>::indexLimit;
1293 ++i)
1294 {
1295 const Piece knight = state.pieceOf(i);
1296 if (!knight.isOnBoard() || knight.isPromoted() ||
1297 knight.owner() != rook.owner())
1298 {
1299 continue;
1300 }
1301
1302 if (rook.owner() == BLACK)
1303 {
1304 if (rook.square().x() > 5)
1305 {
1306 result += table[index(9 - rook.square().x(), rook.square().y() - 1,
1307 9 - silver.square().x(), silver.square().y() - 1,
1308 9 - knight.square().x(), knight.square().y() - 1)];
1309 }
1310 else
1311 {
1312 result += table[index(rook.square().x() - 1, rook.square().y() - 1,
1313 silver.square().x() - 1, silver.square().y() - 1,
1314 knight.square().x() - 1, knight.square().y() - 1)];
1315 }
1316 }
1317 else
1318 {
1319 if (rook.square().x() >= 5)
1320 {
1321 result -= table[index(9 - rook.square().x(), 9 - rook.square().y(),
1322 9 - silver.square().x(), 9 - silver.square().y(),
1323 9 - knight.square().x(), 9 - knight.square().y())];
1324 }
1325 else
1326 {
1327 result -= table[index(rook.square().x() - 1, 9 - rook.square().y(),
1328 silver.square().x() - 1, 9 - silver.square().y(),
1329 knight.square().x() - 1, 9 - knight.square().y())];
1330 }
1331 }
1332 }
1333 }
1334 }
1335 return result;
1336}
1337
1338
1341
1343BishopSilverKnight::setUp(const Weights &weights)
1344{
1345 for (size_t i = 0; i < ONE_DIM; ++i)
1346 {
1347 for (int s=0; s<NStages; ++s)
1348 table[i][s] = weights.value(i + ONE_DIM*s);
1349 }
1350}
1351
1354{
1355 MultiInt result;
1356 for (int i = PtypeTraits<BISHOP>::indexMin;
1357 i < PtypeTraits<BISHOP>::indexLimit;
1358 ++i)
1359 {
1360 const Piece bishop = state.pieceOf(i);
1361 if (!bishop.isOnBoard())
1362 {
1363 continue;
1364 }
1365 for (int i = PtypeTraits<SILVER>::indexMin;
1366 i < PtypeTraits<SILVER>::indexLimit;
1367 ++i)
1368 {
1369 const Piece silver = state.pieceOf(i);
1370 if (!silver.isOnBoard() || silver.isPromoted() ||
1371 silver.owner() != bishop.owner())
1372 {
1373 continue;
1374 }
1375 for (int i = PtypeTraits<KNIGHT>::indexMin;
1376 i < PtypeTraits<KNIGHT>::indexLimit;
1377 ++i)
1378 {
1379 const Piece knight = state.pieceOf(i);
1380 if (!knight.isOnBoard() || knight.isPromoted() ||
1381 knight.owner() != bishop.owner())
1382 {
1383 continue;
1384 }
1385
1386 if (bishop.owner() == BLACK)
1387 {
1388 if (bishop.square().x() > 5)
1389 {
1390 result += table[index(9 - bishop.square().x(), bishop.square().y() - 1,
1391 9 - silver.square().x(), silver.square().y() - 1,
1392 9 - knight.square().x(), knight.square().y() - 1)];
1393 }
1394 else
1395 {
1396 result += table[index(bishop.square().x() - 1, bishop.square().y() - 1,
1397 silver.square().x() - 1, silver.square().y() - 1,
1398 knight.square().x() - 1, knight.square().y() - 1)];
1399 }
1400 }
1401 else
1402 {
1403 if (bishop.square().x() >= 5)
1404 {
1405 result -= table[index(9 - bishop.square().x(), 9 - bishop.square().y(),
1406 9 - silver.square().x(), 9 - silver.square().y(),
1407 9 - knight.square().x(), 9 - knight.square().y())];
1408 }
1409 else
1410 {
1411 result -= table[index(bishop.square().x() - 1, 9 - bishop.square().y(),
1412 silver.square().x() - 1, 9 - silver.square().y(),
1413 knight.square().x() - 1, 9 - knight.square().y())];
1414 }
1415 }
1416 }
1417 }
1418 }
1419 return result;
1420}
1421
1422
1425
1427AttackMajorsInBase::setUp(const Weights &weights)
1428{
1429 for (size_t i = 0; i < ONE_DIM; ++i) {
1430 for (int s=0; s<NStages; ++s)
1431 table[i][s] = weights.value(i + ONE_DIM*s);
1432 if (i > 0)
1433 table[i] += table[0];
1434 }
1435}
1436
1437template <osl::Player P>
1439AttackMajorsInBase::addOne(const NumEffectState &state, Piece rook, MultiInt& result)
1440{
1441 Square sq = rook.square();
1442 if (state.hasEffectAt(alt(P), sq)
1443 || sq.squareForBlack(P).y() < 8)
1444 return;
1445 typedef std::pair<Offset,Square> pair_t;
1446 const CArray<pair_t, 7> bishop_attack =
1447 {{
1448 pair_t(Offset::make<P,U>(), sq.neighbor<P, UL>()),
1449 pair_t(Offset::make<P,U>(), sq.neighbor<P, UR>()),
1450 pair_t(Offset::make<P,L>(), sq.neighbor<P, UL>()),
1451 pair_t(Offset::make<P,R>(), sq.neighbor<P, UR>()),
1452 pair_t(Offset::make<P,D>(), sq.neighbor<P, UL>()),
1453 pair_t(Offset::make<P,D>(), sq.neighbor<P, UR>()),
1454 pair_t(Offset::make<P,U>(), sq.neighbor<P, U>()),
1455 }};
1456 const bool has_gold = state.hasPieceOnStand(alt(P), GOLD);
1457 const bool rook_support = state.hasEffectAt(P, sq);
1458 for (pair_t pair: bishop_attack) {
1459 const Square attack_square = pair.second;
1460 if (! state[attack_square].isEmpty()
1461 || state.countEffect(P, attack_square) > 1)
1462 continue;
1463 const Square bishop_square = attack_square + pair.first;
1464 Piece p = state[bishop_square];
1465 if (! p.isPlayerPtype(P,BISHOP)
1466 || state.hasEffectAt(alt(P), bishop_square))
1467 continue;
1468 int a = state.countEffect(alt(P), attack_square) + has_gold;
1469 if (a <= state.countEffect(P, attack_square))
1470 continue;
1471 const int i = index(state.findCheapAttack(P, attack_square).ptype(),
1472 state.findCheapAttack(alt(P), attack_square).ptype(),
1473 has_gold, rook_support,
1474 state.hasEffectNotBy(P, rook, bishop_square));
1475 if (P == BLACK)
1476 result += table[i];
1477 else
1478 result -= table[i];
1479 }
1480}
1481
1484{
1485 MultiInt result;
1486 for (int i=0; i<state.nthLimit<ROOK>(); ++i) {
1487 const Piece rook = state.nth<ROOK>(i);
1488 if (! rook.isOnBoard() || rook.isPromoted())
1489 continue;
1490 Player P = rook.owner();
1491 if (P == BLACK)
1492 addOne<BLACK>(state, rook, result);
1493 else
1494 addOne<WHITE>(state, rook, result);
1495 }
1496 return result;
1497}
1498
1499
1500namespace osl
1501{
1502 namespace eval
1503 {
1504 namespace ml
1505 {
1506 template class MajorY<true, ROOK>;
1507 template class MajorY<false, ROOK>;
1508 template class MajorY<true, BISHOP>;
1509 template class MajorY<false, BISHOP>;
1510 template class RookPawn<true>;
1511 template class RookPawn<false>;
1512 template class MajorGoldSilverAttacked<false>;
1513 template MultiInt KingRookBishop::evalOne<BLACK>(const NumEffectState &state);
1514 template MultiInt KingRookBishop::evalOne<WHITE>(const NumEffectState &state);
1515 }
1516 }
1517}
1518
1519// ;;; Local Variables:
1520// ;;; mode:c++
1521// ;;; c-basic-offset:2
1522// ;;; End:
const Square nextSquare(Player P, Square pos, Direction dr) const
next position from pos for player P.
Definition boardTable.h:61
利きを持つ局面
const NumBitmapEffect effectSetAt(Square sq) const
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
bool hasEffectNotBy(Player player, Piece piece, Square target) const
対象とするマスにあるプレイヤーの(ただしある駒以外)利きがあるかどうか.
int countEffect(Player player, Square target) const
利きの数を数える.
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
bool hasLongEffectAt(Player P, Square to) const
あるマスにPTYPEの長い利きがあるかどうか.
const Piece findCheapAttack(Player P, Square square) const
Square mobilityOf(Direction d, int num) const
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
const PieceMask & piecesOnBoard(Player p) const
bool hasEffectByPtype(Player attack, Square target) const
target に ptype の利きがあるか? 成不成を区別しない
駒番号のビットセット.
Definition pieceMask.h:21
bool any() const
Definition pieceMask.h:57
PtypeO ptypeO() const
Definition basic_type.h:824
Ptype ptype() const
Definition basic_type.h:821
bool isPromoted() const
promoteした駒かどうかをチェックする
Definition basic_type.h:898
const Square square() const
Definition basic_type.h:832
bool isEmpty() const
Definition basic_type.h:913
Player owner() const
Definition basic_type.h:963
bool isPlayerPtype(Player pl, Ptype ptype) const
あるpieceがPlayer pの持ち物でPtype ptypeであるかどうかをチェックする. TはEMPTY, EDGEではない.
Definition basic_type.h:937
bool canMoveOn() const
Player Pの駒が,thisの上に移動できるか? PIECE_EMPTY 0x00008000 BLACK_PIECE 0x000XxxYY X>=2, YY>0 PIECE_EDGE 0xfff1...
Definition basic_type.h:980
int number() const
Definition basic_type.h:828
bool isOnBoardNotPromoted() const
promoteしていないOnBoardの駒であることのチェック Lance位しか使い道がない?
Definition basic_type.h:904
bool isOnBoard() const
Definition basic_type.h:985
bool hasPieceOnStand(Player player, Ptype ptype) const
const Piece nth(int n) const
unpromote(PTYPE)のn番目の駒を帰す.
Player turn() const
const Piece pieceOf(int num) const
Definition simpleState.h:76
static int nthLimit()
Square kingSquare() const
Definition simpleState.h:94
bool isPawnMaskSet(Player player, int x) const
const Piece pieceAt(Square sq) const
const Square rotate180EdgeOK() const
Definition basic_type.h:617
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
const Square neighbor() const
Definition basic_type.h:746
bool canPromote() const
Definition basic_type.h:659
const Square rotate180() const
Definition basic_type.h:613
const Square squareForBlack(Player player) const
Definition basic_type.h:598
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
Definition basic_type.h:583
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
現在の定義 (2005/3/4以降)
int countEffect(Player pl) const
static MultiInt weight
Definition majorPiece.h:131
static void setUp(const Weights &weights, int stage)
static void addOne(const NumEffectState &state, Piece rook, MultiInt &)
static CArray< MultiInt, ONE_DIM > table
Definition majorPiece.h:698
static void setUp(const Weights &weights)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 64 > table
Definition majorPiece.h:545
static void setUp(const Weights &weights)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 612 > defense_table
Definition majorPiece.h:394
static CArray< MultiInt, 23104 > defense_ur
Definition majorPiece.h:400
static CArray< MultiInt, 23104 > attack_ur
Definition majorPiece.h:396
static CArray< MultiInt, 23104 > defense_dr
Definition majorPiece.h:402
static CArray< MultiInt, 612 > attack_table
Definition majorPiece.h:393
static CArray< MultiInt, 23104 > attack_dr
Definition majorPiece.h:398
static CArray< MultiInt, 722 > attack_nospace
Definition majorPiece.h:404
static CArray< MultiInt, 722 > defense_nospace
Definition majorPiece.h:405
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 32 > piece_table
Definition majorPiece.h:395
static CArray< MultiInt, 23104 > defense_dl
Definition majorPiece.h:403
static CArray< MultiInt, 23104 > attack_ul
Definition majorPiece.h:397
static CArray< MultiInt, 23104 > defense_ul
Definition majorPiece.h:401
static CArray< MultiInt, 23104 > attack_dl
Definition majorPiece.h:399
static MultiInt evalOne(const NumEffectState &state, Square bishop, Square myKing, Square opKing, Square ulp, Square urp, Square dlp, Square drp, bool isP)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights, int stage)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 32 > table
Definition majorPiece.h:460
static MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static CArray< MultiInt, 4896 > king_table
Definition majorPiece.h:461
static CArray< MultiInt, 160 > x_table
Definition majorPiece.h:462
static CArray< MultiInt, ONE_DIM > table
Definition majorPiece.h:680
static MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 32 > table
Definition majorPiece.h:630
static MultiInt eval(const NumEffectState &state)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 374544 > table
Definition majorPiece.h:486
static void setUp(const Weights &weights)
static MultiInt evalOne(const NumEffectState &state)
static CArray< MultiInt, ONE_DIM > table
Definition majorPiece.h:643
static void setUp(const Weights &weights)
static MultiInt addOne(const NumEffectState &state)
static MultiInt eval(const NumEffectState &state)
static int eval(const NumEffectState &state)
static int evalOne(const NumEffectState &state)
static int index(const NumEffectState &state, Piece piece)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
Definition majorPiece.cc:12
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static CArray< MultiInt, 9 > opp_table
Definition majorPiece.h:511
static CArray< MultiInt, 9 > all_table
Definition majorPiece.h:512
static CArray< MultiInt, 9 > self_table
Definition majorPiece.h:510
static MultiInt eval(const NumEffectState &state)
static void countBetween(const NumEffectState &state, Square king, Piece bishop, int &self_count, int &opp_count, int &total_count)
static CArray< MultiInt, 23104 > attack_d
Definition majorPiece.h:257
static MultiInt evalOne(const NumEffectState &state, Square rook, Square myKing, Square opKing, Square up, Square dp, Square rp, Square lp, bool isP)
static CArray< MultiInt, 23104 > defense_d
Definition majorPiece.h:261
static CArray< MultiInt, 23104 > defense_u
Definition majorPiece.h:260
static CArray< MultiInt, 612 > attack_table
Definition majorPiece.h:253
static CArray< MultiInt, 23104 > attack_u
Definition majorPiece.h:256
static CArray< MultiInt, 23104 > attack_l
Definition majorPiece.h:258
static CArray< MultiInt, 23104 > attack_r
Definition majorPiece.h:259
static CArray< MultiInt, 722 > attack_nospace
Definition majorPiece.h:264
static CArray< MultiInt, 722 > defense_nospace
Definition majorPiece.h:265
static CArray< MultiInt, 23104 > defense_r
Definition majorPiece.h:263
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 612 > defense_table
Definition majorPiece.h:254
static int index2(Square king, Square from, bool isP)
黒の飛車(竜)がある場所は空マスでないのでその分を補正するテーブル {attack,defense}_nospace へのアクセス king - 玉の位置 from - 飛車(竜)の位置 isP - 竜...
Definition majorPiece.h:234
static int index1(Square king, Square from, PtypeO ptypeO, bool isP)
黒の飛車(竜)からの利きのある駒のindex {attack,defense}_{u,r,l,d} へのアクセスに使う from - 駒の位置 king - 玉の位置 ptypeO - 駒の種類,白から...
Definition majorPiece.h:205
static CArray< MultiInt, 32 > piece_table
Definition majorPiece.h:255
static CArray< MultiInt, 23104 > defense_l
Definition majorPiece.h:262
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights, int stage)
static void setUp(const Weights &weights)
Definition majorPiece.cc:60
static CArray< MultiInt, 180 > table
Definition majorPiece.h:104
static MultiInt eval(const NumEffectState &state, const CArray2d< int, 2, 9 > &pawns)
Definition majorPiece.cc:84
static void setUp(const Weights &weights)
Definition majorPiece.cc:74
static CArray< MultiInt, 1620 > y_attack_table
Definition majorPiece.h:105
static CArray< MultiInt, 1620 > y_defense_table
Definition majorPiece.h:106
static int eval(const NumEffectState &state)
Definition majorPiece.cc:32
static void setUp(const Weights &weights)
Definition majorPiece.cc:26
static void setUp(const Weights &weights)
static CArray< MultiInt, 256 > promote_defense_table
Definition majorPiece.h:294
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 144 > promote_defense_rook_table
Definition majorPiece.h:295
static void setUp(const Weights &weights)
static CArray< MultiInt, 128 > table
Definition majorPiece.h:620
static MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static void setUp(const Weights &weights)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 800 > table
Definition majorPiece.h:603
static void setUp(const Weights &weights)
static CArray< MultiInt, ONE_DIM > table
Definition majorPiece.h:662
static MultiInt eval(const NumEffectState &state)
CArray< PiecePair::IndexTable, 10 > & x_table
Definition piecePair.cc:35
const PtypeO PTYPEO_EMPTY
Definition basic_type.h:303
@ ROOK
Definition basic_type.h:100
@ BISHOP
Definition basic_type.h:99
@ PTYPE_EDGE
Definition basic_type.h:86
@ PTYPE_EMPTY
Definition basic_type.h:85
@ GOLD
Definition basic_type.h:94
const int PTYPE_SIZE
Definition basic_type.h:107
Ptype getPtype(PtypeO ptypeO)
Definition basic_type.h:217
const int NStages
Definition midgame.h:11
const BoardTable Board_Table
Definition tables.cc:95
Direction
Definition basic_type.h:310
unsigned int ptypeOIndex(PtypeO ptypeo)
Definition basic_type.h:205
Player
Definition basic_type.h:8
@ WHITE
Definition basic_type.h:10
@ BLACK
Definition basic_type.h:9
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
@ PTYPEO_MAX
Definition basic_type.h:201
@ PTYPEO_MIN
Definition basic_type.h:200
constexpr Player alt(Player player)
Definition basic_type.h:13
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
PtypeO altIfPiece(PtypeO ptypeO)
Pieceの時にはowner を反転する
Definition basic_type.h:281
constexpr Direction inverse(Direction d)
Definition basic_type.h:358
size_t dimension() const
Definition weights.h:29
int value(size_t index) const
Definition weights.h:27