Volume 24, N°3

Backgammon tools in J

2. Wastage

by Howard A. Peelle (hapeelle@educ.umass.edu)

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#boardsMinimum WastageBest board
15155047.068950 0 0 3 5 7
14116287.029410 0 0 3 5 6
13 85686.980280 0 0 3 4 6
12 61886.905510 0 0 2 4 6
11 43686.820850 0 0 2 4 5
10 30036.753220 0 0 2 3 5
9 20026.628950 0 0 2 3 4
8 12876.510140 0 0 1 3 4
7 7926.361020 0 0 1 3 3
6 4626.147340 0 0 1 2 3
5 2525.889670 0 0 1 2 2
4 1265.528020 0 0 1 1 2
3 565.305790 0 0 1 1 1
2 214.620371 0 1 0 0 0
1 64.208330 0 0 0 0 1

Reference

  1. Peelle, Howard A. “Backgammon Tools in J: 1. Bearoff Expected Rolls”, Vector, Vol.24, N°2

Appendix

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

 

 

BAA logo

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…)

comp.lang.apl

Kenneth E. Iverson
Kenneth E. Iverson
1920-2004

Coming up

23 Aug–1 Sep
q training courses New York

13-16 Sep
Technische Universität Berlin
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

YouTube

Valid XHTML 1.0 Strict