Problem 46006. Backgammon #2 - Your turn!

A previous problem in this occasional series (Problem 45967) set up 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.
A possible approach, when developing algorithms to determine valid moves, strategies, etc. is only to code them so that they operate from white's perspective. This avoids having to have algorithms work 'in both directions' and thus simplifies their development.
What this will mean, however, is that when it is red's turn, the board has to be 'flipped' so that red 'becomes' white and vice versa. The move/strategy algorithms can then be applied to this flipped board, and then the board 'flipped' back for white's turn.
The input is a vector describing a backgammon board position using the above notation. You should return a vector which is the flipped board in the same notation.
Before attempting to flip the board, you should check that the input represents a legal backgammon board position. If it doesn't then you should return NaN instead.
Previous problem in series: Problem 45967. Backgammon #1- Pip Count
Regexp cheats and other cheats are not appreciated and will be blocked if you use them.

Solution Stats

13.33% Correct | 86.67% Incorrect
Last Solution submitted on Mar 19, 2022

Solution Comments

Show comments

Problem Recent Solvers2

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!