Concepts: CS 1120 (Python) - Spring 2022 Alice's Flat Planet
Concepts: CS 1120 (Python) - Spring 2022 Alice's Flat Planet
Concepts: CS 1120 (Python) - Spring 2022 Alice's Flat Planet
Concepts
Recursion
Base and General Cases
Divide, Conquer and Glue
Problem Specification
Alice lives on a flat planet that can be modeled as a square grid of size n×n, with rows and columns
enumerated from 0 to n-1. We represent the cell at the intersection of row r and column c with
ordered pair (r,c). Each cell in the grid is either land or water.
Alice resides in land cell (r0,c0). She wishes to travel to land cell (r1,c1). At any moment, she may move
to one of the cells adjacent to where she is—in one of the four directions (i.e., N, E, S, or W).
An example planet with n=5. It also appears in the first two sample tests.
Unfortunately, Alice cannot swim, and there are no viable transportation means other than by foot (i.e.,
she can walk only on land). As a result, Alice's trip may be impossible.
For now, your task is to output a path as a list so that Alice could travel from (r0,c0) to (r1,c1). If Alice’s
trip is impossible, the output path should be an empty list, [].
Input
The first line contains one integer n(1≤n≤50) — the width of the square grid.
CS 1120 (Python) - Spring 2022 LA2 Alice’s flat planet
Examples:
Input:
5
00
03
00001
11111
00111
00110
00110
Output:
[(0,0),(0,1),(0,2),(0,3)]
Input:
5
00
44
00001
11111
00111
00110
00110
Output:
[]
Input:
8
73
13
00000000
CS 1120 (Python) - Spring 2022 LA2 Alice’s flat planet
00000000
00111000
00101000
00101000
00000000
00000000
00000000
Output:
[(7, 3), (6, 3), (5, 3), (5, 4), (5, 5), (4, 5), (3, 5), (2, 5), (1, 5), (0, 5), (0, 4), (1, 4), (1, 3)]
Design Requirements
Basic Structure
You will write two functions. One is named create_map_find_path and other is find_path.
Function create_map_find_path(file_name) does the following tasks:
parse the input file given by parameter file_name to create a land/water grid map stored in a
global variable,
Call the find_path(…) function with the appropriate arguments based on the input file and the
above function specification, AND
Simply return the path returned by function find_path(…).
Function print_path(pathList) prints out the path given by parameter pathList. This function is provided
by us and please feel free to call it.
A template main.py has been given to you.
Pseudocode
You must MUST follow the Divide- Conquer -Glue strategy for function find_path(…) and design a
pseudo code based on that.
Implementation Phase
Using the pseudocode developed, write the Python code for your assignment. This is a two-week
assignment.
CS 1120 (Python) - Spring 2022 LA2 Alice’s flat planet
Testing Phase
You have given plenty example inputs with desired outputs. The output should match exactly.
Build your program incrementally, carefully testing each function as you go.
Assignment Submission
Generate a .zip file that contains all your files including:
o Program Files
o Any input or output files
o Application of the DCG strategy for function find_path(…).