CMU 15-112 Summer 2020: Fundamentals of Programming and Computer Science
Collab 5 (Due Wed 27-May, at 11:59pm)
- This assignment is COLLABORATIVE. This means you may work with your week's collaboration group within the course collaboration boundaries. See the syllabus for details.
- To start:
- Create a folder named 'collab5'
- Download collab5.py and cs112_m20_unit5_linter.py to that folder
- Edit collab5.py using VSCode
- When you are ready, submit collab5.py to Autolab. For this hw, you may submit up to 10 times, which is fewer times than you've had in the past but only your last submission counts.
- Do not use sets, dictionaries, or recursion in this assignment.
- Do not hardcode the test cases in your solutions.
- NOTE: We are not providing any test functions in this homework. That means that you need to write complete test functions for areLegalValues and isKingsTour.
- NOTE: This homework is going to be graded for style. Make sure that you adhere to the style guide when you're working on this HW, and double check your file against the style guide before you submit to Autolab!
- areLegalValues(values) [15 pts]
With your group, read the problem statement for isLegalSudoku from hw5. Understand the terminology, our board representation, and the generalization we've made. Then, as part of collab5, write the areLegalValues(values) helper function. You may use this function as a helper in your hw5 file. - isKingsTour(board) [15 pts]
Background: in Chess, a King can move from any square to any adjacent square in any of the 8 possible directions. A King's Tour is a series of legal King moves so that every square is visited exactly once. We can represent a Kings Tour in a 2d list where the numbers represent the order the squares are visited, going from 1 to N2. For example, consider these 2d lists:[ [ 3, 2, 1 ], [ [ 1, 2, 3 ], [ [ 3, 2, 1 ], [ 6, 4, 9 ], [ 7, 4, 8 ], [ 6, 4, 0 ], [ 5, 7, 8 ] ] [ 6, 5, 9 ] ] [ 5, 7, 8 ] ]
The first is a legal Kings Tour but the second is not, because there is no way to legally move from the 7 to the 8, and the third is not, because it contains a 0 which is out of range. Also, this should work not just for 3x3 boards but for any NxN board. For example, here is a legal Kings Tour in a 4x4 board:[ [ 1, 14, 15, 16], [ 13, 2, 7, 6], [ 12, 8, 3, 5], [ 11, 10, 9, 4] ]
With this in mind, write the function isKingsTour(board) that takes a 2d list of integers, which you may assume is NxN for some N>0, and returns True if it represents a legal Kings Tour and False otherwise.