Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

p _ idxs - a set of tuples representing pawn locations k - idx - a tuple representing the starting position of a knight Return

p_idxs - a set of tuples representing pawn locations
k-idx - a tuple representing the starting position of a knight
Return a boolean denoting whether the passed in p_idxs and k_idx represent a solveable board
??#3---k----
??#4--p----
??#5-----p--
??#6---p----
??#7--------Row 7: (7,0),(7,1),(7,2),dots(7,7)
k-idx=(3,3)??# Initial knight index
pidxs={(1,3),(2,1),(2,5),(4,2),(5,5),(6,3)}??# Set of pawn indices
This board is solveable. Our knight can capture all 6 pawns with 6 consecutive moves:
(2,5),(1,3),(2,1),(4,2),(6,3),(5,5)
However, the following board is not solveable:
??# 01234567
??#O-....- Row 0: (0,0),(0,1),(0,2),dots(0,7)
??#1--------
??#2-p--p--
??#3---k----
??#4--p----
??#5-----p--
??#6---p---
??#7--------Row 7: (7,0),(7,1),(7,2),dots(7,7)
k-idx=(3,3)??#Initial knight index
pidxs={(2,1),(2,5),(4,2),(5,5),(6,3)}??# Set of pawn indices
There is no way for our knight to capture all 5 pawns in just 5 moves.
Deliverables
Write Unittests
Use TDD on this assignment- write a test, run it, then implement functionality. You will be graded on your
tests. Starter code for
TestHw5.py includes some guidance on tests. Do not use the examples above as boards
in your tests.
Implment valid_moves(k_idx)
valid_moves(k_idx) returns a set of tuples representing all valid moves for a knight at k-idx.
Implement solveable(p_idxs, k_idx):
p_idxs - a set of tuples representing pawn locations
k_idx - a tuple representing the starting position of a knight
Return a boolean denoting whether the passed in p_idxs and k_idx represent a solveable board
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions