(define "IfEnemyBlotIt" ("HittingCapture" (mapEntry (next))))
(define "BarEmpty" (is Empty "Bar"))
(define "NextSiteFrom" ("NextSiteOnTrack" (pips) from:#1))
(define "Bar" (mapEntry (mover)))
(define "AllPieceInHome" ("AllOwnedPiecesIn" (sites Mover)))
(define "RemoveAPiece" (move Remove (site)))
(define "DieNotUsedAndNoEscapeAndNotOffTheTrack"
(and {
("DieNotUsed")
("IsNotOffBoard" ("NextSiteFrom" (from)))
(not ("IsEndTrack" ("NextSiteFrom" (from))))
})
)
(define "MoveAPiece"
(move
(from #1)
(to
("NextSiteFrom" #1)
if:("NoEnemyOrOnlyOne" (to))
("IfEnemyBlotIt")
)
)
)
(define "MoveAPieceIf"
(forEach Die
replayDouble:True
if:#1
("MoveAPiece" #2)
)
)
(define "AllPieceEscaped" (no Pieces Mover))
(define "NumPiece" (size Stack in:(sites Occupied by:#1)))
(define "CanEscape" ("IsEndTrack" ("NextSiteFrom" (site))))
(define "NotEmptyAndNotOffTheBoard"
(and
(is Occupied (site))
("IsNotOffBoard" ("NextSiteFrom" (site)))
)
)
(define "SetScoreOf"
(set Score
#1
(if (is Mover #1)
(if
(= ("NumPiece" #2) 15)
2
1
)
0
)
)
)
(define "HaveAPieceAndCanEscape"
(and
("IsFriendAt" (site))
(< ("NextSiteOnTrack" (pips) from:(site)) 0)
)
)
//-----------------------------------------------------------------------------
(game "Backgammon"
(players 2)
(equipment {
("BackgammonBoard" ("BackgammonTracksWithBar" End))
(dice num:2)
(regions P1 { 20..25 }) // P1 Home
(regions P2 { 7..12 }) // P2 Home
(map {(pair 1 6) (pair 2 19)}) // Bar
(piece "Disc" Each ("MoveAPieceIf" "DieNotUsedAndNoEscapeAndNotOffTheTrack" (from)))
})
(rules
(start {
(place Stack "Disc1" 0 count:5) (place Stack "Disc1" 12 count:2)
(place Stack "Disc1" 17 count:3) (place Stack "Disc1" 20 count:5)
(place Stack "Disc2" 4 count:3) (place Stack "Disc2" 7 count:5)
(place Stack "Disc2" 13 count:5) (place Stack "Disc2" 25 count:2)
})
(play
("RollEachNewTurnMove"
(if "AllPieceInHome"
(forEach Die
replayDouble:True
if:("DieNotUsed")
(forEach Site
(sites Occupied by:Mover)
(if ("NotEmptyAndNotOffTheBoard")
(if ("CanEscape")
("RemoveAPiece")
("MoveAPiece" (site))
)
)
noMoveYet:(firstMoveOnTrack "Track" Mover
(if "HaveAPieceAndCanEscape"
"RemoveAPiece"
)
)
(then ("ReplayNotAllDiceUsed"))
)
)
(max Distance "Track" Mover
(if "BarEmpty"
(forEach Piece top:True)
("MoveAPieceIf" ("DieNotUsed") ("Bar"))
(then
(if (not (all DiceUsed))
(if (can Move
(if "BarEmpty"
(forEach Piece top:True)
("MoveAPieceIf" ("DieNotUsed") ("Bar"))
)
)
(moveAgain)
)
)
)
)
)
)
)
)
(end
(if ("AllPieceEscaped")
(result Mover Win)
)
)
)
)
//-------------------------------------------------------------------------
(metadata
(info
{
(description "Backgammon as it is known today seems to have been invented around the seventeenth century, but the games from which it developed are much older. The origins of these games lie sometime in the early centuries CE, and it is related to the Persian game Nard. Other related games such as Tric-Trac and Tables were also been played on the same board in medieval and early modern Europe.")
(rules "The game is played on a board with twelve points on either side. The points form a continuous track in a horseshoe shape; each player progresses in opposite directions (one from their bottom right to the top right, the other from their bottom left to their top left. Each player has 15 pieces. The starting position is as such, number the points from the origin of each player's track: Point six: five pieces Point 8: three pieces Point 13: five pieces Point 24: two pieces Play begins by each player rolling one die; the player with the highest roll plays first and plays the numbers on this first roll. Players move according to the number on each die by moving one piece the value on one die then another piece the value on the other die, or by moving one piece the value of one die and then the value of the other. If doubles are rolled, the player must play the number on each die twice. Players cannot end their move on a point with multiple opposing pieces. If a player ends the turn on a point with one opposing piece, that piece is placed in the middle of the board (not on a point) and must reenter the board according the the next die roll, counting the origin point as a move of 1. They cannot reenter on a point with two or more pieces. No other pieces can move until all of the pieces belonging to that player are removed from the center. When all of a player's pieces are on their final 6 points, they may start removing pieces from the board. They can do so by rolling a 6 to move from the 6th point, and so on down to 1. Players must use all available moves presented by the dice. The first player to remove all of their pieces wins.")
(source "Murray 1951: 122.")
(id "76")
(version "1.3.13")
(classification "board/race/escape")
(credit "Eric Piette")
}
)
(graphics {
(board Style backgammon)
(stackType Backgammon)
})
(ai
"Backgammon_ai"
)
)