Problem 53780. Backgammon #5 - Valid Move?
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):
Which is represented as:
White moves towards point 1, red towards point 24.
Given a board position and a proposed move, this problem rerquires you to establish if the proposed move is a valid move for white, or not.
The input consists of a vector and a string; the vector describes a backgammon board position using the above notation and the string specifies a proposed move for a single stone based on the throw of a single dice, in a simplified standard notation.
For the purpose of this exercise, the move is expressed simply as 'starting_point/destination_point' using the point numbers as above, and using 'bar' if a stone is moving from the bar, and 'off' if a stone is bearing off the board. Some example proposed moves are thus:
You should return true or false, depending on whether the proposed move is valid or not for the given board position. Possible reasons why a move might not be valid include:
- White does not have a stone on the starting_point
- Red has more than one stone on the destination_point
- White has a stone on the bar and the move is not moving that stone off the bar
- White is trying to bear off a stone, but not all white stones are in white's inner table (points 1 to 6)
There are a few more reasons why a move might not be valid, but I'll leave those for you to work out for yourself!
For this problem, you can assume that the board input vector represents a legal backgammon board position.
Previous problem in series: Problem 53850. Backgammon #4 - Dice Probabilities
Next problem in series: Coming soon!
Regexp cheats and other cheats are not appreciated and will be blocked if you use them.
Solution CommentsShow comments
Problem Recent Solvers1