This file is indexed.

/usr/include/osl/eval/majorPiece.h is in libosl-dev 0.8.0-1.4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/* majorPiece.h
 */

#ifndef EVAL_ML_MAJORPIECE_H
#define EVAL_ML_MAJORPIECE_H

#include "osl/eval/weights.h"
#include "osl/eval/midgame.h"
#include "osl/numEffectState.h"
#include <cstdlib>

namespace osl
{
  namespace eval
  {
    namespace ml
    {
      template <bool Opening, Ptype MajorBasic>
      class MajorY
      {
      private:
	static CArray<int, 18> table;
	static int index(Piece piece)
	{
	  return ((piece.owner() == BLACK) ? (piece.square().y() - 1) :
		  (9 - piece.square().y())) + (piece.isPromoted() ? 9 : 0);
	}
      public:
	enum { DIM = 18 };
	static void setUp(const Weights &weights);
	static int eval(const NumEffectState &state)
	{
	  int value = 0;
	  for (int i = PtypeTraits<MajorBasic>::indexMin;
	       i < PtypeTraits<MajorBasic>::indexLimit;
	       ++i)
	  {
	    const Piece piece = state.pieceOf(i);
	    if (piece.isOnBoard())
	      {
		if (piece.owner() == BLACK)
		  value += table[index(piece)];
	        else
		  value -= table[index(piece)];
	      }
	  }
	  return value;
	}
      };

      class RookYOpening : public MajorY<true, ROOK>
      {
      };
      class RookYEnding : public MajorY<false, ROOK>
      {
      };
      class BishopYOpening : public MajorY<true, BISHOP>
      {
      };
      class BishopYEnding : public MajorY<false, BISHOP>
      {
      };

      template <bool Opening>
      class RookPawn
      {
      public:
	enum { DIM = 1 };
	static void setUp(const Weights &weights);
	static int eval(const NumEffectState &state);
      private:
	static int weight;
      };
      class RookPawnOpening : public RookPawn<true>
      {
      };
      class RookPawnEnding : public RookPawn<false>
      {
      };

      class RookPawnY
      {
	friend class RookPawnYX;
      public:
	enum { ONE_DIM = 180, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state,
			      const CArray2d<int, 2, 9> &pawns);
      private:
	static int index(const Piece rook, const int pawn_y)
	{
	  const int rook_y =
	    (rook.owner() == BLACK ? rook.square().y() : 10 - rook.square().y());
	  return (rook_y - 1) * 10 + pawn_y + (rook.isPromoted() ? 90 : 0);
	}
	static int indexY(const Square king,
			  const Piece rook, int pawn_y)
	{
	  const int x_diff = std::abs(rook.square().x() - king.x());
	  const int rook_y =
	    (rook.owner() == BLACK ? rook.square().y() : 10 - rook.square().y());
	  return x_diff * 10 * 9 + (rook_y - 1) * 10 + pawn_y + (rook.isPromoted() ? 810 : 0);
	}
	static CArray<MultiInt, 180> table;
	static CArray<MultiInt, 1620> y_attack_table;
	static CArray<MultiInt, 1620> y_defense_table;
      };

      class RookPawnYX
      {
      public:
	enum { ONE_DIM = 1620, DIM = ONE_DIM * 2*EvalStages };
	static void setUp(const Weights &weights);
      };

      class AllMajor
      {
      public:
	enum { DIM = 1 };
	static void setUp(const Weights &weights,int stage);
	static MultiInt eval(int black_major_count)
	{
	  if (black_major_count == 4)
	    return weight;
	  else if (black_major_count == 0)
	    return -weight;

	  return MultiInt();
	}
      private:
	static MultiInt weight;
      };

      template <bool Opening>
      class MajorGoldSilverAttacked
      {
      public:
	enum { DIM = 32 };
	static void setUp(const Weights &weights);
	static int eval(const NumEffectState &state);
	static int index(const NumEffectState &state, Piece piece);
	template <Ptype PTYPE>
	static int evalOne(const NumEffectState &state);
      private:
	static CArray<int, 32> table;
      };

      class MajorGoldSilverAttackedOpening : public MajorGoldSilverAttacked<true>
      {
      };
      class MajorGoldSilverAttackedEnding : public MajorGoldSilverAttacked<false>
      {
      };

      class RookEffectBase
      {
	friend class RookEffectPiece;
      public:
	enum { ONE_DIM = 612, DIM = ONE_DIM * 2 };
	static MultiInt eval(const NumEffectState &state);
      protected:
	template<Player P>
	static MultiInt evalOne(const NumEffectState& state,
				 Square rook,
				 Square myKing,
				 Square opKing,
				 Square up,
				 Square dp,
				 Square rp,
				 Square lp,
				 bool isP);
	/**
	 * (abs_x_diff, y_diff) - 玉を原点とした時の空マスの相対位置
	 * horizontal - 飛車の横利きがある場合
	 * is_promoted - 竜の場合
	 */
	static int index(int abs_x_diff, int y_diff, bool horizontal, bool is_promoted)
	{
	  return y_diff + 8 + abs_x_diff * 17 + (horizontal ? 153 : 0) +
	    (is_promoted ? 306 : 0);
	}
	/**
	 * 黒の飛車(竜)から利きのある駒
	 * (abs_x_diff, y_diff) - 駒を基準にした玉の相対位置
	 *                        abs_x_diffは絶対値
	 * ptypeO - 駒のptypeO, 白からの場合は反転
	 * horizontal - 飛車の横利きがある場合
	 * is_promoted - 竜の場合
	 */
	static int index0(int abs_x_diff,int y_diff,
			  PtypeO ptypeO,
			  bool horizontal, bool promoted){
	  return y_diff+8+abs_x_diff*17+(ptypeO - PTYPEO_MIN) * 17 * 9 +
	    (horizontal ? 4896 : 0) + (promoted ? 9792 : 0);
	}
	/**
	 * 黒の飛車(竜)からの利きのある駒のindex
	 * {attack,defense}_{u,r,l,d} へのアクセスに使う
	 * from - 駒の位置
	 * king - 玉の位置
	 * ptypeO - 駒の種類,白からの利きの場合は反転.
	 *          (BLACK,PTYPE_EDGE)もあり得る
	 * isP - 竜の場合
	 */
	static int index1(Square king,Square from,PtypeO ptypeO,bool isP)
	{
	  int y_diff=from.y()-king.y();
	  int x_diff=from.x()-king.x();
	  return index1(x_diff,y_diff,ptypeO,isP);
	}
	/**
	 * 黒の飛車(竜)からの利きのある駒のindex
	 * {attack,defense}_{u,r,l,d} へのアクセスに使う
	 * (x_diff, y_diff) - 玉を基準に見た駒の相対位置
	 * ptypeO - 駒の種類,白からの利きの場合は反転.
	 *          (BLACK,PTYPE_EDGE)もあり得る
	 * isP - 竜の場合
	 */
	static int index1(int x_diff,int y_diff,PtypeO ptypeO,bool isP){
	  assert(-9 <= y_diff && y_diff <= 9);
	  assert(-9 <= x_diff && x_diff <= 9);
	  assert(getPtype((PtypeO)ptypeO)!=PTYPE_EMPTY);
	  int index=(ptypeO-PTYPEO_MIN)+32*((y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0)));
	  assert(0<=index && index<32*19*19*2);
	  return index;
	}
	/**
	 * 黒の飛車(竜)がある場所は空マスでないのでその分を補正するテーブル
	 * {attack,defense}_nospace へのアクセス
	 * king - 玉の位置
	 * from - 飛車(竜)の位置
	 * isP - 竜の場合
	 */
        static int index2(Square king,Square from,bool isP)
	{
	  int y_diff=from.y()-king.y();
	  int x_diff=from.x()-king.x();
	  return index2(x_diff,y_diff,isP);
	}
	/**
	 * 黒の飛車(竜)がある場所は空マスでないのでその分を補正するテーブル
	 * {attack,defense}_nospace へのアクセス
	 * (x_diff, y_diff)  - 玉を基準にしてみた飛車(竜)の相対位置
	 * isP - 竜の場合
	 */
	static int index2(int x_diff,int y_diff,bool isP){
	  assert(-9 <= y_diff && y_diff <= 9);
	  assert(-9 <= x_diff && x_diff <= 9);
	  int index=(y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0));
	  assert(0<=index && index<19*19*2);
	  return index;
	}
	static CArray<MultiInt, 612> attack_table;
	static CArray<MultiInt, 612> defense_table;
	static CArray<MultiInt, 32> piece_table;
	static CArray<MultiInt, 23104> attack_u;
	static CArray<MultiInt, 23104> attack_d;
	static CArray<MultiInt, 23104> attack_l;
	static CArray<MultiInt, 23104> attack_r;
	static CArray<MultiInt, 23104> defense_u;
	static CArray<MultiInt, 23104> defense_d;
	static CArray<MultiInt, 23104> defense_l;
	static CArray<MultiInt, 23104> defense_r;
	static CArray<MultiInt, 722> attack_nospace;
	static CArray<MultiInt, 722> defense_nospace;
      };
      class RookEffect : public RookEffectBase
      {
      public:
	static void setUp(const Weights &weights,int stage);
      };

      class RookEffectPiece
      {
      public:
	enum { DIM = 32 * EvalStages };
	static void setUp(const Weights &weights);
      };
      class RookEffectPieceKingRelative : RookEffectBase
      {
      public:
	enum { ONE_DIM = 19584, DIM = ONE_DIM * 2*EvalStages };
	static void setUp(const Weights & weights);
      };

      class RookPromoteDefense : public RookEffectBase
      {
	friend class RookPromoteDefenseRookH;
      public:
	enum { ONE_DIM = 256, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static CArray<MultiInt, 256> promote_defense_table;
	static CArray<MultiInt, 144> promote_defense_rook_table;
      };

      class RookPromoteDefenseRookH : public RookEffectBase
      {
      public:
	enum { ONE_DIM = 144, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
      private:
      };

      class BishopEffectBase
      {
	friend class BishopEffectPiece;
      public:
	enum { ONE_DIM = 612, DIM = ONE_DIM * 2 };
	static MultiInt eval(const NumEffectState &state);
      protected:
	template<Player P>
	static MultiInt evalOne(const NumEffectState& state,
				 Square bishop,
				 Square myKing,
				 Square opKing,
				 Square ulp,
				 Square urp,
				 Square dlp,
				 Square drp,
				 bool isP);
	static int index(int x_diff, int y_diff, bool ur, bool promoted)
	{
	  if (x_diff<0)
	    ur = !ur;
	  return y_diff + 8 + std::abs(x_diff) * 17 + (ur ? 153 : 0) + (promoted ? 306 : 0);
	}
	static int index0(int x_diff, int y_diff,PtypeO ptypeO,bool ur, bool promoted)
	{
	  if (x_diff>0)
	    ur = !ur;
	  return -y_diff + 8 + std::abs(x_diff) * 17 + (ptypeO - PTYPEO_MIN) * 17 * 9 +
	    (ur ? 4896 : 0) + (promoted ? 9792 : 0);
	}
	/**
	 * 黒の角(馬)からの利きのある駒のindex
	 * {attack,defense}_{ul,ur,dl,dr} へのアクセスに使う
	 * from - 駒の位置
	 * king - 玉の位置
	 * ptypeO - 駒の種類,白からの利きの場合は反転.
	 *          (BLACK,PTYPE_EDGE)もあり得る
	 * isP - 馬の場合
	 */
	static int index1(Square king,Square from,PtypeO ptypeO,bool isP)
	{
	  int y_diff=from.y()-king.y();
	  int x_diff=from.x()-king.x();
	  return index1(x_diff,y_diff,ptypeO,isP);
	}
	/**
	 * 黒の角(馬)からの利きのある駒のindex
	 * {attack,defense}_{ul,ur,dl,dr} へのアクセスに使う
	 * (x_diff, y_diff) - 玉を基準に見た駒の相対位置
	 * ptypeO - 駒の種類,白からの利きの場合は反転.
	 *          (BLACK,PTYPE_EDGE)もあり得る
	 * isP - 馬の場合
	 */
	static int index1(int x_diff,int y_diff,PtypeO ptypeO,bool isP){
	  assert(-9 <= y_diff && y_diff <= 9);
	  assert(-9 <= x_diff && x_diff <= 9);
	  assert(getPtype((PtypeO)ptypeO)!=PTYPE_EMPTY);
	  int index=(ptypeO-PTYPEO_MIN)+32*((y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0)));
	  assert(0<=index && index<32*19*19*2);
	  return index;
	}
	/**
	 * 黒の角(馬)がある場所は空マスでないのでその分を補正するテーブル
	 * {attack,defense}_nospace へのアクセス
	 * king - 玉の位置
	 * from - 角(馬)の位置
	 * isP - 馬の場合
	 */
        static int index2(Square king,Square from,bool isP)
	{
	  int y_diff=from.y()-king.y();
	  int x_diff=from.x()-king.x();
	  return index2(x_diff,y_diff,isP);
	}
	/**
	 * 黒の角(馬)がある場所は空マスでないのでその分を補正するテーブル
	 * {attack,defense}_nospace へのアクセス
	 * (x_diff, y_diff)  - 玉を基準にしてみた角(馬)の相対位置
	 * isP - 馬の場合
	 */
	static int index2(int x_diff,int y_diff,bool isP){
	  assert(-9 <= y_diff && y_diff <= 9);
	  assert(-9 <= x_diff && x_diff <= 9);
	  int index=(y_diff+9)+19*(x_diff+9+19*(isP ? 1 : 0));
	  assert(0<=index && index<19*19*2);
	  return index;
	}
	static CArray<MultiInt, 612> attack_table;
	static CArray<MultiInt, 612> defense_table;
	static CArray<MultiInt, 32> piece_table;
	static CArray<MultiInt, 23104> attack_ur;
	static CArray<MultiInt, 23104> attack_ul;
	static CArray<MultiInt, 23104> attack_dr;
	static CArray<MultiInt, 23104> attack_dl;
	static CArray<MultiInt, 23104> defense_ur;
	static CArray<MultiInt, 23104> defense_ul;
	static CArray<MultiInt, 23104> defense_dr;
	static CArray<MultiInt, 23104> defense_dl;
	static CArray<MultiInt, 722> attack_nospace;
	static CArray<MultiInt, 722> defense_nospace;
      };
      class BishopEffect : public BishopEffectBase
      {
      public:
	static void setUp(const Weights &weights,int stage);
      };
      class BishopEffectPiece
      {
      public:
	enum { DIM = 32*EvalStages };
	static void setUp(const Weights &weights);
      };

      class BishopEffectPieceKingRelative : BishopEffectBase
      {
      public:
	enum { ONE_DIM = 19584, DIM = ONE_DIM * 2*EvalStages };
	static void setUp(const Weights & weights);
      };

      class BishopHead
      {
	friend class BishopHeadKingRelative;
	friend class BishopHeadX;
      public:
	enum { ONE_DIM = 32, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static int indexK(Player player, PtypeO ptypeO, int x_diff, int y_diff)
	{
	  if (player == WHITE)
	    {
	      ptypeO=(PtypeO)(static_cast<int>(ptypeO)^(~15));
	    }
	  if (player == WHITE)
	    {
	      y_diff = -y_diff;
	    }
	  return (ptypeOIndex(ptypeO) * 9 + x_diff) * 17 + y_diff + 8;
	}
	template <Player P>
	static int indexX(PtypeO ptypeO, int x)
	{
	  if (x > 5)
	  {
	    x = 10 - x;
	  }
	  if (P == WHITE)
	  {
	    ptypeO = altIfPiece(ptypeO);
	  }
	  return x - 1 + 5 * ptypeOIndex(ptypeO);
	}
	static CArray<MultiInt, 32> table;
	static CArray<MultiInt, 4896> king_table;
	static CArray<MultiInt, 160> x_table;
      };

      class BishopHeadKingRelative
      {
      public:
	enum { ONE_DIM = 4896, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
      };
      class BishopHeadX
      {
      public:
	enum { ONE_DIM = 160, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
      };
      class KingRookBishop
      {
      public:
	enum { ONE_DIM = 374544, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
	template<Player King>
	static MultiInt evalOne(const NumEffectState &state);
	static MultiInt eval(const NumEffectState &state);
      private:
	static CArray<MultiInt, 374544> table;
	template <Player King>
	static int index(const Square king, const Piece rook, const Piece bishop)
	{
	  const int rook_x = std::abs(king.x() - rook.square().x());
	  const int bishop_x = std::abs(king.x() - bishop.square().x());
	  const int rook_y = (King == BLACK ? rook.square().y() - king.y() : king.y() - rook.square().y());
	  const int bishop_y = (King == BLACK ? bishop.square().y() - king.y() : king.y() - bishop.square().y());
	  return bishop_y + 8 + 17 * (bishop_x + 9 * (rook_y + 8 + 17 * (rook_x + 9 * ((bishop.owner() == King ? 1 : 0) + 2 * ((rook.owner() == King ? 1 : 0) + 2 * (2 * (bishop.isPromoted() ? 1 : 0) + (rook.isPromoted() ? 1 : 0)))))));
	}
      };

      class NumPiecesBetweenBishopAndKing
      {
	friend class NumPiecesBetweenBishopAndKingSelf;
	friend class NumPiecesBetweenBishopAndKingOpp;
	friend class NumPiecesBetweenBishopAndKingAll;
      public:
	static MultiInt eval(const NumEffectState &state);
      private:
	static void countBetween(const NumEffectState &state,
				 Square king, Piece bishop,
				 int &self_count, int &opp_count,
				 int &total_count);
	static CArray<MultiInt, 9> self_table;
	static CArray<MultiInt, 9> opp_table;
	static CArray<MultiInt, 9> all_table;
      };
      class NumPiecesBetweenBishopAndKingSelf
      {
      public:
	enum { ONE_DIM = 9, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
      };
      class NumPiecesBetweenBishopAndKingOpp
      {
      public:
	enum { ONE_DIM = 9, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
      };
      class NumPiecesBetweenBishopAndKingAll
      {
      public:
	enum { ONE_DIM = 9, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
      };
      class BishopBishopPiece
      {
      public:
	enum { ONE_DIM = 64, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static int index(Ptype ptype, bool self_with_support,
			 bool opp_with_support)
	{
	  return ptype + PTYPE_SIZE * ((self_with_support ? 1 : 0) +
				       2 * (opp_with_support ? 1 : 0));
	}
	static CArray<MultiInt, 64> table;
      };

      class RookRook
      {
      public:
	enum { ONE_DIM = 800, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	template <bool SamePlayer, Player P>
	static int index(Piece rook1, Piece rook2)
	{
	  const int y1 = (rook1.isOnBoard() ? rook1.square().y() : 0);
	  const int y2 = (rook2.isOnBoard() ? rook2.square().y() : 0);
	  if (SamePlayer)
	  {
	    if (P == BLACK)
	    {
	      return y1 + 10 *
		(y2 + 10 * ((rook1.isPromoted() ? 1 : 0) + 2 *
			    ((rook2.isPromoted() ? 1 : 0) + 2 *
			     (SamePlayer ? 1 : 0))));
	    }
	    else
	    {
	      if (y1 == 0 || y2 == 0 || y1 == y2)
	      {
		return (10 - y1) % 10 + 10 *
		  ((10 - y2) % 10 + 10 * ((rook1.isPromoted() ? 1 : 0) + 2 *
					  ((rook2.isPromoted() ? 1 : 0) + 2 *
					   (SamePlayer ? 1 : 0))));
	      }
	      else
	      {
		return (10 - y2) % 10 + 10 *
		  ((10 - y1) % 10 + 10 * ((rook2.isPromoted() ? 1 : 0) + 2 *
					  ((rook1.isPromoted() ? 1 : 0) + 2 *
					   (SamePlayer ? 1 : 0))));
	      }
	    }
	  }
	  else
	  {
	    return y1 + 10 *
	      (y2 + 10 * ((rook1.isPromoted() ? 1 : 0) + 2 *
			  ((rook2.isPromoted() ? 1 : 0) + 2 *
			   (SamePlayer ? 1 : 0))));
	  }
	}
	static int index(bool same_player, bool promoted1,
			 bool promoted2, int y1, int y2)
	{
	  return y1 + 10 *
	    (y2 + 10 * ((promoted1 ? 1 : 0) + 2 *
			((promoted2 ? 1 : 0) + 2 *
			 (same_player ? 1 : 0))));
	}
	static CArray<MultiInt, 800> table;
      };

      class RookRookPiece
      {
      public:
	enum { ONE_DIM = 128, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static int index(Ptype ptype, bool self_with_support,
			 bool opp_with_support, bool vertical)
	{
	  return ptype + PTYPE_SIZE * ((self_with_support ? 1 : 0) +
				       2 * (opp_with_support ? 1 : 0)) +
	    (vertical ? PTYPE_SIZE * 2 * 2 : 0);
	}
	static CArray<MultiInt, 128> table;
      };

      class BishopStandFile5
      {
      public:
	enum { ONE_DIM = 32, DIM = ONE_DIM * EvalStages };
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static CArray<MultiInt, 32> table;
      };

      class MajorCheckWithCapture
      {
      public:
	enum {
	  ONE_DIM = PTYPE_SIZE * 2/*bishop or rook*/ * 2 /*promotable*/,
	  DIM = ONE_DIM * EvalStages
	};
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static CArray<MultiInt, ONE_DIM> table;	
	template <Player Owner>
	static MultiInt addOne(const NumEffectState &state);
	static size_t index(Ptype ptype, bool is_rook, bool can_promote) 
	{
	  return ptype * 4 + is_rook * 2 + can_promote;
	}
      };

      class RookSilverKnight
      {
      public:
	enum {
	  ONE_DIM = 5 * 9 * 9 * 9 * 9 * 9,
	  DIM = ONE_DIM * EvalStages
	};
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static CArray<MultiInt, ONE_DIM> table;	
	static size_t index(int rook_x, int rook_y, int silver_x, int silver_y,
			    int knight_x, int knight_y)
	{
	  return knight_y + 9 * (knight_x + 9 * (silver_y + 9 * (silver_x + 9 * (rook_y + 9 * rook_x))));
	}
      };

      class BishopSilverKnight
      {
      public:
	enum {
	  ONE_DIM = 5 * 9 * 9 * 9 * 9 * 9,
	  DIM = ONE_DIM * EvalStages
	};
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static CArray<MultiInt, ONE_DIM> table;	
	static size_t index(int bishop_x, int bishop_y, int silver_x, int silver_y,
			    int knight_x, int knight_y)
	{
	  return knight_y + 9 * (knight_x + 9 * (silver_y + 9 * (silver_x + 9 * (bishop_y + 9 * bishop_x))));
	}
      };

      class AttackMajorsInBase
      {
      public:
	enum {
	  ONE_DIM = PTYPE_SIZE * PTYPE_SIZE * 2 * 2 * 2,
	  DIM = ONE_DIM * EvalStages
	};
	static void setUp(const Weights &weights);
	static MultiInt eval(const NumEffectState &state);
      private:
	static CArray<MultiInt, ONE_DIM> table;	
	size_t maxActive() const { return 4; }
	static int index(Ptype support, Ptype attack, bool has_gold, 
			 bool rook_support, bool bishop_support)
	{
	  return (unpromoteSafe(support)*16 + unpromoteSafe(attack))*8+has_gold*4
	    +rook_support*2+bishop_support;
	}
	template <Player Owner>
	static void addOne(const NumEffectState &state, Piece rook, MultiInt&);
      };
    }
  }
}

#endif // EVAL_ML_MAJORPIECE_H
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End: