00001
00002
00003
00004 #include "osl/eval/ppair/piecePairRawEval.h"
00005 #include <boost/scoped_ptr.hpp>
00006 #include <iostream>
00007 #include <cstdlib>
00008 #include <unistd.h>
00009
00023 using namespace osl;
00024 using namespace osl::eval;
00025
00026 void usage(const char *prog)
00027 {
00028 using namespace std;
00029 cerr << "Usage: " << prog << " [-f read-pair-file-name] [-o write-pair-file-name] "
00030 << endl;
00031 exit(1);
00032 }
00033
00034 bool verbose = false;
00035
00036 void adjust(PiecePairRawTable& table,
00037 Position pos1, PtypeO ptypeo1,
00038 Position pos2, PtypeO ptypeo2,
00039 int value)
00040 {
00041 assert(pos1.isOnBoard());
00042 assert(pos2.isOnBoard());
00043 const unsigned int index1 = table.indexOf(pos1, ptypeo1);
00044 const unsigned int index2 = table.indexOf(pos2, ptypeo2);
00045
00046 int val = table.valueOf(index1, index2);
00047 assert(val == table.valueOf(index2, index1));
00048 if (verbose)
00049 std::cerr << pos1 << ptypeo1 << " " << pos2 << ptypeo2
00050 << " " << val << " => ";
00051 val += value;
00052 val = std::min(127, val);
00053 val = std::max(-127, val);
00054 if (verbose)
00055 std::cerr << val << "\n";
00056 table.valueOf(index1, index2) = val;
00057 table.valueOf(index2, index1) = val;
00058 }
00059
00060 void adjustKingBonus(PiecePairRawTable& table,
00061 Position pos1, PtypeO ptypeo1,
00062 Position pos2, PtypeO ptypeo2,
00063 int bonus)
00064 {
00065 assert(getPtype(ptypeo1) == KING);
00066 assert(getPtype(ptypeo2) != KING);
00067 assert(getOwner(ptypeo1) != getOwner(ptypeo2));
00068 assert((bonus > 0) ^ (getOwner(ptypeo1) == BLACK));
00069
00070 adjust(table, pos1, ptypeo1, pos2, ptypeo2, bonus);
00071 }
00072
00074 void adjustDual(PiecePairRawTable& table,
00075 Position king, Position attacker, Ptype attackerType,
00076 int blackAttackBonus, int whiteAttackBonus)
00077 {
00078 adjustKingBonus(table, king.rotate180(), newPtypeO(BLACK, KING),
00079 attacker.rotate180(), newPtypeO(WHITE, attackerType),
00080 whiteAttackBonus);
00081 adjustKingBonus(table, king, newPtypeO(WHITE, KING),
00082 attacker, newPtypeO(BLACK, attackerType),
00083 blackAttackBonus);
00084 }
00085
00086 void adjustDual(PiecePairRawTable& table,
00087 Position black, Ptype black_ptype,
00088 Position white, Ptype white_ptype,
00089 int value)
00090 {
00091 adjust(table, black, newPtypeO(BLACK, black_ptype),
00092 white, newPtypeO(WHITE, white_ptype), value);
00093 adjust(table, black.rotate180(), newPtypeO(WHITE, black_ptype),
00094 white.rotate180(), newPtypeO(BLACK, white_ptype), -value);
00095 }
00096
00097 void addValue(Player player, PiecePairRawTable& table,
00098 Position pos1, Ptype ptype1,
00099 Position pos2, Ptype ptype2,
00100 int bonus)
00101 {
00102 const PtypeO ptypeo1 = newPtypeO(player, ptype1);
00103 const PtypeO ptypeo2 = newPtypeO(player, ptype2);
00104 adjust(table, pos1, ptypeo1, pos2, ptypeo2, bonus);
00105 }
00106
00107 void addPenalty(Player player, PiecePairRawTable& table,
00108 Position pos1, Ptype ptype1,
00109 Position pos2, Ptype ptype2,
00110 int bonus)
00111 {
00112 assert(eval::betterThan(player, 0, bonus));
00113 addValue(player, table, pos1, ptype1, pos2, ptype2, bonus);
00114 }
00115
00116 void addBonus(Player player, PiecePairRawTable& table,
00117 Position pos1, Ptype ptype1,
00118 Position pos2, Ptype ptype2,
00119 int bonus)
00120 {
00121 assert(eval::betterThan(player, bonus, 0));
00122 addValue(player, table, pos1, ptype1, pos2, ptype2, bonus);
00123 }
00124
00125 void addPenaltyDual(PiecePairRawTable& table,
00126 Position pos1, Ptype ptype1,
00127 Position pos2, Ptype ptype2,
00128 int black_bonus)
00129 {
00130 assert(black_bonus < 0);
00131 addPenalty(BLACK, table, pos1, ptype1, pos2, ptype2, black_bonus);
00132 addPenalty(WHITE, table, pos1, ptype1, pos2, ptype2, -black_bonus);
00133 }
00134
00135 void addSelfPenaltyDual(PiecePairRawTable& table,
00136 Position pos, Ptype ptype,
00137 int black_bonus)
00138 {
00139 addPenaltyDual(table, pos, ptype, pos, ptype, black_bonus);
00140 }
00141
00142
00143 int main(int argc, char **argv)
00144 {
00145 const char *program_name = argv[0];
00146 bool error_flag = false;
00147 const char *read_pairfilename = 0;
00148 const char *write_pairfilename = 0;
00149
00150 extern char *optarg;
00151 extern int optind;
00152 char c;
00153 while ((c = getopt(argc, argv, "f:o:vh")) != EOF)
00154 {
00155 switch(c)
00156 {
00157 case 'f': read_pairfilename = optarg;
00158 break;
00159 case 'o': write_pairfilename = optarg;
00160 break;
00161 case 'v': verbose = true;
00162 break;
00163 default: error_flag = true;
00164 }
00165 }
00166 argc -= optind;
00167 argv += optind;
00168
00169 if (error_flag || (! read_pairfilename) || (! write_pairfilename))
00170 usage(program_name);
00171
00172 boost::scoped_ptr<PiecePairRawTable> table(new PiecePairRawTable);
00173 table->loadFromBinaryFile(read_pairfilename);
00174
00175
00176 CArray2d<bool,Position::SIZE,Position::SIZE> adjusted;
00177 adjusted.fill(false);
00178 for (int king_x=1; king_x<=9; ++king_x)
00179 {
00180 for (int king_y=1; king_y<=9; ++king_y)
00181 {
00182 const Position king(king_x,king_y);
00183 for (int attacker_x = ((king_x==9) ? king_x-3 : king_x-2);
00184 attacker_x <= ((king_x==1) ? king_x+3 : king_x+2); ++attacker_x)
00185 {
00186 if ((attacker_x < 1) || (attacker_x > 9))
00187 continue;
00188 for (int attacker_y = ((king_y==9) ? king_y-3 : king_y-2);
00189 attacker_y <= ((king_y==1) ? king_y+3 : king_y+2); ++attacker_y)
00190 {
00191 if ((attacker_y < 1) || (attacker_y > 9))
00192 continue;
00193 const Position attacker(attacker_x,attacker_y);
00194 if (king == attacker)
00195 continue;
00196 adjusted[king.index()][attacker.index()] = true;
00197 adjustDual(*table, king, attacker, PPAWN, 100, -100);
00198 adjustDual(*table, king, attacker, PLANCE, 100, -100);
00199 adjustDual(*table, king, attacker, PKNIGHT, 100, -100);
00200 adjustDual(*table, king, attacker, PBISHOP, 100, -100);
00201 adjustDual(*table, king, attacker, PROOK, 100, -100);
00202 adjustDual(*table, king, attacker, SILVER, 100, -100);
00203 adjustDual(*table, king, attacker, BISHOP, 100, -100);
00204 adjustDual(*table, king, attacker, ROOK, 100, -100);
00205
00206
00207 if (attacker_y != 1)
00208 {
00209 const int bonus =
00210 (attacker_y >= king_y) ? 100 : 50;
00211 adjustKingBonus(*table, king, newPtypeO(WHITE, KING),
00212 attacker, newPtypeO(BLACK, PSILVER),
00213 bonus);
00214 adjustKingBonus(*table, king, newPtypeO(WHITE, KING),
00215 attacker, newPtypeO(BLACK, GOLD),
00216 bonus);
00217 }
00218 if (attacker_y != 9)
00219 {
00220 const int bonus =
00221 (attacker_y <= king_y) ? -100 : -50;
00222 adjustKingBonus(*table, king, newPtypeO(BLACK, KING),
00223 attacker, newPtypeO(WHITE, PSILVER),
00224 bonus);
00225 adjustKingBonus(*table, king, newPtypeO(BLACK, KING),
00226 attacker, newPtypeO(WHITE, GOLD),
00227 bonus);
00228 }
00229
00230 if (attacker_y >= king_y)
00231 {
00232 adjustKingBonus(*table, king, newPtypeO(WHITE, KING),
00233 attacker, newPtypeO(BLACK, PAWN),
00234 100);
00235 }
00236 if (attacker_y <= king_y)
00237 {
00238 adjustKingBonus(*table, king, newPtypeO(BLACK, KING),
00239 attacker, newPtypeO(WHITE, PAWN),
00240 -100);
00241 }
00242 }
00243
00244 for (int attacker_y = ((king_y==9) ? king_y-4 : king_y-3);
00245 attacker_y <= ((king_y==1) ? king_y+4 : king_y+3); ++attacker_y)
00246 {
00247 if ((attacker_y < 1) || (attacker_y > 9))
00248 continue;
00249 const Position attacker(attacker_x,attacker_y);
00250 if (king == attacker)
00251 continue;
00252
00253
00254 if (! ((attacker_y == 5)
00255 && ((attacker_x == 2)
00256 || (attacker_x == 4)
00257 || (attacker_x == 6)
00258 || (attacker_x == 8))))
00259 {
00260 if ((attacker_y > king_y) && (attacker_y > 2))
00261 {
00262 adjustKingBonus(*table, king, newPtypeO(WHITE, KING),
00263 attacker, newPtypeO(BLACK, LANCE),
00264 100);
00265 adjustKingBonus(*table, king, newPtypeO(WHITE, KING),
00266 attacker, newPtypeO(BLACK, KNIGHT),
00267 100);
00268 }
00269 if ((attacker_y < king_y) && (attacker_y < 8))
00270 {
00271 adjustKingBonus(*table, king, newPtypeO(BLACK, KING),
00272 attacker, newPtypeO(WHITE, LANCE),
00273 -100);
00274 adjustKingBonus(*table, king, newPtypeO(BLACK, KING),
00275 attacker, newPtypeO(WHITE, KNIGHT),
00276 -100);
00277 }
00278 }
00279 }
00280 }
00281 }
00282 }
00283
00284 for (int king_x=1; king_x<=9; ++king_x)
00285 {
00286 for (int king_y=1; king_y<=3; ++king_y)
00287 {
00288 const Position king(king_x,king_y);
00289 for (int rook_x=1; rook_x<=9; ++rook_x)
00290 {
00291 for (int rook_y=king_y-1; rook_y<=king_y+1; ++rook_y)
00292 {
00293 if ((rook_y < 1) || (rook_y > 9))
00294 continue;
00295 const Position rook(rook_x, rook_y);
00296 if (king == rook)
00297 continue;
00298 if (! adjusted[king.index()][rook.index()])
00299 {
00300 adjustDual(*table, king, rook, ROOK, 30, -30);
00301 adjustDual(*table, king, rook, PROOK, 30, -30);
00302 }
00303 }
00304 }
00305 for (int attacker_x = ((king_x==9) ? king_x-4 : king_x-3);
00306 attacker_x <= ((king_x==1) ? king_x+4 : king_x+3); ++attacker_x)
00307 {
00308 if ((attacker_x < 1) || (attacker_x > 9))
00309 continue;
00310 for (int attacker_y = king_y; attacker_y <= ((king_y==1) ? king_y+3 : king_y+2); ++attacker_y)
00311 {
00312 if ((attacker_y < 1) || (attacker_y > 9))
00313 continue;
00314 const Position attacker(attacker_x,attacker_y);
00315 if (king == attacker)
00316 continue;
00317 if (adjusted[king.index()][attacker.index()])
00318 continue;
00319 adjusted[king.index()][attacker.index()] = true;
00320 adjustDual(*table, king, attacker, PPAWN, 40, -40);
00321 adjustDual(*table, king, attacker, PLANCE, 40, -40);
00322 adjustDual(*table, king, attacker, PKNIGHT, 40, -40);
00323 adjustDual(*table, king, attacker, SILVER, 40, -40);
00324 }
00325 }
00326 }
00327 }
00328
00329 for (int king_x=1; king_x<=9; ++king_x)
00330 {
00331 for (int king_y=1; king_y<=3; ++king_y)
00332 {
00333 const Position king(king_x,king_y);
00334 for (int attacker_x = ((king_x==9) ? king_x-5 : king_x-4);
00335 attacker_x <= ((king_x==1) ? king_x+5 : king_x+4); ++attacker_x)
00336 {
00337 if ((attacker_x < 1) || (attacker_x > 9))
00338 continue;
00339 for (int attacker_y = king_y+1; attacker_y <= ((king_y==1) ? king_y+3 : king_y+2); ++attacker_y)
00340 {
00341 if ((attacker_y < 1) || (attacker_y > 9))
00342 continue;
00343 const Position attacker(attacker_x,attacker_y);
00344 if (king == attacker)
00345 continue;
00346 if (adjusted[king.index()][attacker.index()])
00347 continue;
00348 adjustDual(*table, king, attacker, PPAWN, 10, -10);
00349 adjustDual(*table, king, attacker, PLANCE, 10, -10);
00350 adjustDual(*table, king, attacker, PKNIGHT, 10, -10);
00351 adjustDual(*table, king, attacker, SILVER, 10, -10);
00352 }
00353 }
00354 }
00355 }
00356 for (int attacker_x=1; attacker_x<=9; ++attacker_x)
00357 {
00358 for (int attacker_y=1; attacker_y<=9; ++attacker_y)
00359 {
00360 const Position attacker(attacker_x,attacker_y);
00361
00362 if ((attacker_x == 1) || (attacker_x == 9))
00363 {
00364 addSelfPenaltyDual(*table, attacker, KNIGHT, -100);
00365 addSelfPenaltyDual(*table, attacker, SILVER, -100);
00366 addSelfPenaltyDual(*table, attacker, GOLD , -100);
00367 addSelfPenaltyDual(*table, attacker, PPAWN , -100);
00368 addSelfPenaltyDual(*table, attacker, PLANCE, -100);
00369 addSelfPenaltyDual(*table, attacker, PKNIGHT, -100);
00370 addSelfPenaltyDual(*table, attacker, PSILVER, -100);
00371 }
00372 }
00373 }
00374
00375 addPenalty(BLACK, *table, Position(2,6), SILVER, Position(3,7), KNIGHT, -80);
00376 addPenalty(WHITE, *table, Position(8,4), SILVER, Position(7,3), KNIGHT, +80);
00377
00378 addPenalty(BLACK, *table, Position(2,6), SILVER, Position(1,5), PAWN, -80);
00379 addPenalty(WHITE, *table, Position(8,4), SILVER, Position(9,5), PAWN, +80);
00380
00381 addPenalty(BLACK, *table, Position(9,7), SILVER, Position(8,8), BISHOP, -80);
00382 addPenalty(BLACK, *table, Position(1,7), SILVER, Position(2,8), BISHOP, -80);
00383 addPenalty(WHITE, *table, Position(9,3), SILVER, Position(8,2), BISHOP, +80);
00384 addPenalty(WHITE, *table, Position(1,3), SILVER, Position(2,2), BISHOP, +80);
00385
00386
00387 addPenalty(BLACK, *table, Position(9,9), KING, Position(7,7), KNIGHT, -120);
00388 addPenalty(BLACK, *table, Position(9,9), KING, Position(9,7), KNIGHT, -120);
00389 addPenalty(BLACK, *table, Position(1,9), KING, Position(3,7), KNIGHT, -120);
00390 addPenalty(BLACK, *table, Position(1,9), KING, Position(1,7), KNIGHT, -120);
00391 addPenalty(WHITE, *table, Position(9,1), KING, Position(7,3), KNIGHT, +120);
00392 addPenalty(WHITE, *table, Position(9,1), KING, Position(9,3), KNIGHT, +120);
00393 addPenalty(WHITE, *table, Position(1,1), KING, Position(3,3), KNIGHT, +120);
00394 addPenalty(WHITE, *table, Position(1,1), KING, Position(1,3), KNIGHT, +120);
00395
00396
00397 addPenalty(BLACK, *table, Position(9,9), KING, Position(9,9), KING, -120);
00398 addBonus(BLACK, *table, Position(9,9), KING, Position(9,8), LANCE, 40);
00399 addBonus(BLACK, *table, Position(9,9), KING, Position(8,9), KNIGHT, 80);
00400
00401 addPenalty(BLACK, *table, Position(1,9), KING, Position(1,9), KING, -120);
00402 addBonus(BLACK, *table, Position(1,9), KING, Position(1,8), LANCE, 40);
00403 addBonus(BLACK, *table, Position(1,9), KING, Position(2,9), KNIGHT, 80);
00404
00405 addPenalty(WHITE, *table, Position(9,1), KING, Position(9,1), KING, +120);
00406 addBonus(WHITE, *table, Position(9,1), KING, Position(9,2), LANCE, -40);
00407 addBonus(WHITE, *table, Position(9,1), KING, Position(8,1), KNIGHT, -80);
00408
00409 addPenalty(WHITE, *table, Position(1,1), KING, Position(1,1), KING, +120);
00410 addBonus(WHITE, *table, Position(1,1), KING, Position(1,2), LANCE, -40);
00411 addBonus(WHITE, *table, Position(1,1), KING, Position(2,1), KNIGHT, -80);
00412
00413
00414 for (int x=2; x<=8; ++x)
00415 {
00416
00417 const Position attacker(x,5);
00418 addSelfPenaltyDual(*table, attacker, KNIGHT, -100);
00419
00420
00421 adjust(*table, Position(x,1), newPtypeO(WHITE,PAWN), attacker, newPtypeO(BLACK,KNIGHT), 100);
00422 adjust(*table, Position(x,2), newPtypeO(WHITE,PAWN), attacker, newPtypeO(BLACK,KNIGHT), 100);
00423 adjust(*table, Position(x,9), newPtypeO(BLACK,PAWN), attacker, newPtypeO(WHITE,KNIGHT), -100);
00424 adjust(*table, Position(x,8), newPtypeO(BLACK,PAWN), attacker, newPtypeO(WHITE,KNIGHT), -100);
00425 }
00426
00427
00428 for (int promoted_x=1; promoted_x<=9; ++promoted_x)
00429 {
00430 for (int x=1; x<=9; ++x)
00431 {
00432 for (int promoted_y=1; promoted_y<=3; ++promoted_y)
00433 {
00434 const Position promoted(promoted_x, promoted_y);
00435 for (int y=1; y<=3; ++y)
00436 {
00437 const Position unpromoted(x, y);
00438 if (promoted == unpromoted)
00439 continue;
00440 adjust(*table, promoted, newPtypeO(BLACK,PROOK),
00441 unpromoted, newPtypeO(WHITE,ROOK), 100);
00442 adjust(*table, promoted, newPtypeO(BLACK,PROOK),
00443 unpromoted, newPtypeO(WHITE,BISHOP), 100);
00444 adjust(*table, promoted, newPtypeO(BLACK,PBISHOP),
00445 unpromoted, newPtypeO(WHITE,ROOK), 100);
00446 adjust(*table, promoted, newPtypeO(BLACK,PBISHOP),
00447 unpromoted, newPtypeO(WHITE,BISHOP), 100);
00448 }
00449 }
00450 for (int promoted_y=7; promoted_y<=9; ++promoted_y)
00451 {
00452 const Position promoted(promoted_x, promoted_y);
00453 for (int y=7; y<=9; ++y)
00454 {
00455 const Position unpromoted(x, y);
00456 if (promoted == unpromoted)
00457 continue;
00458 adjust(*table, promoted, newPtypeO(WHITE,PROOK),
00459 unpromoted, newPtypeO(BLACK,ROOK), -100);
00460 adjust(*table, promoted, newPtypeO(WHITE,PROOK),
00461 unpromoted, newPtypeO(BLACK,BISHOP), -100);
00462 adjust(*table, promoted, newPtypeO(WHITE,PBISHOP),
00463 unpromoted, newPtypeO(BLACK,ROOK), -100);
00464 adjust(*table, promoted, newPtypeO(WHITE,PBISHOP),
00465 unpromoted, newPtypeO(BLACK,BISHOP), -100);
00466 }
00467 }
00468 }
00469 }
00470
00471 for (int x=1; x<=9; ++x)
00472 {
00473
00474 const Position black_position(x,4);
00475 const Position white_position(x,6);
00476 addBonus(BLACK, *table, black_position, PAWN, black_position, PAWN, 100);
00477 addBonus(WHITE, *table, white_position, PAWN, white_position, PAWN,-100);
00478 }
00479
00480 for (int x=1; x<=9; ++x)
00481 {
00482
00483 addPenalty(BLACK, *table, Position(x,6), ROOK, Position(x,7), PAWN, -95);
00484 addPenalty(WHITE, *table, Position(x,4), ROOK, Position(x,3), PAWN, +95);
00485
00486 if (x == 1 || x == 3 || x == 7 || x == 9)
00487 {
00488 addPenalty(BLACK, *table, Position(x,6), SILVER, Position(x,7), PAWN, -80);
00489 addPenalty(WHITE, *table, Position(x,4), SILVER, Position(x,3), PAWN, +80);
00490 }
00491
00492 for (int i=x-1; i<=x+1; ++i)
00493 {
00494 if (i<1 || i > 9)
00495 continue;
00496 addPenalty(BLACK, *table, Position(x,6), ROOK, Position(i,8), KING, -100);
00497 addPenalty(BLACK, *table, Position(x,6), ROOK, Position(i,9), KING, -90);
00498 addPenalty(WHITE, *table, Position(x,4), ROOK, Position(i,2), KING, +100);
00499 addPenalty(WHITE, *table, Position(x,4), ROOK, Position(i,1), KING, +90);
00500 }
00501
00502 for (int y=7; y<=9; ++y)
00503 {
00504 const int wy = 10-y;
00505 addPenalty(BLACK, *table, Position(x,y), KING, Position(x,y-1), ROOK, -70);
00506 addPenalty(BLACK, *table, Position(x,y-1), KING, Position(x,y), ROOK, -70);
00507 addPenalty(WHITE, *table, Position(x,wy), KING, Position(x,wy+1), ROOK, +70);
00508 addPenalty(WHITE, *table, Position(x,wy+1), KING, Position(x,wy), ROOK, +70);
00509 if (x > 1)
00510 {
00511 addPenalty(BLACK, *table, Position(x,y), KING, Position(x-1,y), ROOK, -70);
00512 addPenalty(WHITE, *table, Position(x,wy), KING, Position(x-1,wy), ROOK, +70);
00513 }
00514 if (x > 2)
00515 {
00516 addPenalty(BLACK, *table, Position(x,y), KING, Position(x-2,y), ROOK, -50);
00517 addPenalty(WHITE, *table, Position(x,wy), KING, Position(x-2,wy), ROOK, +50);
00518 }
00519 if (x < 9)
00520 {
00521 addPenalty(BLACK, *table, Position(x,y), KING, Position(x+1,y), ROOK, -70);
00522 addPenalty(WHITE, *table, Position(x,wy), KING, Position(x+1,wy), ROOK, +70);
00523 }
00524 if (x < 8)
00525 {
00526 addPenalty(BLACK, *table, Position(x,y), KING, Position(x+2,y), ROOK, -50);
00527 addPenalty(WHITE, *table, Position(x,wy), KING, Position(x+2,wy), ROOK, +50);
00528 }
00529 }
00530 }
00531
00532
00533 addPenalty(BLACK, *table, Position(1,7), ROOK, Position(2,9), KNIGHT, -70);
00534 addPenalty(BLACK, *table, Position(3,7), ROOK, Position(2,9), KNIGHT, -70);
00535 addPenalty(BLACK, *table, Position(7,7), ROOK, Position(8,9), KNIGHT, -70);
00536 addPenalty(BLACK, *table, Position(9,7), ROOK, Position(8,9), KNIGHT, -70);
00537 addPenalty(WHITE, *table, Position(1,3), ROOK, Position(2,1), KNIGHT, +70);
00538 addPenalty(WHITE, *table, Position(3,3), ROOK, Position(2,1), KNIGHT, +70);
00539 addPenalty(WHITE, *table, Position(7,3), ROOK, Position(8,1), KNIGHT, +70);
00540 addPenalty(WHITE, *table, Position(9,3), ROOK, Position(8,1), KNIGHT, +70);
00541
00542 for (int x=1; x<=9; ++x)
00543 {
00544 for (int y=8; y<=9; ++y)
00545 {
00546 const Position bishop(x, y);
00547 if (x < 9)
00548 {
00549 const Position ul(x+1, y-1);
00550 addPenalty(BLACK, *table, bishop, BISHOP, ul, GOLD, -65);
00551 addPenalty(WHITE, *table, bishop.rotate180(), BISHOP,
00552 ul.rotate180(), GOLD, 65);
00553 }
00554 if (x > 1)
00555 {
00556 const Position ur(x-1, y-1);
00557 addPenalty(BLACK, *table, bishop, BISHOP, ur, GOLD, -65);
00558 addPenalty(WHITE, *table, bishop.rotate180(), BISHOP,
00559 ur.rotate180(), GOLD, 65);
00560 }
00561 }
00562 }
00563
00564
00565 const CArray<Ptype, 6> types =
00566 {{ LANCE, KNIGHT, PPAWN, PLANCE, PKNIGHT, PSILVER }};
00567 for (int x1=1; x1<=9; ++x1)
00568 {
00569 for (int x2=x1; x2<=9; ++x2)
00570 {
00571 const int xdiff = abs(x1 - x2);
00572 if (xdiff > 2)
00573 continue;
00574 for (int y1=1; y1<=3; ++y1)
00575 {
00576 const Position p1(x1,y1);
00577 for (int y2=y1; y2<=3; ++y2)
00578 {
00579 if (x1 == x2 && y1 == y2)
00580 continue;
00581 const Position p2(x2,y2);
00582 const int py = (3-std::min(y1, y2))*10;
00583 const int center = std::min(abs(5-x1), abs(5-x2));
00584 const int p = 0-py-center*15;
00585 if (p == 0)
00586 continue;
00587 for (int t1=0; t1<types.size(); ++t1)
00588 {
00589 assert(isPiece(types[t1]));
00590 if (y1 < 3 && types[t1] == KNIGHT)
00591 continue;
00592 if (y1 == 1 && (types[t1] == LANCE || types[t1] == PAWN))
00593 continue;
00594 for (int t2=0; t2<types.size(); ++t2)
00595 {
00596 if (y2 < 3 && types[t2] == KNIGHT)
00597 continue;
00598 if (y2 == 1 && (types[t2] == LANCE || types[t2] == PAWN))
00599 continue;
00600 addPenalty(BLACK, *table, p1, types[t1], p2, types[t2], p);
00601 addPenalty(WHITE, *table, p1.rotate180(), types[t1],
00602 p2.rotate180(), types[t2], -p);
00603 }
00604 }
00605 }
00606 }
00607 }
00608 }
00609
00610
00611 for (int x=1; x<=9; ++x)
00612 {
00613 for (int y=5; y<=7; ++y)
00614 {
00615 const Position pawn(x,y);
00616 for (int ry=6; ry<=9; ++ry)
00617 {
00618 if (y == ry)
00619 continue;
00620 const Position rook(x,ry);
00621 const int p = -y*10-25;
00622 addPenalty(BLACK, *table, rook, ROOK, pawn, PAWN, p);
00623 addPenalty(WHITE, *table, rook.rotate180(), ROOK,
00624 pawn.rotate180(), PAWN, -p);
00625 }
00626 }
00627 }
00628
00629
00630 for (int x=1; x<=9; ++x)
00631 {
00632 for (int y=3; y<=7; ++y)
00633 {
00634 const Position pawn(x,y);
00635 for (int ry=1; ry<y; ++ry)
00636 {
00637 const Position rook(x,ry);
00638 adjustDual(*table, pawn, PAWN, rook, ROOK, 90);
00639 adjustDual(*table, pawn, PAWN, rook, LANCE, 90);
00640 }
00641 }
00642 }
00643
00644
00645 for (int x=1; x<=9; ++x)
00646 {
00647 for (int y=8; y<=9; ++y)
00648 {
00649 const Position pawn(x,y);
00650 const Position pawn_white = pawn.rotate180();
00651 #if 0
00652 addPenalty(BLACK, *table, pawn, PAWN, pawn, PAWN, -60);
00653 addPenalty(WHITE, *table, pawn_white, PAWN, pawn_white, PAWN, 60);
00654 #endif
00655
00656 for (int kx=1; kx<=9; ++kx)
00657 {
00658 for (int ky=7; ky<=9; ++ky)
00659 {
00660 const Position king(kx,ky);
00661 const Position king_white = king.rotate180();
00662 if (king == pawn)
00663 continue;
00664 const int penalty = -(8-abs(kx-x))*10;
00665 if (penalty == 0)
00666 continue;
00667 addPenalty(BLACK, *table, pawn, PAWN, king, KING, penalty);
00668 addPenalty(WHITE, *table, pawn_white, PAWN, king_white, KING, -penalty);
00669
00670
00671 adjust(*table, pawn, newPtypeO(BLACK,PAWN),
00672 Position(kx,10-ky), newPtypeO(WHITE,KING), penalty);
00673 adjust(*table, Position(x,10-y), newPtypeO(WHITE,PAWN),
00674 king, newPtypeO(BLACK,KING), -penalty);
00675 }
00676 }
00677 }
00678 }
00679
00680 table->writeInBinaryFile(write_pairfilename);
00681 }
00682
00683
00684
00685
00686
00687
00688