Twix  T
1 Twix  T Boards
twixt-board?
empty-twixt-board
sample-twixt-board
twixt-board
twixt-board-get-peg
twixt-board-put-all-pegs
twixt-board-pegs
twixt-board-occupied-positions
twixt-board-links
1.1 Twix  T Board Positions
twixt-position?
twixt-position
twixt-position-row
twixt-position-column
standard-twixt-board-size
twixt-index/  c
2 Twix  T Players
twixt-player?
red
black
3 Twix  T Pegs
twixt-peg?
twixt-peg
red-twixt-peg
black-twixt-peg
twixt-peg-owner
twixt-peg-position
twixt-peg-links
twixt-peg-link-directions
3.1 Twix  T Peg Links
twixt-link?
twixt-link
twixt-link-owner
twixt-link-left-end
twixt-link-right-end
twixt-link-direction?
up-left-link
up-right-link
right-up-link
right-down-link
down-right-link
down-left-link
left-down-link
left-up-link
4 Drawing Twix  T Games
twixt-board-pict
twixt-stylesheet?
standard-twixt-stylesheet
monochrome-twixt-stylesheet
8.12

TwixT🔗ℹ

 (require twixt) package: twixt

TwixT is an abstract, turn-based, two-player board game in which players try to connect their two sides of the board while preventing the opponent from doing the same. The twixt library provides a basic data model for representing, displaying, and playing TwixT games.

1 TwixT Boards🔗ℹ

A TwixT board is a 24-by-24 rectangular board on which games of TwixT are played. Each space of the board contains a hole, in which a TwixT peg may be placed. The four corner spaces of the board do not contain holes; pegs cannot be placed in corners. The non-corner spaces on the edge of the board make up the TwixT border rows, and each player controls two rows on opposite sides of the board.

procedure

(twixt-board? v)  boolean?

  v : any/c
A predicate for TwixT boards.

The empty TwixT board, which contains no pegs or links.

Example:

Creates a random TwixT board with a few pegs and links on it. This function is mostly intended for REPL experimentation and for example boards in Scribble documentation.

Currently, this function occasionally produces illegal boards. Hopefully that will be fixed someday.

Example:

procedure

(twixt-board peg ...)  twixt-board?

  peg : twixt-peg?
Constructs a TwixT board with each peg (and its associated links) inserted into the board. Pegs cannot overlap with each other, nor can their links. Any peg with a link must have a corresponding peg at the link’s destination, although that peg need not include a link back to the source peg.

Example:
> (twixt-board-pict
   (twixt-board
    (red-twixt-peg #:row 8 #:column 9 right-down-link)
    (red-twixt-peg #:row 9 #:column 11)
    (red-twixt-peg #:row 11 #:column 10 up-right-link)
    (black-twixt-peg #:row 15 #:column 12)
    (black-twixt-peg #:row 13 #:column 11 down-right-link)))

image

procedure

(twixt-board-get-peg board position)  (option/c twixt-peg?)

  board : twixt-board?
  position : twixt-position?
Returns the TwixT peg at position of board, if there is one.

Examples:
(define board (twixt-board (red-twixt-peg #:row 9 #:column 11)))

 

> (twixt-board-get-peg board (twixt-position #:row 9 #:column 11))

(present

 (twixt-peg

   #:link-directions (set)

   #:owner #<twixt-player:red>

   #:position (twixt-position #:column 11 #:row 9)))

> (twixt-board-get-peg board (twixt-position #:row 4 #:column 18))

#<absent>

procedure

(twixt-board-put-all-pegs board pegs)  twixt-board?

  board : twixt-board?
  pegs : (sequence/c twixt-peg?)
Puts each TwixT peg in pegs onto board at the peg’s position. Two pegs on a board cannot occupy the same position, and links must be connected to pegs on both ends. If either of these conditions is violated, a contract failure is raised. Links between pegs cannot overlap, but enforcement of this property is not yet implemented.

Examples:
(define board (twixt-board (red-twixt-peg #:row 9 #:column 11)))

 

> (twixt-board-pict
   (twixt-board-put-all-pegs
    board
    (list (red-twixt-peg #:row 7 #:column 12 down-left-link)
          (red-twixt-peg #:row 10 #:column 13 left-up-link)
          (red-twixt-peg #:row 10 #:column 9 right-up-link)
          (red-twixt-peg #:row 12 #:column 14 up-left-link))))

image

procedure

(twixt-board-pegs board)  (set/c twixt-peg?)

  board : twixt-board?
Returns a set of all TwixT pegs placed on board.

Examples:
(define board (sample-twixt-board))

 

> (twixt-board-pegs board)

(set

 (twixt-peg

   #:link-directions (set #<twixt-link-direction:right-up-link>)

   #:owner #<twixt-player:red>

   #:position (twixt-position #:column 18 #:row 11))

 (twixt-peg

   #:link-directions (set #<twixt-link-direction:left-down-link>)

   #:owner #<twixt-player:red>

   #:position (twixt-position #:column 20 #:row 10))

 (twixt-peg

   #:link-directions (set #<twixt-link-direction:right-up-link>)

   #:owner #<twixt-player:black>

   #:position (twixt-position #:column 14 #:row 9))

 (twixt-peg

   #:link-directions (set #<twixt-link-direction:left-down-link>)

   #:owner #<twixt-player:black>

   #:position (twixt-position #:column 16 #:row 8)))

> (twixt-board-pict board)

image

procedure

(twixt-board-occupied-positions board)

  (set/c twixt-position?)
  board : twixt-board?
Returns a set of all positions on board that are occupied by TwixT pegs.

Examples:
(define board (sample-twixt-board))

 

> (twixt-board-occupied-positions board)

(set

 (twixt-position #:column 3 #:row 15)

 (twixt-position #:column 4 #:row 17)

 (twixt-position #:column 16 #:row 16)

 (twixt-position #:column 18 #:row 15))

> (twixt-board-pict board)

image

procedure

(twixt-board-links board)  (set/c twixt-link?)

  board : twixt-board?
Returns a set of all TwixT links between pegs on board.

Examples:
(define board (sample-twixt-board))

 

> (twixt-board-links board)

(set

 (twixt-link

   #:left-end (twixt-position #:column 6 #:row 17)

   #:owner #<twixt-player:black>

   #:right-end (twixt-position #:column 7 #:row 15))

 (twixt-link

   #:left-end (twixt-position #:column 7 #:row 8)

   #:owner #<twixt-player:red>

   #:right-end (twixt-position #:column 9 #:row 7)))

> (twixt-board-pict board)

image

1.1 TwixT Board Positions🔗ℹ

A TwixT position is a space on a TwixT board. Each board has 24 rows and columns, so positions are represented by a pair of integers between 0 and 23, with the top-left corner of the board corresponding to row zero and column zero.

procedure

(twixt-position? v)  boolean?

  v : any/c
A predicate for TwixT positions.

procedure

(twixt-position #:row row #:column column)  twixt-position?

  row : twixt-index/c
  column : twixt-index/c
Constructs a TwixT position for the space that is row spaces below and column spaces to the right of the top left corner of the board. Can also be used as a match expander.

Examples:
> (twixt-board-pict (twixt-board (black-twixt-peg #:row 4 #:column 0)))

image

> (twixt-board-pict (twixt-board (red-twixt-peg #:row 1 #:column 3)))

image

procedure

(twixt-position-row position)  twixt-index/c

  position : twixt-position?
Returns the row of position.

procedure

(twixt-position-column position)  twixt-index/c

  position : twixt-position?
Returns the column of position.

A constant for the length of each side of a TwixT board. Boards are always square shaped.

A flat contract for integers that are within the bounds of a TwixT board, and can be used to reference positions on the board.

2 TwixT Players🔗ℹ

There are two players in a game of TwixT, referred to as red and black. The red player always moves first. Note that the actual color of the displayed pieces may be different due to the use of a non-standard stylesheet such as monochrome-twixt-stylesheet. Regardless of the actual piece color, the player who moves first is called the red player.

procedure

(twixt-player? v)  boolean?

  v : any/c
A predicate for TwixT players.

Constants for the red and black TwixT players. The red player always moves first.

3 TwixT Pegs🔗ℹ

A TwixT peg is a piece owned by one of the two TwixT players and placed somewhere on a TwixT board. Each peg may have TwixT links attaching it to the player’s other pegs.

procedure

(twixt-peg? v)  boolean?

  v : any/c
A predicate for TwixT pegs.

procedure

(twixt-peg #:owner owner    
  #:position position    
  #:link-directions links)  twixt-peg?
  owner : twixt-player?
  position : twixt-position?
  links : (sequence/c twixt-link-direction?)
Constructs a TwixT peg at position and owned by owner. Each link in links specifies a direction in which the peg is linked to another peg. Can also be used as a match expander.

This is a general-purpose constructor for twixt pegs. When the owning player and set of links are statically known, using red-twixt-peg or black-twixt-peg may be more readable.

procedure

(red-twixt-peg #:row row    
  #:column column    
  link ...)  twixt-peg?
  row : twixt-index/c
  column : twixt-index/c
  link : twixt-link-direction?
Constructs a TwixT peg at row and column, owned by the red player. Each link specifies a direction in which the peg is linked to another peg.

Example:
> (twixt-board-pict
   (twixt-board
    (red-twixt-peg #:row 10 #:column 12
                   up-right-link
                   down-right-link
                   left-up-link)
    (red-twixt-peg #:row 8 #:column 13)
    (red-twixt-peg #:row 12 #:column 13)
    (red-twixt-peg #:row 9 #:column 10)))

image

procedure

(black-twixt-peg #:row row    
  #:column column    
  link ...)  twixt-peg?
  row : twixt-index/c
  column : twixt-index/c
  link : twixt-link-direction?
Constructs a TwixT peg at row and column, owned by the black player. Each link specifies a direction in which the peg is linked to another peg.

Example:
> (twixt-board-pict
   (twixt-board
    (black-twixt-peg #:row 14 #:column 7 right-down-link)
    (black-twixt-peg #:row 15 #:column 9 right-up-link)
    (black-twixt-peg #:row 14 #:column 11 up-right-link)
    (black-twixt-peg #:row 12 #:column 12)))

image

procedure

(twixt-peg-owner peg)  twixt-player?

  peg : twixt-peg?
Returns the player that owns peg.

procedure

(twixt-peg-position peg)  twixt-position?

  peg : twixt-peg?
Returns the position where peg is placed on the board.

procedure

(twixt-peg-links peg)  (set/c twixt-link?)

  peg : twixt-peg?
Returns the set of TwixT links attached to this peg.

Returns the set of directions in which peg is linked to other pegs.

3.1 TwixT Peg Links🔗ℹ

A TwixT link is a link between two TwixT pegs owned by the same player. Linked pegs must always be a knight’s move apart, meaning two spaces apart horizontally and one space apart vertically or vice-versa.

procedure

(twixt-link? v)  boolean?

  v : any/c
A predicate for TwixT links.

procedure

(twixt-link #:owner owner    
  #:left-end left-end    
  #:right-end right-end)  twixt-link?
  owner : twixt-player?
  left-end : twixt-position?
  right-end : twixt-position?
Constructs a TwixT link between left-end and right-end and owned by owner. The column of left-end must be less than that of right-end. Can also be used as a match expander.

procedure

(twixt-link-owner link)  twixt-player?

  link : twixt-link?
Returns the TwixT player that owns link.

procedure

(twixt-link-left-end link)  twixt-position?

  link : twixt-link?
Returns the position of the left end of link.

procedure

(twixt-link-right-end link)  twixt-position?

  link : twixt-link?
Returns the position of the right end of link.

procedure

(twixt-link-direction? v)  boolean?

  v : any/c
A predicate for the directions in which a peg may link to another peg.

Constants for the eight directions in which one TwixT peg may link to another. Each link travels two spaces in the first direction of it’s name, then one space in the second direction.

4 Drawing TwixT Games🔗ℹ

procedure

(twixt-board-pict board    
  [#:stylesheet styles])  pict?
  board : twixt-board?
  styles : twixt-stylesheet? = standard-twixt-stylesheet
Draws board using styles to control the size and colors of the pieces.

Example:

procedure

(twixt-stylesheet? v)  boolean?

  v : any/c
A predicate for TwixT stylesheets, which control various aspects of how TwixT boards are drawn. The two built-in stylesheets are standard-twixt-stylesheet and monochrome-twixt-stylesheet.

A stylesheet that draws TwixT boards in the clasic red-and-black style. This is the default stylesheet.

A stylesheet that draws TwixT boards in black and white. White goes first.

Example:
> (twixt-board-pict (sample-twixt-board)
                    #:stylesheet monochrome-twixt-stylesheet)

image