|
22 | 22 | default=1, |
23 | 23 | help="number of plies to advance", |
24 | 24 | ) |
| 25 | + parser.add_argument( |
| 26 | + "--targetMate", |
| 27 | + type=int, |
| 28 | + help="in each position advance enough plies to leave a mate-in-TARGETMATE (overrides --plies)", |
| 29 | + ) |
25 | 30 | parser.add_argument( |
26 | 31 | "--mateType", |
27 | 32 | choices=["all", "won", "lost"], |
28 | | - default="won", |
| 33 | + default="all", |
29 | 34 | help="type of positions to advance from", |
30 | 35 | ) |
31 | 36 | args = parser.parse_args() |
|
45 | 50 |
|
46 | 51 | print(f"{len(fens)} FENs loaded...") |
47 | 52 |
|
48 | | - count = 0 |
| 53 | + count, plies = 0, args.plies |
49 | 54 | with open(args.outFile, "w") as f: |
50 | 55 | for fen, bm, pv, line in fens: |
51 | 56 | plies_to_checkmate = 2 * bm - 1 if bm > 0 else -2 * bm |
| 57 | + if args.targetMate: |
| 58 | + m = args.targetMate |
| 59 | + plies4m = 2 * m - 1 if m > 0 else -2 * m |
| 60 | + plies = plies_to_checkmate - plies4m |
| 61 | + if plies < 0: |
| 62 | + plies = plies_to_checkmate + 1 |
52 | 63 | if ( |
53 | | - args.plies <= len(pv) |
54 | | - and args.plies < plies_to_checkmate |
| 64 | + plies <= len(pv) |
| 65 | + and plies < plies_to_checkmate |
55 | 66 | and ( |
56 | 67 | args.mateType == "all" |
57 | 68 | or args.mateType == "won" |
|
61 | 72 | ) |
62 | 73 | ): |
63 | 74 | board = chess.Board(fen) |
64 | | - for move in pv[: args.plies]: |
| 75 | + for move in pv[:plies]: |
65 | 76 | board.push(chess.Move.from_uci(move)) |
66 | 77 | bm = -bm + (1 if bm > 0 else 0) |
67 | 78 | fen = board.epd() |
68 | | - pv = pv[args.plies :] |
| 79 | + pv = pv[plies:] |
69 | 80 | f.write(f"{fen} bm #{bm}; PV: {' '.join(pv)};\n") |
70 | 81 | count += 1 |
71 | 82 | else: |
72 | 83 | f.write(line) |
73 | 84 |
|
74 | | - print(f"Positions in which we advanced {args.plies} plies: ", count) |
| 85 | + if args.targetMate: |
| 86 | + print(f"Number of #{args.targetMate} positions created: ", count) |
| 87 | + else: |
| 88 | + print(f"Positions in which we advanced {plies} plies: ", count) |
0 commit comments