An image can be represented as a grid of black and white cells. An object in the image is defined as a group of connected black cells that touch on one side (Please note: cells are not connected if they only touch at a corner). The diagram below represents an image that contains two objects, therefore, and one of them consists of a single cell.
A way to test whether a group of cells is an object (within an image) is to ask:
Many drawing or graphic programs include erasing features. With such an eraser tool, an object can be completely erased by double-clicking on that object with a mouse.
This problem involves erasing an object stored as a collection of black squares in a matrix image.
Here is a video explaining the flood fill strategy used in erase object.
The first entry in the provided text file digital.txt is the number of pairs that follow (i.e., 55). Each subsequent line contains a pair of integers, separated by a blank space. Each pair is a row and column coordinate that specifies the location of a black cell in the starting grid. The row and column values range from 1 to 20.
Write a program that accomplishes the following:
Load the text file digital.txt representing the 20 x 20 grid of black and white squares.
Ask the user for the starting coordinate of an attempted erasure. If this starting coordinate is part of an object, the program should erase the entire object (change black to white). If the starting coordinate is out of bounds, you program should do nothing (and not crash). Also, if the starting coordinate is on the edge of the board, your program should not crash out of bounds when calling recursion.
Print out the grid afterwards.
Repeat steps (b) and (c) until the user says they do not want to erase again.
Submit your code below
You must Sign In to submit to this assignment
Last modified: April 24, 2024
Back to The Solution To The Maze Problem