diff options
Diffstat (limited to 'include/ct1986.c')
| -rw-r--r-- | include/ct1986.c | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/include/ct1986.c b/include/ct1986.c index 5e1c0fc..9289d2f 100644 --- a/include/ct1986.c +++ b/include/ct1986.c @@ -170,8 +170,14 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth, const uint8_t min, float alpha, float beta) { enum E_RESULT r; - const uint8_t white_count_backup = white_count, - black_count_backup = black_count; + const uint8_t black = (ply & 1), + material = (black) ? black_count : white_count; + + uint8_t cap = 0, flat = material & 127, standing = 0; + if (ply > 2) { + if (material & 128) cap = 1; + if (material & 127) standing = 1; + } // 1.0 is a `certain' black win, -1.0 is a `certain' white win. float optimal = (min) ? infty : -infty; @@ -261,30 +267,55 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth, } } } else if (count == 0) { - // Empty square, try the three placements. Again, looping - // through enums, sigh. - for (enum STONE_VARIANT stone = STONE_FLAT; - stone <= STONE_CAPSTONE; stone++) { - // try_place will never check for winning, and we don't do - // that either here - r = try_place(loc, current_colour, stone); - // Legal placement, evaluate it - if (r == ACT_OK) { - // First check for wins, if we're at the bottom - // evaluate, otherwise recurse - WIN_EVALUATE_OR_RECURSE({ + // Empty square, try the three placements. + + if (flat) { + // Generate the placement + if (black) black_count--; + else white_count--; + colours[loc] = current_colour; + celldat[loc] = NUM_INC | STONE_FLAT; + WIN_EVALUATE_OR_RECURSE({ // If we did update the optimal value, store - // this move - generate_place(loc, stone, ct1986_ptn); + generate_place(loc, STONE_FLAT, ct1986_ptn); + }); + // Reset the state + celldat[loc] = 0; + if (black) black_count++; + else white_count++; + // Prune + if (alpha >= beta) return optimal; + + // Do the same for walls, can't happen without flats + if (standing) { + if (black) black_count--; + else white_count--; + colours[loc] = current_colour; + celldat[loc] = NUM_INC | STONE_STANDING; + WIN_EVALUATE_OR_RECURSE({ + generate_place(loc, STONE_STANDING, ct1986_ptn); }); - // Reset the state celldat[loc] = 0; - white_count = white_count_backup; - black_count = black_count_backup; - // Prune + if (black) black_count++; + else white_count++; if (alpha >= beta) return optimal; } } + + // and for caps + if (cap) { + if (black) black_count &= 127; + else white_count &= 127; + colours[loc] = current_colour; + celldat[loc] = NUM_INC | STONE_STANDING; + WIN_EVALUATE_OR_RECURSE({ + generate_place(loc, STONE_STANDING, ct1986_ptn); + }); + celldat[loc] = 0; + if (black) black_count |= 128; + else white_count |= 128; + if (alpha >= beta) return optimal; + } } ct1986_display_progress(cur_depth); } |
