Volume 24, N°3
J programs are presented as analytical tools for expert backgammon. Part 2 here develops a program to compute the number of pips expected to be wasted while bearing off pieces in one inner board (without contact).
The inner board is represented as a list of six integers. For example, 0 pieces on the 1, 2, and 3 points, 2 on the 4-point, 3 on the 5, and 4 on the 6:
board =: 0 0 0 2 3 4
To count pips for bearing off, sum the board times a list of the point numbers:
,pips =: +/ board * 1 2 3 4 5 6 47
Use program
N
(from [1]) to compute expected number of rolls to bear off:
,n =: N board 6.56681
Expected number of pips to bear off is the expected number of rolls
n
times the average number of pips per roll (8 1/6):
n * 8+1%6 53.6289
Wastage is this expected number of pips minus the pipcount.
,wastage =: (n * 8+1%6) - pips 6.62895
Define a program to compute wastage for any inner board:
Wastage =: (N * 8:+1:%6:) - Pips
Pips =: +/ . * Points
Points =: 1: + i.@6:
For the example above:
Wastage 0 0 0 2 3 4 6.62895
Wastage for all possible full distributions (with all 15 pieces) in the inner board follows:
all =: (6#16) #: i.16^6 boards =: (15 = +/"1 all) # all
(See Appendix for an alternative way to generate these boards using partitions.)
Wastages for all full inner boards are:
wastages =: Wastage"1 boards
The minimum wastage is:
<./wastages 7.06895
The board with minimal wastage is:
boards #~ wastages = <./wastages 0 0 0 3 5 7
Other distributions can be searched similarly:
| # Pieces | #boards | Minimum Wastage | Best board |
|---|---|---|---|
| 15 | 15504 | 7.06895 | 0 0 0 3 5 7 |
| 14 | 11628 | 7.02941 | 0 0 0 3 5 6 |
| 13 | 8568 | 6.98028 | 0 0 0 3 4 6 |
| 12 | 6188 | 6.90551 | 0 0 0 2 4 6 |
| 11 | 4368 | 6.82085 | 0 0 0 2 4 5 |
| 10 | 3003 | 6.75322 | 0 0 0 2 3 5 |
| 9 | 2002 | 6.62895 | 0 0 0 2 3 4 |
| 8 | 1287 | 6.51014 | 0 0 0 1 3 4 |
| 7 | 792 | 6.36102 | 0 0 0 1 3 3 |
| 6 | 462 | 6.14734 | 0 0 0 1 2 3 |
| 5 | 252 | 5.88967 | 0 0 0 1 2 2 |
| 4 | 126 | 5.52802 | 0 0 0 1 1 2 |
| 3 | 56 | 5.30579 | 0 0 0 1 1 1 |
| 2 | 21 | 4.62037 | 1 0 1 0 0 0 |
| 1 | 6 | 4.20833 | 0 0 0 0 0 1 |
Program to compute wastage:
Wastage =: (N * 8:+1:%6:) – (+/ . * 1: + i.@6:)
See [1] for script with definition of N to compute expected number of rolls to bear off.
Co-recursive program to compute all partitions of an integer x into y parts:
ELSE =: ` WHEN =: @.
Partitions =: ;@AllParts
AllParts =: <@Parts"0 >:@i.
Parts =: Ps ELSE (,.@[) WHEN (]=1:)
Ps =: Add1 ELSE (#1:) WHEN =
Add1 =: 1: + ] {."1 – Partitions - <. ]
For example:
8 Partitions 3 8 0 0 7 1 0 6 2 0 5 3 0 4 4 0 6 1 1 5 2 1 4 3 1 4 2 2 3 3 2
Program to produce a table of permutations:
Perms =: i.@! A. i.
All full distributions of 15 pieces on 6 points in an inner board:
boards =: ~. ,/ (Perms 6) {"1/ 15 Partitions 6
Number of full inner boards:
#boards 15504
All wastages:
wastages =. Wastage"1 boards
Average wastage:
Average =: +/ % # Average wastage 15.7857
Minimal wastage:
<./wastages 7.06895
Board with minimal wastage:
boards #~ wastages = <./wastages 0 0 0 3 5 7
Top ten minimal boards:
10 {. boards /: wastages
0 0 0 3 5 7
0 0 1 2 5 7
0 0 1 3 5 6
0 0 0 2 5 8
0 0 1 3 4 7
0 0 0 2 6 7
0 0 0 3 6 6
0 0 0 4 5 6
0 0 0 3 4 8
0 0 1 2 6 6
Next meetings
Vector is the journal of the British APL Association. The BAA promotes the APLs, terse programming languages derived from Iverson’s mathematical notation. (more…)
23 Aug–1 Sep
q training courses
New York
13-16 Sep

APL 2010
Berlin
13-23 Sep
q training courses
London
27 Sep–4 Oct
q training courses
Singapore
18-28 Oct
q training courses
New York
8-18 Nov
q training courses
London
8-20 Dec
q training courses
New York
Web design by
Lambent Technology