User:Hexanna

From HexWiki
Revision as of 02:07, 5 September 2024 by Hexanna (Talk | contribs)

Jump to: navigation, search

Openings on 19 x 19

Strategic advice from KataHex

I started learning Hex mid-July of 2021, about 2 weeks before I created my LittleGolem account.

katahex 20240812

  • It's hard to put into words precisely, but the new net plays quite counterintuitively. Many of its preferred moves are surprising to me, and its play on 19×19 feels less "local" and more structured. This is probably just placebo, but I like to think that it's because the net was actually trained on 19×19 for a much longer time (on a stronger GPU), so it actually learned to play on 19×19 instead of just applying heuristics from 13×13.

katahex/general strategy (draft material)

Some miscellaneous topics — I've written rough drafts/outlines of a few but they aren't ready to be published. If you have KataHex, you might consider these "select topics" as an advanced study guide for large boards, to explore on your own.

a3 opening

Nowadays, strong players rarely play a3 on the first move because it's similar to c2 (which is already on the losing side on most board sizes), but a bit weaker. There are some subtle differences between a3 and c2, however, and most strategy advice on the a3 opening is outdated.

If Red plays a3, some older strategy guides recommend that Blue respond d6 or e7 if she wants to play in the acute corner. However, KataHex considers this an inaccuracy; even though d6 and e7 are attacking stones in the sense that Blue would win a bridge ladder towards the acute corner, they don't do a good job blocking Red's edge the way e4 does in an empty corner.

If you want to play the acute corner, 5-5, or 4-4 on smaller boards, is a good choice. (There are other options further away from the corner on larger boards.) KataHex and other bots consistently prefer these moves:

One reason may be the efficiency of templates IV2e and V2d, both of which have a "hole"; the template can be rotated so that the hole coincides with Red's a3 stone. This is explored in more detail below.

It can be useful to realize that a3 is primarily a blocking move (blocking Blue on the left rather than helping Red connect to top), whereas c2 is half blocking and half connecting. To illustrate the point, it's a bad idea for Red to play both c2 and 4-4 obtuse corner on the top edge (in the absence of Blue's blocking stones), because that's too much strength near the top. However, Red could feasibly play both a3 and 4-4 on the top edge.

a3 can combine well with c5. Red's goal is to leave b4/c5 open as options (these are the same hexes used in the a3 escape trick, but of course, a3+c5 can also connect upwards). Blue should also keep an eye on b4 - not to play immediately because it's too close to her own edge - but as the most efficient option for connecting to the left side near the top. Blue would much prefer to connect using b4 (which is a locally efficient move that neutralizes a3's switchback and upwards connecting potential) than b5 (which only slightly weakens a3's potential, forcing Red to play d5 instead of c5), or a 2nd row ladder with b3 (which removes Red's weakness at b1).

a3 is one of my favorite openings to analyze (I only wish it were more fair as an opening move). Unlike c2 where Blue's best move is typically to tenuki, a3 gives Blue the option to fight in the same acute corner. There is essentially a separate theory of a3 corner joseki.

I find a3 lines particularly educational because a3 changes the corner just enough to make different moves more efficient. You can learn a lot about how an existing stone influences neighboring stones.

Notation for distances

When analyzing patterns, it's useful to have a way to express various distances concisely. There are terms like adjacent, bridge, "classic block," but larger distances are hard to describe. Distances like "two hexes away" are ambiguous, does it mean a distance of 2 (like a1 and c1) or two hexes in between (like a1 and d1)? Everyone has their own way of thinking about it. Here's the one I use:

  • Pretend that the hex grid consists of regular hexagons, and adjacent hexagons' centers have distance 1. (Equivalently, the centers of the hexes form a triangular lattice; pretend these triangles are equilateral with side length 1.)
  • It's not hard to show that a "bridge" (like a1 and b2) has length sqrt(3) if you connect the centers, and a "classic block" (like a1 and c2) has length sqrt(7). A fun exercise is to show that the distances between the centers of two hexes is always the square root of an integer. Which integers are possible as squared distances? Answer: Löschian numbers.
  • The fact that squared distances are integers is notationally convenient. Let Δn denote a squared distance of n (I like this because it looks nicer than a square root symbol, and a letter like "d" can be confused with a coordinate).
  • "Adjacent" is Δ1; "bridge" is Δ3; "classic block" is Δ7; the distance between a1 and c1 is Δ4; "two bridges away" is Δ12.
  • Are there collisions? Yes, but the first collision is Δ49 (a distance of 7), which is both the distance between a1 and h1, and between a1 and f4. This is large enough that for practical purposes, the notation is unique. (An interesting fact: the first number with a 4-way collision is, coincidentally, 1729 of Ramanujan fame.)
  • Here is a mapping of squared distances from the hex marked (*). Most of the time, you only need distances up to Δ16.
1491625364964371321314357121928395227374948

Why I like the swap rule

  1. The standard reason: It makes the game much more fair.
  2. Every Hex player knows "Hex without swap is a first-player win." Add the swap rule, and you get another elegant result for free: "Hex with swap is a second-player win."
  3. It provides much-needed asymmetry to the opening. The Hex board has two-fold rotational symmetry, and on odd-sized boards without swap, most players will open in the center. The symmetry isn't broken until the second turn!
  4. The opening stone is especially influential in determining the character of the game. On 19x19, games that open with c2 look quite different from those that open with a10. A lot of cool tactics, like the a3 and a4 switchbacks, only really appear when you add the swap rule. The swap rule greatly expands the variety of plausible positions, and who doesn't like more variety?
  5. While the second player has a theoretical advantage, the first player has a practical advantage: she can choose what opening to play. Because the opening stone is much more influential than later stones, the first player can pick an opening that she's especially familiar with, or one that her opponent is weak at. It would not be surprising if the first and second player's advantages cancel out among strong humans (on 19x19), and each player wins almost exactly 50% of games.
  6. Since the swap rule is nonconstructive, it scales up beautifully to larger boards. Even if players have no idea which opening stones are fair, it's virtually certain that fair stones exist, and there should be no qualms about fairness. Contrast this with komi in Go: a fair komi has to be empirically determined for each board size, and there could be disagreements about the komi for various board sizes. (This concern is alleviated with auction komi, but that adds another rule to the game.)
  7. It's resistant to partial solutions. Let's say that someone miraculously comes up with a constructive proof that the obtuse corner is winning on 19x19. No problem, players will just stop playing obtuse corner and play other opening moves instead.
  8. It's fun to try to trick players into swapping a weak move or not swapping a deceptively strong move. :)

Second row ladder vs. connecting directly

Pretty contrived, but holding your opponent to a (one-sided) second row ladder instead of letting them connect directly is worth more than getting a second-row escape yourself.

I came across this intuition a few times when studying various sequences on large boards, and it seemed surprisingly self-evident (almost like it "has" to be true). I wasn't sure why, so I thought it was a fun exercise to convince myself that it actually makes sense from first principles. Here is an informal argument:

  • Let x = "holding your opponent to a second row ladder instead of letting them connect directly"
  • Let y = "getting a second-row escape yourself"
  • To show that x > y, decompose x = m - n, where
  • m = "your opponent has a second row ladder"
  • n = "your opponent connects directly"
  • Also, -y is "your opponent has a second-row escape". Then, x > y is equivalent to m + (-y) > n.
  • That is, all else equal, you'd rather allow your opponent a second-row ladder with a second-row escape, than allow your opponent a direct connection. Why is this true? In the first situation (m + (-y)), you have the ability to jump as the defender, and gain territory in exchange for allowing your opponent to connect. On the other hand, if the opponent is connected directly without the need for a ladder escape, you have no such option.

Some potential applications of this rule (it's a stretch to say that these are direct implications of the rule, but the rule can help with building intuition):

Insights and tidbits from KataHex (hzy's bot)

  • katahex_model_20220618.bin.gz (I'll call this the "strong" net) appears significantly stronger than the "default" net.
  • Swap map for 19×19 generated with the strong net, with around 15k visits for most moves. For the red hexes, the number corresponds to Blue's Elo advantage if she swaps Red's move; for the blue hexes, the number corresponds to Blue's Elo advantage if she does not swap Red's move. Smaller numbers correspond to fairer openings. Includes all fair openings as well as a few selected unfair openings, including the strongest move without swap (e10). I used more visits for the fairest moves: 1000k for e3 (49.5% win rate), 500k for n3 (49.2%), 100k for a15 (52.5%).
    • Key takeaways: The swap map at Swap rule#Size 19 uses data that is almost certainly from the "weak" net. Compared to the weak net, the strong net notably thinks a19, n3—p3, and k4—l4 are stronger. I personally trust the strong net's evaluations more; I think it's dubious that the weak net thought l4 was a very fair opening. The nets disagree on whether e3 is winning or losing, though it's so close to 50% that the difference isn't meaningful.
abcdefghijklmnopqrs123456789101112131415161718195677675614616369201174100137157653737673849010310449647599611083731217267819413857136122108133179356957813111599814138238241819911513178955693171331081221365713894816772121738311096594764910410390847376733651571371001742016916314656677756

Random unsolved questions

Most of these are very difficult to answer, and I would be happy if even a few were answered in the next few years:

  • Is the obtuse corner always winning on larger board sizes? What about the b4 opening? Let P(n) be the statement that "the obtuse corner is a winning opening in n×n Hex without swap." There are a few possible cases; an interesting exercise is to come up with subjective probabilities of each case being true.
    • A. P(n) is always true. If so, can we prove this?
    • B. P(n) is true for infinitely many n, with finitely many counterexamples. If so, what's the smallest counterexample?
    • C. P(n) is true for infinitely many n, with infinitely many counterexamples. If so, does P(n) hold "almost always," "almost never," or somewhere in between?
    • D. P(n) is true for finitely many n. If so, what's the largest such n?
  • Kriegspiel Hex (Dark Hex), a variant with incomplete information
    • Under optimal mixed strategies, what is Red's win probability on 4×4?
    • For larger boards (say, 19×19), is Red's win probability close to 50%?
      • If so, a swap rule might not be needed for Kriegspiel Hex, which would be neat.
      • If not, imagine a variant where Red's first move is publicly announced to both players, and Blue has the option to swap it. Which initial moves are the fairest now?


replies by Demer:

  • https://zhuanlan.zhihu.com/p/476464087 has percentages, although it doesn't translate these into a guessed swap map and I don't know anything about the bot they came from.
    • ​ It suggests that [on 13x13, g3 is the most balanced opening] and [on 14x14, g3 should not be swapped].
    • On 27x27 without swap, it likes the 4-4 obtuse corner opening slightly more than anything else nearby.
  • As far as I'm aware, even 3×4 Dark Hex has not been solved. ​ (https://content.iospress.com/articles/icga-journal/icg180057 apparently gives "some preliminary results" for that size.)

hexanna:

  • Thank you, this is amazing! From the Google Translate, the bot is an adaptation of KataGo trained on 13×13 and smaller, using transfer learning to train larger nets on top of the 13×13 net for a short period of time. I may edit the swap rule article later with some insights.
    • The results for up to 15×15 look very reliable to me. This is because many of the subtle patterns suggested by other bots, like leela_bot, appear in these swap maps. For example, on 13×13:
      • a1–c1 are stronger than d1; a2–c2 ≥ d2 ≥ e2 in strength; and a similar relation holds for moves on the third row. See Openings on 11 x 11#d2.
      • b4 is weaker than all of its neighbors, because Blue can fit the ziggurat in the corner.
      • j3 is surprisingly weak and i3 is surprisingly strong. Many people were surprised about this when leela_bot's swap map came out, but the result may be more than just random noise.
      • a10 is the weakest of a4–a10, while a5 is the strongest.
      • b10 is stronger than all of its neighbors, because Blue cannot fit the ziggurat in the obtuse corner.
    • That this bot picked up on all these subtleties, and assigns a win percentage close to 100% for most moves on 13×13, suggest to me that it is probably stronger than leela_bot and gzero_bot. I can't know for sure, though.
    • On the other hand, and the author seems to agree, the 37×37 map looks very unreliable. I see percentages as low as 37% but only as high as 54% (for a move like f1, which should almost certainly be a losing move).
    • The 27×27 map looks more reliable. I'm personally very skeptical that moves on Red's 6th row are among the most balanced moves, but there are some interesting (if somewhat noisy) insights to be had still.

Recursive swap

Not really a serious suggestion, just for fun. One advantage of "recursive swap" over multi-stone swap is that opening preparation plays a smaller role, because both players have control over the first n stones.

RECURSIVE_SWAP'[k, depth, color]:
  if depth = 0:
    [color] continues playing as normal.
  else:
    [color] plays a move. [~color] can either
      swap[k], or
      RECURSIVE_SWAP'[k+1, depth-1, ~color]

RECURSIVE_SWAP[n]:
  RECURSIVE_SWAP'[1, n, Red]

RECURSIVE_SWAP[0]:

Red continues playing as normal.

RECURSIVE_SWAP[1]:

Red plays a move. Blue can either

  • swap, or
  • continue playing as normal.

RECURSIVE_SWAP[2]:

Red plays a move. Blue can either

  • swap, or
  • play a move, after which Red can either
    • swap2, or
    • continue playing as normal.

RECURSIVE_SWAP[3]:

Red plays a move. Blue can either

  • swap, or
  • play a move, after which Red can either
    • swap2, or
    • play a move, after which Blue can either
      • swap3, or
      • continue playing as normal.

Analysis

RECURSIVE_SWAP[0] is the same as playing with no swap.

RECURSIVE_SWAP[1] is the same as playing with the swap rule.

RECURSIVE_SWAP[2]:

  • Red shouldn't play a move that's too strong or it'll be swapped.
  • If Red plays a weak stone, Blue should try to play a move just strong enough that Red will be indifferent to swap2. (If a "fair" move is half a stone, and Red plays a weak move worth x < 0.5 stones, Blue should play a move worth x + 0.5 stones.)
  • Red should try to play a weak move that's also hard for Blue to equalize (so that Red gets a sizable advantage when deciding whether to swap2 or not).

RECURSIVE_SWAP[3]:

  • If Red plays a move worth x > 0.5 stones, Blue should swap.
  • If Red plays a weak stone worth x < 0.5, Blue should play a move worth less than x + 0.5 (or else Red will swap2). If Blue's move is worth y, then Red should play a move as close to (y - x) + 0.5 as possible, so that Blue's swap3 decision is difficult.
  • Red should play a weak move that's hard for Blue to find a tricky reply to (where a "tricky" reply is one that makes it hard for Red to equalize, such that Blue has an easy time deciding whether to swap3 or not).

Miscellaneous:

  • Infinite recursive swap is (under perfect play) strategically equivalent to Reverse Hex, because each player must try to play a losing move as long as possible, or else their opponent will swap and win.
  • On any board size, assuming the opponent has the swap option after the board is completely filled, I believe RECURSIVE_SWAP[n] is a win for Red if n is even, and a win for Blue if n is odd.
    • I'm bad at proving things rigorously, but I think this follows from the fact that Reverse Hex is barely a win for the winning side (in that the losing side can delay the loss until the whole board is filled).

Fjan2ej57w's question 7, "how much space of an empty board would be filled if both sides play optimally":

Stack Overflow answer for reference. My conjecture is that Hex without swap asymptotically requires Θ(n^2) cells, and more generally, a Demer handicap of Θ(f(n)) stones requires Θ(n^2/f(n)) cells, for all f(n) between Θ(1) and Θ(n). My intuition is that on 1000000×1000000 Hex, the first-player advantage is minuscule, and even a handicap of n^(1/2) = 1000 stones, say spaced out evenly across the short diagonal, would require on the order of "1000 columns and 1000000 rows", n^(3/2), to convert to a final connection. Another interesting question is to find a constructive winning strategy with an o(n) (sub-linear) handicap.

reply by Demer: ​ ​ ​ ​ ​ ​ ​ Even one with ​ n/6 - ω(1) ​ handicap would be interesting. ​ ​ ​ (improving on ​ https://webdocs.cs.ualberta.ca/~hayward/papers/handicap.pdf )