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)
+-13-14-15-16-17-18-BB-19-20-21-22-23-24-+
+ O X BB X O +
+ O X BB X O +
+ O X BB X +
+ O BB X +
+ O BB X +
+ BB +
+===================BB===================+
+ BB +
+ X BB O +
+ X BB O +
+ X O BB O +
+ X O BB O X +
+ X O BB O X +
+-12-11-10-09-08-07-BB-06-05-04-03-02-01-+
White (O)
Which is represented as:
Board=[-2,0,0,0,0,5,0,3,0,0,0,-5,5,0,0,0,-3,0,-5,0,0,0,0,2,0,0,0,0];
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.
Next problem in series: Problem 46006. Backgammon #2 - Your turn!
Regexp cheats and other cheats are not appreciated and will be blocked if you use them.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers3
Suggested Problems
-
228 Solvers
-
Getting the row and column location from a matrix
284 Solvers
-
Find out total non zero element of matrix
267 Solvers
-
958 Solvers
-
Matrix of almost all zeros, except for main diagonal
181 Solvers
More from this Author17
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!