Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function that, when given a list of rooks on a chessboard and a square on the chessboard, returns the number of times the
Write a function that, when given a list of rooks on a chessboard and a square on the chessboard, returns the number of times the square is attacked by the rooks. The chessboard is an 8 by 8 grid, with each square a tuple of a column ('a' through 'h') and a row (1 through 8). A rook moves vertically and horizontally, attacking each square on its column or its row (but not both - it can't defend itself). We assume the rooks can pass through each other - a rook on a can attack the square a3 even if there is another rook on a5. The below image highlights all the squares that a particular rook attacks. So using the above image as an example value, if rooks is [('e',4)] and square is ('e',3), the function should return 1 because the square at location is attacked by the one rook. But if rooks is [('e',4)) and square is (f,8), the function should return 0. In other words, numattackingrooks([('e', 4)], ('e',3)) = 1 numattackingrooks([('e',4), ('f',8)) = 0 Hint: You'll want to keep a counter variable during the loop that keeps track of the number of attacking rooks. For each rook, you want to increment the counter (this means increase it by 1) if that rook attacks the square in question. B CTIVITY 6.20.1: Breakout Rooms: Rooks on a Chessboa Load default main.py 5 6 1 def num_attacking_rooks (rooks, square): - 2 3 Rooks is a list of squares, and each square is a tuple of column (which is a string) and row (which is a number). 4 Returns the number of rooks in the rook list which can attach the square. (square_colunn, square_row) - square counter = 0 8 9 for (rook_column, rook_row) in rooks: 10 #add your code here 11 12 return counter 1 hmittinn for grading Below, type
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started