Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Playing partitions Partitions again?? Man I ' m getting sick of these things. I ' m sure you are too. But this time we're going
Playing partitions
Partitions again?? Man Im getting sick of these things. Im sure you are too. But this
time we're going to do something a little different. We're going to play a game with
them. Or at least, we're going to study a game that could be played with them.
A position in this game is simply a Ferrers board, and a move is exactly one of the moves
described in Pathfinding partitions. The game is played by two players, who take turns
making moves. The game is defined by a starting position, and a list of target positions.
The winner is the first player to achieve one of the target positions. The game is drawn
if each player can prevent the other from achieving a target position.
Task
Write a program that takes input from stdin a data file formatted according to the rules
of the Parsing Partitions tude where each scenario in the file will consist of a starting
position, and a list of target positions. The starting position will never be one of the
target positions. The output to stdout should be in standard form. Each scenario
should be represented by the starting position, a blank line, the list of target positions,
and then a single comment line which is one of the following:
# WIN
# LOSE
# DRAW
indicating the outcome of the game from the starting position for the first player as
suming that both players are trying to win if possible.playing partitions
Partitions are represented as a single line eg
would be
x x x
x x
x
The best approach recommended to to work on the moves backwards and go from the target to win to the starting partition and keeping track of what will be a winning position for player that goes first, what will be a losing position or a draw for both players playing the game.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started