Subversion Repositories Games.Chess Giants

Rev

Rev 108 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 108 Rev 154
Line 278... Line 278...
278
      }
278
      }
279
    }
279
    }
280
    maxp++;
280
    maxp++;
281
    for (i = 0; i < nmoves; i++) {
281
    for (i = 0; i < nmoves; i++) {
282
      bs_value[i] = 1;
282
      bs_value[i] = 1;
283
      bs_value[i] += bs_played[i] / (float) maxp *1000.0f * book_weight_freq; // Pierre-Marie Baty -- added type cast
283
      bs_value[i] += bs_played[i] / (float) maxp *1000.0 * book_weight_freq;
284
 
284
 
285
      if (minlv < maxlv)
285
      if (minlv < maxlv)
286
        bs_value[i] +=
286
        bs_value[i] +=
287
            (bs_learn[i] - minlv) / (float) (maxlv -
287
            (bs_learn[i] - minlv) / (float) (maxlv -
288
            minlv) * 1000.0f * book_weight_learn; // Pierre-Marie Baty -- added type cast
288
            minlv) * 1000.0 * book_weight_learn;
289
      if (minev < maxev)
289
      if (minev < maxev)
290
        bs_value[i] +=
290
        bs_value[i] +=
291
            (evaluations[i] - minev) / (float) (Max(maxev - minev,
291
            (evaluations[i] - minev) / (float) (Max(maxev - minev,
292
                50)) * 1000.0f * book_weight_eval; // Pierre-Marie Baty -- added type cast
292
                50)) * 1000.0 * book_weight_eval;
293
    }
293
    }
294
    total_played = total_moves;
294
    total_played = total_moves;
295
/*
295
/*
296
 ************************************************************
296
 ************************************************************
297
 *                                                          *
297
 *                                                          *
Line 323... Line 323...
323
        done = 1;
323
        done = 1;
324
        for (i = 0; i < nmoves - 1; i++) {
324
        for (i = 0; i < nmoves - 1; i++) {
325
          if (bs_percent[i] < bs_percent[i + 1]
325
          if (bs_percent[i] < bs_percent[i + 1]
326
              || (bs_percent[i] == bs_percent[i + 1]
326
              || (bs_percent[i] == bs_percent[i + 1]
327
                  && bs_value[i] < bs_value[i + 1])) {
327
                  && bs_value[i] < bs_value[i + 1])) {
328
            tempr = (float) bs_played[i]; // Pierre-Marie Baty -- added type cast (FIXME: ugly!)
328
            tempr = bs_played[i];
329
            bs_played[i] = bs_played[i + 1];
329
            bs_played[i] = bs_played[i + 1];
330
            bs_played[i + 1] = (int) tempr; // Pierre-Marie Baty -- added type cast (FIXME: ugly!)
330
            bs_played[i + 1] = tempr;
331
            tempr = bs_value[i];
331
            tempr = bs_value[i];
332
            bs_value[i] = bs_value[i + 1];
332
            bs_value[i] = bs_value[i + 1];
333
            bs_value[i + 1] = tempr;
333
            bs_value[i + 1] = tempr;
334
            temp = evaluations[i];
334
            temp = evaluations[i];
335
            evaluations[i] = evaluations[i + 1];
335
            evaluations[i] = evaluations[i + 1];
Line 427... Line 427...
427
    if (!play_percentage) {
427
    if (!play_percentage) {
428
      for (i = 0; i < nmoves; i++)
428
      for (i = 0; i < nmoves; i++)
429
        if (!(book_status[i] & 0x03) || bs_percent[i]) {
429
        if (!(book_status[i] & 0x03) || bs_percent[i]) {
430
          selected_status[num_selected] = book_status[i];
430
          selected_status[num_selected] = book_status[i];
431
          selected_order_played[num_selected] = bs_played[i];
431
          selected_order_played[num_selected] = bs_played[i];
432
          selected_value[num_selected] = (int) bs_value[i]; // Pierre-Marie Baty -- added type cast
432
          selected_value[num_selected] = bs_value[i];
433
          selected_percent[num_selected] = bs_percent[i];
433
          selected_percent[num_selected] = bs_percent[i];
434
          selected_key[num_selected] = book_key[i];
434
          selected_key[num_selected] = book_key[i];
435
          selected[num_selected++] = book_moves[i];
435
          selected[num_selected++] = book_moves[i];
436
        }
436
        }
437
    } else {
437
    } else {
438
      for (i = 0; i < nmoves; i++)
438
      for (i = 0; i < nmoves; i++)
439
        if (bs_percent[i]) {
439
        if (bs_percent[i]) {
440
          selected_status[num_selected] = book_status[i];
440
          selected_status[num_selected] = book_status[i];
441
          selected_order_played[num_selected] = bs_played[i];
441
          selected_order_played[num_selected] = bs_played[i];
442
          selected_value[num_selected] = (int) bs_value[i]; // Pierre-Marie Baty -- added type cast
442
          selected_value[num_selected] = bs_value[i];
443
          selected_percent[num_selected] = bs_percent[i];
443
          selected_percent[num_selected] = bs_percent[i];
444
          selected_key[num_selected] = book_key[i];
444
          selected_key[num_selected] = book_key[i];
445
          selected[num_selected++] = book_moves[i];
445
          selected[num_selected++] = book_moves[i];
446
        }
446
        }
447
    }
447
    }
448
    for (i = 0; i < num_selected; i++) {
448
    for (i = 0; i < num_selected; i++) {
449
      book_status[i] = selected_status[i];
449
      book_status[i] = selected_status[i];
450
      bs_played[i] = selected_order_played[i];
450
      bs_played[i] = selected_order_played[i];
451
      bs_value[i] = (float) selected_value[i]; // Pierre-Marie Baty -- added type cast
451
      bs_value[i] = selected_value[i];
452
      bs_percent[i] = selected_percent[i];
452
      bs_percent[i] = selected_percent[i];
453
      book_moves[i] = selected[i];
453
      book_moves[i] = selected[i];
454
    }
454
    }
455
    nmoves = num_selected;
455
    nmoves = num_selected;
456
/*
456
/*
Line 500... Line 500...
500
        for (i = 0; i < nmoves; i++)
500
        for (i = 0; i < nmoves; i++)
501
          if (book_status[i] & 16) {
501
          if (book_status[i] & 16) {
502
            forced = 1;
502
            forced = 1;
503
            selected_status[num_selected] = book_status[i];
503
            selected_status[num_selected] = book_status[i];
504
            selected_order_played[num_selected] = bs_played[i];
504
            selected_order_played[num_selected] = bs_played[i];
505
            selected_value[num_selected] = (int) bs_value[i]; // Pierre-Marie Baty -- added type cast
505
            selected_value[num_selected] = bs_value[i];
506
            selected_key[num_selected] = book_key[i];
506
            selected_key[num_selected] = book_key[i];
507
            selected[num_selected++] = book_moves[i];
507
            selected[num_selected++] = book_moves[i];
508
          }
508
          }
509
    if (!num_selected && !puzzling)
509
    if (!num_selected && !puzzling)
510
      if (book_accept_mask & 8)
510
      if (book_accept_mask & 8)
511
        for (i = 0; i < nmoves; i++)
511
        for (i = 0; i < nmoves; i++)
512
          if (book_status[i] & 8) {
512
          if (book_status[i] & 8) {
513
            forced = 1;
513
            forced = 1;
514
            selected_status[num_selected] = book_status[i];
514
            selected_status[num_selected] = book_status[i];
515
            selected_order_played[num_selected] = bs_played[i];
515
            selected_order_played[num_selected] = bs_played[i];
516
            selected_value[num_selected] = (int) bs_value[i]; // Pierre-Marie Baty -- added type cast
516
            selected_value[num_selected] = bs_value[i];
517
            selected_key[num_selected] = book_key[i];
517
            selected_key[num_selected] = book_key[i];
518
            selected[num_selected++] = book_moves[i];
518
            selected[num_selected++] = book_moves[i];
519
          }
519
          }
520
    if (!num_selected && !puzzling)
520
    if (!num_selected && !puzzling)
521
      if (book_accept_mask & 4)
521
      if (book_accept_mask & 4)
522
        for (i = 0; i < nmoves; i++)
522
        for (i = 0; i < nmoves; i++)
523
          if (book_status[i] & 4) {
523
          if (book_status[i] & 4) {
524
            selected_status[num_selected] = book_status[i];
524
            selected_status[num_selected] = book_status[i];
525
            selected_order_played[num_selected] = bs_played[i];
525
            selected_order_played[num_selected] = bs_played[i];
526
            selected_value[num_selected] = (int) bs_value[i]; // Pierre-Marie Baty -- added type cast
526
            selected_value[num_selected] = bs_value[i];
527
            selected_key[num_selected] = book_key[i];
527
            selected_key[num_selected] = book_key[i];
528
            selected[num_selected++] = book_moves[i];
528
            selected[num_selected++] = book_moves[i];
529
          }
529
          }
530
    if (!num_selected && !puzzling)
530
    if (!num_selected && !puzzling)
531
      for (i = 0; i < nmoves; i++)
531
      for (i = 0; i < nmoves; i++)
532
        if (book_status[i] & book_accept_mask) {
532
        if (book_status[i] & book_accept_mask) {
533
          selected_status[num_selected] = book_status[i];
533
          selected_status[num_selected] = book_status[i];
534
          selected_order_played[num_selected] = bs_played[i];
534
          selected_order_played[num_selected] = bs_played[i];
535
          selected_value[num_selected] = (int) bs_value[i]; // Pierre-Marie Baty -- added type cast
535
          selected_value[num_selected] = bs_value[i];
536
          selected_key[num_selected] = book_key[i];
536
          selected_key[num_selected] = book_key[i];
537
          selected[num_selected++] = book_moves[i];
537
          selected[num_selected++] = book_moves[i];
538
        }
538
        }
539
    if (!num_selected)
539
    if (!num_selected)
540
      for (i = 0; i < nmoves; i++) {
540
      for (i = 0; i < nmoves; i++) {
541
        selected_status[num_selected] = book_status[i];
541
        selected_status[num_selected] = book_status[i];
542
        selected_order_played[num_selected] = bs_played[i];
542
        selected_order_played[num_selected] = bs_played[i];
543
        selected_value[num_selected] = (int) bs_value[i]; // Pierre-Marie Baty -- added type cast
543
        selected_value[num_selected] = bs_value[i];
544
        selected_key[num_selected] = book_key[i];
544
        selected_key[num_selected] = book_key[i];
545
        selected[num_selected++] = book_moves[i];
545
        selected[num_selected++] = book_moves[i];
546
      }
546
      }
547
    if (!num_selected)
547
    if (!num_selected)
548
      return 0;
548
      return 0;
549
    for (i = 0; i < num_selected; i++) {
549
    for (i = 0; i < num_selected; i++) {
550
      book_status[i] = selected_status[i];
550
      book_status[i] = selected_status[i];
551
      book_moves[i] = selected[i];
551
      book_moves[i] = selected[i];
552
      bs_played[i] = selected_order_played[i];
552
      bs_played[i] = selected_order_played[i];
553
      bs_value[i] = (float) selected_value[i]; // Pierre-Marie Baty -- added type cast
553
      bs_value[i] = selected_value[i];
554
      bs_key[i] = selected_key[i];
554
      bs_key[i] = selected_key[i];
555
    }
555
    }
556
    nmoves = num_selected;
556
    nmoves = num_selected;
557
    if (nmoves == 0)
557
    if (nmoves == 0)
558
      return 0;
558
      return 0;
Line 597... Line 597...
597
      total_value = 1000.0;
597
      total_value = 1000.0;
598
    total_percent = (total_percent > 99) ? 99 : total_percent;
598
    total_percent = (total_percent > 99) ? 99 : total_percent;
599
    for (i = 0; i < nmoves; i++)
599
    for (i = 0; i < nmoves; i++)
600
      if (bs_percent[i])
600
      if (bs_percent[i])
601
        bs_value[i] =
601
        bs_value[i] =
602
            total_value / (1.0f - // Pierre-Marie Baty -- added type cast
602
            total_value / (1.0 -
603
            (float) total_percent / 100.0f) * (float) bs_percent[i] / 100.0f; // Pierre-Marie Baty -- added type casts
603
            (float) total_percent / 100.0) * (float) bs_percent[i] / 100.0;
604
/*
604
/*
605
 ************************************************************
605
 ************************************************************
606
 *                                                          *
606
 *                                                          *
607
 *  Display the book moves, and total counts, etc. if the   *
607
 *  Display the book moves, and total counts, etc. if the   *
608
 *  operator has requested it.                              *
608
 *  operator has requested it.                              *
Line 672... Line 672...
672
          }
672
          }
673
        } else {
673
        } else {
674
          tree->pv[0].path[1] = book_moves[0];
674
          tree->pv[0].path[1] = book_moves[0];
675
          tree->pv[0].pathl = 2;
675
          tree->pv[0].pathl = 2;
676
          tree->pv[0].pathd = 0;
676
          tree->pv[0].pathd = 0;
-
 
677
          tree->pv[0].pathv = 0;
677
        }
678
        }
678
        return 1;
679
        return 1;
679
      }
680
      }
680
    }
681
    }
681
/*
682
/*
Line 728... Line 729...
728
    for (i = 0; i < j; i++)
729
    for (i = 0; i < j; i++)
729
      which = Random32();
730
      which = Random32();
730
    total_moves = 0;
731
    total_moves = 0;
731
    for (i = 0; i < last_move; i++) {
732
    for (i = 0; i < last_move; i++) {
732
      if (bs_percent[0])
733
      if (bs_percent[0])
733
        total_moves += (int) bs_value[i]; // Pierre-Marie Baty -- added type cast
734
        total_moves += bs_value[i];
734
      else
735
      else
735
        total_moves += (int) (bs_value[i] * bs_value[i]); // Pierre-Marie Baty -- added type cast
736
        total_moves += bs_value[i] * bs_value[i];
736
    }
737
    }
737
    distribution = Abs(which) % Max(total_moves, 1);
738
    distribution = Abs(which) % Max(total_moves, 1);
738
    for (which = 0; which < last_move; which++) {
739
    for (which = 0; which < last_move; which++) {
739
      if (bs_percent[0])
740
      if (bs_percent[0])
740
        distribution -= (int) bs_value[which]; // Pierre-Marie Baty -- added type cast
741
        distribution -= bs_value[which];
741
      else
742
      else
742
        distribution -= (int) (bs_value[which] * bs_value[which]); // Pierre-Marie Baty -- added type cast
743
        distribution -= bs_value[which] * bs_value[which];
743
      if (distribution < 0)
744
      if (distribution < 0)
744
        break;
745
        break;
745
    }
746
    }
746
    which = Min(which, last_move - 1);
747
    which = Min(which, last_move - 1);
747
    tree->pv[0].path[1] = book_moves[which];
748
    tree->pv[0].path[1] = book_moves[which];
Line 921... Line 922...
921
  FILE *book_input;
922
  FILE *book_input;
922
  char fname[128], start, *ch, output_filename[128];
923
  char fname[128], start, *ch, output_filename[128];
923
  static char schar[2] = { "." };
924
  static char schar[2] = { "." };
924
  int result = 0, played, i, mask_word, total_moves;
925
  int result = 0, played, i, mask_word, total_moves;
925
  int move, move_num, wtm, book_positions, major, minor;
926
  int move, move_num, wtm, book_positions, major, minor;
926
  int cluster, max_cluster, discarded = 0, discarded_mp = 0, discarded_lose =
927
  int cluster, max_cluster, ignored = 0, ignored_mp = 0, ignored_lose =
927
      0;
928
      0;
928
  int errors, data_read;
929
  int errors, data_read;
929
  int start_elapsed_time, ply, max_ply = 256;
930
  int start_elapsed_time, ply, max_ply = 256;
930
  int stat, files = 0, buffered = 0, min_played = 0, games_parsed = 0;
931
  int stat, files = 0, buffered = 0, min_played = 0, games_parsed = 0;
931
  int wins, losses;
932
  int wins, losses;
Line 1129... Line 1130...
1129
            if (!strchr(buffer, '$') && !strchr(buffer, '*')) {
1130
            if (!strchr(buffer, '$') && !strchr(buffer, '*')) {
1130
              if (ply < max_ply)
1131
              if (ply < max_ply)
1131
                move = ReadNextMove(tree, buffer, 2, wtm);
1132
                move = ReadNextMove(tree, buffer, 2, wtm);
1132
              else {
1133
              else {
1133
                move = 0;
1134
                move = 0;
1134
                discarded++;
1135
                ignored++;
1135
              }
1136
              }
1136
              if (move) {
1137
              if (move) {
1137
                ply++;
1138
                ply++;
1138
                max_search_depth = Max(max_search_depth, ply);
1139
                max_search_depth = Max(max_search_depth, ply);
1139
                total_moves++;
1140
                total_moves++;
Line 1209... Line 1210...
1209
                break;
1210
                break;
1210
              }
1211
              }
1211
            }
1212
            }
1212
            data_read = ReadPGN(book_input, 0);
1213
            data_read = ReadPGN(book_input, 0);
1213
          }
1214
          }
-
 
1215
          strcpy(initial_position, "");
1214
        } while (0);
1216
        } while (0);
1215
    } while (strcmp(buffer, "end") && data_read != -1);
1217
    } while (strcmp(buffer, "end") && data_read != -1);
1216
    if (book_input != stdin)
1218
    if (book_input != stdin)
1217
      fclose(book_input);
1219
      fclose(book_input);
1218
    if (buffered)
1220
    if (buffered)
Line 1266... Line 1268...
1266
      losses++;
1268
      losses++;
1267
    if (temp.status & 32 && !(temp.percent_play & 128))
1269
    if (temp.status & 32 && !(temp.percent_play & 128))
1268
      wins++;
1270
      wins++;
1269
    if (temp.status & 32 && temp.percent_play & 128)
1271
    if (temp.status & 32 && temp.percent_play & 128)
1270
      losses++;
1272
      losses++;
1271
    while (1) {
1273
    while (FOREVER) {
1272
      temp = BookupNextPosition(files, 0);
1274
      temp = BookupNextPosition(files, 0);
1273
      memcpy((char *) &next.position, temp.position, 8);
1275
      memcpy((char *) &next.position, temp.position, 8);
1274
      next.status_played = temp.status << 24;
1276
      next.status_played = temp.status << 24;
1275
      if (start)
1277
      if (start)
1276
        next.status_played += temp.percent_play & 127;
1278
        next.status_played += temp.percent_play & 127;
Line 1304... Line 1306...
1304
          memcpy((void *) &book_buffer_char[0].position,
1306
          memcpy((void *) &book_buffer_char[0].position,
1305
              (void *) BookOut64(current.position), 8);
1307
              (void *) BookOut64(current.position), 8);
1306
          memcpy((void *) &book_buffer_char[0].status_played,
1308
          memcpy((void *) &book_buffer_char[0].status_played,
1307
              (void *) BookOut32(current.status_played), 4);
1309
              (void *) BookOut32(current.status_played), 4);
1308
          memcpy((void *) &book_buffer_char[0].learn,
1310
          memcpy((void *) &book_buffer_char[0].learn,
1309
              (void *) BookOut32((int) current.learn), 4); // Pierre-Marie Baty -- added type cast
1311
              (void *) BookOut32(current.learn), 4);
1310
          stat =
1312
          stat =
1311
              fwrite(book_buffer_char, sizeof(BOOK_POSITION), 1, book_file);
1313
              fwrite(book_buffer_char, sizeof(BOOK_POSITION), 1, book_file);
1312
          if (stat != 1)
1314
          if (stat != 1)
1313
            Print(4095, "ERROR!  write failed, disk probably full.\n");
1315
            Print(4095, "ERROR!  write failed, disk probably full.\n");
1314
        } else if (played < min_played)
1316
        } else if (played < min_played)
1315
          discarded_mp++;
1317
          ignored_mp++;
1316
        else
1318
        else
1317
          discarded_lose++;
1319
          ignored_lose++;
1318
        if (last != (int) (next.position >> 49)) {
1320
        if (last != (int) (next.position >> 49)) {
1319
          next_cluster = ftell(book_file);
1321
          next_cluster = ftell(book_file);
1320
          fseek(book_file, cluster_seek, SEEK_SET);
1322
          fseek(book_file, cluster_seek, SEEK_SET);
1321
          memcpy((void *) &cluster, BookOut32(cluster), 4);
1323
          memcpy((void *) &cluster, BookOut32(cluster), 4);
1322
          stat = fwrite(&cluster, sizeof(int), 1, book_file);
1324
          stat = fwrite(&cluster, sizeof(int), 1, book_file);
Line 1369... Line 1371...
1369
    free(index);
1371
    free(index);
1370
    start_elapsed_time = ReadClock() - start_elapsed_time;
1372
    start_elapsed_time = ReadClock() - start_elapsed_time;
1371
    Print(4095, "\n\nparsed %d moves (%d games).\n", total_moves,
1373
    Print(4095, "\n\nparsed %d moves (%d games).\n", total_moves,
1372
        games_parsed);
1374
        games_parsed);
1373
    Print(4095, "found %d errors during parsing.\n", errors);
1375
    Print(4095, "found %d errors during parsing.\n", errors);
1374
    Print(4095, "discarded %d moves (maxply=%d).\n", discarded, max_ply);
1376
    Print(4095, "ignored %d moves (maxply=%d).\n", ignored, max_ply);
1375
    Print(4095, "discarded %d moves (minplayed=%d).\n", discarded_mp,
1377
    Print(4095, "ignored %d moves (minplayed=%d).\n", ignored_mp,
1376
        min_played);
1378
        min_played);
1377
    Print(4095, "discarded %d moves (win/lose=%.1f%%).\n", discarded_lose,
1379
    Print(4095, "ignored %d moves (win/lose=%.1f%%).\n", ignored_lose,
1378
        wl_percent * 100);
1380
        wl_percent * 100);
1379
    Print(4095, "book contains %d unique positions.\n", book_positions);
1381
    Print(4095, "book contains %d unique positions.\n", book_positions);
1380
    Print(4095, "deepest book line was %d plies.\n", max_search_depth);
1382
    Print(4095, "deepest book line was %d plies.\n", max_search_depth);
1381
    Print(4095, "longest cluster of moves was %d.\n", max_cluster);
1383
    Print(4095, "longest cluster of moves was %d.\n", max_cluster);
1382
    Print(4095, "time used:  %s elapsed.\n", DisplayTime(start_elapsed_time));
1384
    Print(4095, "time used:  %s elapsed.\n", DisplayTime(start_elapsed_time));