5 #include <boost/scoped_ptr.hpp>
25 using namespace osl::eval;
30 cerr <<
"Usage: " << prog <<
" [-f read-pair-file-name] [-o write-pair-file-name] "
37 void adjust(PiecePairRawTable& table,
44 const unsigned int index1 = table.indexOf(pos1, ptypeo1);
45 const unsigned int index2 = table.indexOf(pos2, ptypeo2);
47 int val = table.valueOf(index1, index2);
48 assert(val == table.valueOf(index2, index1));
50 std::cerr << pos1 << ptypeo1 <<
" " << pos2 << ptypeo2
51 <<
" " << val <<
" => ";
56 std::cerr << val <<
"\n";
57 table.valueOf(index1, index2) = val;
58 table.valueOf(index2, index1) = val;
71 adjust(table, pos1, ptypeo1, pos2, ptypeo2, bonus);
77 int blackAttackBonus,
int whiteAttackBonus)
105 adjust(table, pos1, ptypeo1, pos2, ptypeo2, bonus);
114 addValue(player, table, pos1, ptype1, pos2, ptype2, bonus);
123 addValue(player, table, pos1, ptype1, pos2, ptype2, bonus);
131 assert(black_bonus < 0);
144 int main(
int argc,
char **argv)
146 const char *program_name = argv[0];
147 bool error_flag =
false;
148 const char *read_pairfilename = 0;
149 const char *write_pairfilename = 0;
154 while ((c = getopt(argc, argv,
"f:o:vh")) != EOF)
158 case 'f': read_pairfilename = optarg;
160 case 'o': write_pairfilename = optarg;
164 default: error_flag =
true;
170 if (error_flag || (! read_pairfilename) || (! write_pairfilename))
173 boost::scoped_ptr<PiecePairRawTable> table(
new PiecePairRawTable);
174 table->loadFromBinaryFile(read_pairfilename);
177 CArray2d<bool,Square::SIZE,Square::SIZE> adjusted;
178 adjusted.fill(
false);
179 for (
int king_x=1; king_x<=9; ++king_x)
181 for (
int king_y=1; king_y<=9; ++king_y)
183 const Square king(king_x,king_y);
184 for (
int attacker_x = ((king_x==9) ? king_x-3 : king_x-2);
185 attacker_x <= ((king_x==1) ? king_x+3 : king_x+2); ++attacker_x)
187 if ((attacker_x < 1) || (attacker_x > 9))
189 for (
int attacker_y = ((king_y==9) ? king_y-3 : king_y-2);
190 attacker_y <= ((king_y==1) ? king_y+3 : king_y+2); ++attacker_y)
192 if ((attacker_y < 1) || (attacker_y > 9))
194 const Square attacker(attacker_x,attacker_y);
195 if (king == attacker)
197 adjusted[king.
index()][attacker.
index()] =
true;
211 (attacker_y >= king_y) ? 100 : 50;
222 (attacker_y <= king_y) ? -100 : -50;
231 if (attacker_y >= king_y)
237 if (attacker_y <= king_y)
245 for (
int attacker_y = ((king_y==9) ? king_y-4 : king_y-3);
246 attacker_y <= ((king_y==1) ? king_y+4 : king_y+3); ++attacker_y)
248 if ((attacker_y < 1) || (attacker_y > 9))
250 const Square attacker(attacker_x,attacker_y);
251 if (king == attacker)
255 if (! ((attacker_y == 5)
256 && ((attacker_x == 2)
259 || (attacker_x == 8))))
261 if ((attacker_y > king_y) && (attacker_y > 2))
270 if ((attacker_y < king_y) && (attacker_y < 8))
285 for (
int king_x=1; king_x<=9; ++king_x)
287 for (
int king_y=1; king_y<=3; ++king_y)
289 const Square king(king_x,king_y);
290 for (
int rook_x=1; rook_x<=9; ++rook_x)
292 for (
int rook_y=king_y-1; rook_y<=king_y+1; ++rook_y)
294 if ((rook_y < 1) || (rook_y > 9))
296 const Square rook(rook_x, rook_y);
306 for (
int attacker_x = ((king_x==9) ? king_x-4 : king_x-3);
307 attacker_x <= ((king_x==1) ? king_x+4 : king_x+3); ++attacker_x)
309 if ((attacker_x < 1) || (attacker_x > 9))
311 for (
int attacker_y = king_y; attacker_y <= ((king_y==1) ? king_y+3 : king_y+2); ++attacker_y)
313 if ((attacker_y < 1) || (attacker_y > 9))
315 const Square attacker(attacker_x,attacker_y);
316 if (king == attacker)
320 adjusted[king.
index()][attacker.
index()] =
true;
330 for (
int king_x=1; king_x<=9; ++king_x)
332 for (
int king_y=1; king_y<=3; ++king_y)
334 const Square king(king_x,king_y);
335 for (
int attacker_x = ((king_x==9) ? king_x-5 : king_x-4);
336 attacker_x <= ((king_x==1) ? king_x+5 : king_x+4); ++attacker_x)
338 if ((attacker_x < 1) || (attacker_x > 9))
340 for (
int attacker_y = king_y+1; attacker_y <= ((king_y==1) ? king_y+3 : king_y+2); ++attacker_y)
342 if ((attacker_y < 1) || (attacker_y > 9))
344 const Square attacker(attacker_x,attacker_y);
345 if (king == attacker)
357 for (
int attacker_x=1; attacker_x<=9; ++attacker_x)
359 for (
int attacker_y=1; attacker_y<=9; ++attacker_y)
361 const Square attacker(attacker_x,attacker_y);
363 if ((attacker_x == 1) || (attacker_x == 9))
415 for (
int x=2; x<=8; ++x)
418 const Square attacker(x,5);
429 for (
int promoted_x=1; promoted_x<=9; ++promoted_x)
431 for (
int x=1; x<=9; ++x)
433 for (
int promoted_y=1; promoted_y<=3; ++promoted_y)
435 const Square promoted(promoted_x, promoted_y);
436 for (
int y=1; y<=3; ++y)
438 const Square unpromoted(x, y);
439 if (promoted == unpromoted)
451 for (
int promoted_y=7; promoted_y<=9; ++promoted_y)
453 const Square promoted(promoted_x, promoted_y);
454 for (
int y=7; y<=9; ++y)
456 const Square unpromoted(x, y);
457 if (promoted == unpromoted)
472 for (
int x=1; x<=9; ++x)
475 const Square black_position(x,4);
476 const Square white_position(x,6);
481 for (
int x=1; x<=9; ++x)
487 if (x == 1 || x == 3 || x == 7 || x == 9)
493 for (
int i=x-1; i<=x+1; ++i)
503 for (
int y=7; y<=9; ++y)
543 for (
int x=1; x<=9; ++x)
545 for (
int y=8; y<=9; ++y)
547 const Square bishop(x, y);
550 const Square ul(x+1, y-1);
557 const Square ur(x-1, y-1);
566 const CArray<Ptype, 6> types =
568 for (
int x1=1; x1<=9; ++x1)
570 for (
int x2=x1; x2<=9; ++x2)
572 const int xdiff = abs(x1 - x2);
575 for (
int y1=1; y1<=3; ++y1)
578 for (
int y2=y1; y2<=3; ++y2)
580 if (x1 == x2 && y1 == y2)
583 const int py = (3-
std::min(y1, y2))*10;
585 const int p = 0-py-center*15;
588 for (
int t1=0; t1<(int)types.size(); ++t1)
591 if (y1 < 3 && types[t1] ==
KNIGHT)
593 if (y1 == 1 && (types[t1] ==
LANCE || types[t1] ==
PAWN))
595 for (
int t2=0; t2<(int)types.size(); ++t2)
597 if (y2 < 3 && types[t2] ==
KNIGHT)
599 if (y2 == 1 && (types[t2] ==
LANCE || types[t2] ==
PAWN))
612 for (
int x=1; x<=9; ++x)
614 for (
int y=5; y<=7; ++y)
617 for (
int ry=6; ry<=9; ++ry)
622 const int p = -y*10-25;
631 for (
int x=1; x<=9; ++x)
633 for (
int y=3; y<=7; ++y)
636 for (
int ry=1; ry<y; ++ry)
646 for (
int x=1; x<=9; ++x)
648 for (
int y=8; y<=9; ++y)
657 for (
int kx=1; kx<=9; ++kx)
659 for (
int ky=7; ky<=9; ++ky)
665 const int penalty = -(8-abs(kx-x))*10;
681 table->writeInBinaryFile(write_pairfilename);