The figures illustrate a solution for a game played on a 4x4 board with three blue marbles, three gray holes and one wall. The solution has five moves: 1.) Lift the right side. 2.) Lift the top side. 3.) Lift the bottom side. 4.) Lift the left side. 5.) Lift the top side. Your program should determine the fewest number of moves to drop all the marbles into the correct holes – if such a move sequence is possible. If not it should output ‘No Solution’. For the example given on the first page (and below) it would output ‘5 moves’.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

A Marble Game is played with M marbles on a square board. The board is divided into NxN squares, and
M of those squares contain holes. Marbles and holes are numbered from 1 to M. The goal of the Marble
game is to roll each marble into the hole that has the same number. A game board may contain walls.
Each wall is one unit long and stands between two adjacent unit squares. Two squares are considered
adjacent if and only if they share a side.
At the beginning of the game, all marbles are placed on the board, each in a different square. A “move”
consists of slightly lifting a side of the game board. Then all marbles on the board roll downward toward
the opposite side, each one rolling until it meets a wall or drops into an empty hole, or until the next
square is already occupied by another marble. Marbles roll subject to the following restrictions:
 Marbles cannot jump over walls, other marbles, or empty holes
 Marbles cannot leave the board (The edge is a wall)
 A unit square can contain at most a single marble at any one time.
 When a marble moves into a square with a hole, the marble drops into that hole. The hole is
then filled, and other marbles can subsequently roll over the hole. A marble in a hole can never
leave that hole.
The game is over when each marble has dropped into a hole with the corresponding number.


The figures illustrate a solution for a game played on a 4x4 board with three blue marbles, three gray
holes and one wall. The solution has five moves: 1.) Lift the right side. 2.) Lift the top side. 3.) Lift the
bottom side. 4.) Lift the left side. 5.) Lift the top side.
Your program should determine the fewest number of moves to drop all the marbles into the correct
holes – if such a move sequence is possible. If not it should output ‘No Solution’. For the example given
on the first page (and below) it would output ‘5 moves’.
Input
You program should prompt the user to specify an input file describing the initial configuration of the
marble game board. The first line of the input file contains three numbers: the size N (2 ≤ N ≤ 6) of the
board, the number M (M>0) of marbles, and the number W of walls. Each of the following 2M lines
contains two numbers. The first integer is a row location and the second is a column location. The first
M of those lines represent the locations of the marbles, where marble #1 is on the first line, marble #2 is
on the second, etc. The last M of those lines represent the locations of the holes, with the location of
hole #1 coming first, hole #2 coming second, and so on. Finally, the next W lines represent the wall
locations. Each of those lines contains four integers. The first pair are the row and column of the square
on one side of the wall and the second pair are the row and column. Rows and columns are numbered 0
to N-1.
Sample File:
4 3 1
0 1
1 0
1 2
2 3
2 1
3 2
1 1 1 2
Output
5 moves

A Description
The images on page 1 illustrate this, but the following text describes the process of solving the board in
the minimum number of moves. From the initial board described in the input file on page two we do the
following:
1.) Tip the board left. This causes ball #1 at 0,1 to roll to 0,0. Ball #2 at 1,0 stays where it is against
the left wall. Ball #3 at 1,2 stays where it is because there is a wall between 1,1 and 1,2.
2.) Tip the board down. Ball #2 rolls from 1,0 to 3,0 and hits the bottom. Ball #1 was above #2 at 0,0
and now rolls down to 2,0. Ball #3 rolls from 1,2 down to 3,2. However, hole #3 is located at 3,2.
These two match up, so the ball and hole are removed from the board. 3,2 is now an empty
space.
3.) Tip the board up. Recall ball #1 is above #2 in the first column, so ball #1 moves from 2,0 to 0,0
and ball #2 moves from 3,0 to 1,0.
4.) Tip the board right. Ball #1 rolls from 0,0 all the way over to 0,3. Ball #2 however stops rolling
partway across from 1,0 to 1,1 because it hit the left side of the wall between 1,1 and 1,2.
5.) The last move is to tip the board down. Ball #1 in 0,3 rolls down and hits hole #1 at 2,3 and ball
#2 in 1,1 rolls down and hits hole #2 in 2,1. Both balls fell in matching holes and are removed.
There are no more balls or holes on the board, so the game is over.

2
1
2
1
2
2
3
3
1
1
2
2
2
2
3
3
-
1
l
1
2
2
T
Transcribed Image Text:2 1 2 1 2 2 3 3 1 1 2 2 2 2 3 3 - 1 l 1 2 2 T
Expert Solution
steps

Step by step

Solved in 6 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education