Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 1 0 0 Marks there are no other pieces on the board ) . A move is valid if the plece can move

Question 1
100 Marks there are no other pieces on the board). A move is valid if the plece can move folls within the fol squares of the board, labeled from 'a' to 'h' horizontally and '1' to '8' vertically. A move from 'a8' to 'h1' means that the piece intends to move from the upper left corner of the board to the lower right corner.
For the purposes of testing, the order of the horizontal/vertical board positions may be transposed ('8a' and 'a8' are equal), and you must perform error checking on the input to ensure it is within the range of the board.
You should handle the following pieces in your implementation, with each piece's implementation being worth 15 marks: King, Queen, Bishop, Rook (Castle), Knight (Horse)
Before you begin, think about valuable functions to build. Small parts of the more extensive program that you can extract that you will need for all the pieces. You should have one helper function for each piece (named as you choose, with parameters of your choosing), and other functions as you see fit.
The final 25 marks will be allocated to:
checking for proper positions
controlling for alternate inputs ('a8' vs '8a')
controlling for other incorrect inputs('a10','10aaa', 'hhhh')
incorrect input should return False
def is_move_valid(piece:str, current_location:str, destination:str) bool:
# YOUR IMPLEMENTATION
Examples of the function running should appear as follows:
> is_move_valid('Queen','a7','a1')
True
is_move_valid('queen','(:7A',?'A1'}
True
is_move_valid('king','A7','C8')
False
is_move_valid('knight','A7','C8')
True
is_move_valid('knight','AA','C8') # AA is an invalid position
False
is_move_valid('knight','A7','C9') # c9 is an invalid square
False
is_move_valid('hammer','A7','A1') # a hammer is not a piece
False
3
3
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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

Students also viewed these Databases questions