Problem 45967. Backgammon #1 - Pip Count

The following is a possible representation of a backgammon board:
  • White stones are represented by positive integers Red stones represented by negative integers.
  • The board is a vector of integers: The first 24 integers are the points numbered (from White's perspective) 1 to 24; integers 25 and 26 are white's bar and red's bar respectively; integers 27 and 28 are whites home and red's home respectively
  • Each integer represents the number of stones on that point; e.g. 4 means white has 4 stones on that point; -2 means red has 2 stones on that point.
So initial board set-up is (from White's perspective):
Red (X)
+ O X BB X O +
+ O X BB X O +
+ O X BB X +
+ O BB X +
+ O BB X +
+ BB +
+ BB +
+ X BB O +
+ X BB O +
+ X O BB O +
+ X O BB O X +
+ X O BB O X +
White (O)
Which is represented as:
White moves towards point 1, red towards point 24.
The Pip Count rates the relative strength of one player's position against the other's, by counting the total dice throw required to exactly bear off all that player's remaining stones and comparing the relative count of one player against the other to determine which has the stronger position.
The input is a vector describing a backgammon board position using the above notation. You should return a vector containing three elements: white's pip count, red's pipcount and the relative pipcount from white's perspective - i.e. a negative relative pipcount means that white has the stronger position.
Before attempting to calculate the pipcount you should check that the input represents a legal backgammon board position. If it doesn't then you should return NaN for all three output elements.
Regexp cheats and other cheats are not appreciated and will be blocked if you use them.

Solution Stats

4.69% Correct | 95.31% Incorrect
Last Solution submitted on Mar 19, 2022

Solution Comments

Show comments

Problem Recent Solvers3

Suggested Problems

More from this Author17

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!