(define "IfEnemyBlotIt"
(apply
if:(is Enemy (who at:(to)))
(fromTo
(from (to))
(to (mapEntry (next)))
)
)
)
(define "NotEnemyOrOnlyOne"
(or
(and
(is Enemy (who at:(to)))
(= (topLevel at:(to)) 0)
)
(not (is Enemy (who at:(to))))
)
)
(define "BarEmpty" (= (what at:"Bar") 0))
(define "NextSiteFrom"
(trackSite Move
from:#1
steps:(pips)
)
)
(define "Bar" (mapEntry (mover)))
(define "DieNotUsed" (!= (pips) 0))
(define "AllPieceInHome"
("NoSites"
(difference
(sites Occupied by:Mover)
(sites Mover)
)
)
)
(define "RemoveAPiece"
(move
Remove
(site)
)
)
(define "DieNotUsedAndNoEscapeAndNotOffTheTrack"
(and {
("DieNotUsed")
(!= ("NextSiteFrom" (from)) Off)
(!= ("NextSiteFrom" (from)) End)
})
)
(define "MoveAPiece"
(move
(from #1)
(to
("NextSiteFrom" #1)
if:("NotEnemyOrOnlyOne")
("IfEnemyBlotIt")
)
)
)
(define "MoveAPieceIf"
(forEach Die
replayDouble:true
if:#1
("MoveAPiece" #2)
)
)
(define "AllPieceEscaped" ("NoSites" (sites Occupied by:Mover top:false)))
(define "NumPiece" (size Stack in:(sites Occupied by:#1)))
(define "CanEspace" (= ("NextSiteFrom" (site)) End))
(define "NotEmptyAndNotOffTheBoard"
(and
(!= (what at:(site)) 0)
(!= ("NextSiteFrom" (site)) Off)
)
)
(define "SetScoreOf"
(set Score
#1
(if (is Mover #1)
(if
(= ("NumPiece" #2) 15)
2
1
)
0
)
)
)
(define "HaveAPieceAndCanEscape"
(and
(is Friend (who at:(site)))
(< (trackSite Move from:(site) steps:(pips)) 0)
)
)
//-----------------------------------------------------------------------------
(game "Backgammon"
(players 2)
(equipment
{
(board (rectangle 2 13)
{
(track "Track1" {6 12..7 5..0 13..18 20..25 End} P1 directed:true)
(track "Track2" {19 25..20 18..13 0..5 7..12 End} P2 directed:true)
}
use:Vertex
)
(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
(do
(if (not "SameTurn") (roll))
next:(if "AllPieceInHome"
(forEach Die
replayDouble:true
if:("DieNotUsed")
(forEach Site
(sites Mover)
(if ("NotEmptyAndNotOffTheBoard")
(if ("CanEspace")
("RemoveAPiece")
("MoveAPiece" (site))
)
)
noMoveYet:(firstMoveOnTrack "Track" Mover
(if "HaveAPieceAndCanEscape"
"RemoveAPiece"
)
)
(then
(if (not (all DiceUsed))
(moveAgain)
)
)
)
)
(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 Roman board game XII Scripta and the Persian game Nard. Early boards can be found from around the sixth century in South and Southwest Asia, though other 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 number on one die and other the number on the other die, or by moving one piece the total number of both die. 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.")
(version "1.0.7")
(classification "board/race/escape")
(credit "Eric Piette")
}
)
(graphics {
(board Style backgammon)
(stackType Backgammon)
})
(ai
"Backgammon_ai"
)
)