Twixt

  Difficulty: Introductory   Keywords: Question, Rules, Theory

A game published in the 1960s by the 3M corporation in their "bookshelf" line. The board consists of a 24x24 array of holes arranged in a square grid. The outermost line of holes surrounding the board is partitioned off, and opposite sides are assigned to opposing players by colors red and black (similarly to Hex).

Players take turns placing colored pegs into the holes, and when two pegs of the same color share a "Knight's Move" relationship to each other, they place a small plastic bar across the tops of the pegs. As in Hex, the goal is to complete a bridge from one side of the board to the opposite side using these bars. Since bars are not allowed to cross each other, they can be used defensively (block the way of the opponent) as well.


http://www.bggfiles.com/bggimages/pic55595_t.jpg


The Twixt Server k2z

  • Steps to get started:
    • Download the client: [ext] http://www.gamerz.net/k2z/download
    • use as Server URL: www.gamerz.net, Port: 57017 (both should be default)
    • use as Login: guest1,2,3,...9, Password: guest1,2,3,...9
    • wait until another player connects... :) (or play against the bots)

http://www.gamerz.net/k2z/images/game5.png (picture of early version of the client)



Programming a Computer Opponent for Twixt (a Twixt-Bot)

Choosing the rules

  • There are about 24x22=528 legal moves (on 24x24 board) in the beginning for each player
  • TwixtPP (little golem) means:
    • crossing own links is allowed
    • link removal is not allowed
  • Standard Twixt Rules are:
    • crossing own links is not allowed
    • link removal is allowed
  • TwixtPP is almost the same as Twixt with removing links for most of the game, except for some (endgame-)"fights" where the player is blocking his own way - removing links would help him then.
  • I recommend TwixtPP (=no link removal) for computer-experiments for the beginning.
  • a simple Twixt(TwixtPP) move (without link removal) consists of a x- and y-coordinate of the peg to be placed on the board. All possible links (up to 8) are then added automatically.
  • Tie: a tie (no player able to complete a connection) is possible with both rules (TwixtPP and Standard Twixt)

Representing a board situation

  • simple: keep a List of Pegs and Links for each Player (k2z uses this)
  • represent the board as a 24x24 array for the pegs and have another (about 24x24) array for the links (8 directions=8bit-bitfield); 2 possibilities:
    • store each link "twice" in the array (once for the point where the link begins and once for the point where it ends)
    • store each link only once in the array, but use the convention, that links have to go to the right (for example) =only 4 directions left (T1 uses this)
  • what next? Already "connected" pegs, together with the links that connect them, form a group, which the opponent can't break and which will stay on the board like it is till the end of the game in almost all cases (the only exception: link removal in the "endgame"). So the program can recognize and represent such groups in some datastructure. (incrementally perhaps, if undoing moves during search is necessary -- I implemented this already based on the source of "T1", but didn't use it for anything).
  • another useful idea might be - especially when representing the board as a 2d-array (but not only then) -, to normalize the board so that the player-to-move always plays horizontally. This is imho very useful for all kind of algorithms ("pattern searching", just generating moves, etc), and eliminates a lot of special cases in the code.
    • instead of "normalizing" the board and rotating it after every move, two board-objects (c++) should be kept, one where the player-to-move has to play horizontally (this is used for the actual algorithms/calculations) and one where the player-to-move would have to play in vertical direction (this is kept in the background). After the player has made the same move in both boards, the pointers to the board-objects are just swapped. (i implemented it to this point)
  • the next level would be to have also 2 boards mirrored along the vertical axis, for searching for connections to the left OR right border of the board, depending on which subgame you are considering (an example for subgames: moves at the left side of the board might be completely independent of moves at the right side of the board, although both areas might not yet be completley connected, but both sides have to get connected, finally (AND-situation)) (in the opening there are no subgames, so it doesn't matter which of the 2 (mirrored) boards you look at for choosing the move).
    • (So this gives a sum of 4 boards to update (or recalculate) for every move or undone move)
  • to mirror the board also along the horizontal axis (player-to-move still plays horizontally) might make sense for very few algorithms (opening database is an example, this is normalized for first peg in upper left corner). However the above 2 normalizations are more useful/important.
  • UPDATE (last 2 points): my opinion is now to use only the 2 mirrored boards that are updated for every move (during search etc). 4 or 8 boards is too complicated and not really useful (lots of coordinate-transformations to find the same point in another board). For 2 boards you just have to swap x and y coordinates, so not a too big problem.

Possible Strategies

  • an opening book for the first moves is necessary, but of course it can't cover all possible situations in the opening

About Search

  • there seems to be a special kind of search necessary:
    • sometimes (especially towards the end of the game) there might be a winning move a for Player A (or a move that gives a big advantage) but it's Player B's turn: so it's clear that B must block A's way "somehow" (play in same area); especially all the about 400-500 other legal moves would lose immediately, so they need not be generated if you can prove that they make no difference!
    • replace "a winning move a for Player A" by "an area (or a set of points), where at least some moves in the area would win (but definitely none out of this area)"

Rules/Patterns/Generating Moves

  • rules/patterns: there are a few moves, which are often good, so the computer can try these moves first (then some other moves in the same area):
    • extensions/jumps: 2-1,1-2;3-3,4-0, etc
    • blocks: 2-0,4-0, etc

Diagonal guide lines

Analyzing the goodness of a certain board position

Evaluation function

... to be written

Subgames (in simple situations)

  • another observation is, that independent subgames often emerge quite early in the game; sometimes as soon as a (longer) string in the middle of the board exists, and "only" the 2 ends have to be connected to the sides (AND-Situation).
  • to consider 2 situations (at the 2 ends of the large group/string, for example) as subgames might make sense, in a given situation, only, if the player-to-move is able to win both subgames provably (or at least very likely, according to heuristics). Being not able to win one of the 2 subgames directly means a different strategy has to be chosen, which possibly only uses the large group (at which's 2 ends the 2 subgames exist) as an indirect threat.
  • when analyzing subgames it is not only interesting whether the player-to-move can win the subgame, but also whether he can win it, even if he moves second in the subgame.

Solving Twixt on small boards

  • Rules:
    • (no swap allowed)

4x4

  • 8 legal moves as Move1 for Player1
  • all moves result in a tie, because no complete connection is possible on this small board
[Diagram]

4x4


5x5

  • 6 possible moves (with considering symmetries) for Move1
    • move in the middle wins for Player 1?? / 2?? / Tie?? ???
    • ...todo
[Diagram]

5x5

[Diagram]

5x5

If "Vertical" plays 1, H plays 2 (for example), etc...


6x6

[Diagram]

6x6


Twixt Puzzles

  • [ext] http://www.gamerz.net/pbmserv/Twixt/puzzles.html 40 puzzles
    • I have entered these as 24x24 full board problems, so they can be used as testcases for a program, to test whether it is able to solve these problems (currently no program exists however). (--> there is no download address for this, but ask here if you need it)

List of known Programs

http://www.johannes-schwagereit.de/t1_06.png (picture of T1)

http://www.johannes-schwagereit.de/T1_OldVersion.png (early version of T1: when you place a bridge on the board, exactly 9 other bridges are made impossible (plus the one bridge you are placing on the board=10 bridges)



Discussion about this page on /Discussion


This is a copy of the living page "Twixt" at Sensei's Library.
(OC) 2007 the Authors, published under the OpenContent License V1.0.
[Welcome to Sensei's Library!]
StartingPoints
ReferenceSection
About