Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python please Write a function that, when given a list of rooks on a chessboard and a square on the chessboard, returns the number

image text in transcribedin python please

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 a8 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 (1,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. 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 a8 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 (1,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

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

What do they need to do differently?

Answered: 1 week ago