Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 need help with Python code with best performance Jafar is playing checkers with his friend Aladdin. Checkers is a board game in which both
need help with Python code with best performance
Jafar is playing checkers with his friend Aladdin. Checkers is a board game in which both players take turns to move their pawns. Jafar has just one pawn left, and he is going to take a final turn, beating as many of Aladdin's pawns as possible.
Pawns in checkers move diagonally. The pawn always moves one step in the upright or upleft direction. If Jafar's pawn moves and its target field is occupied by one of Aladdin's pawns, Aladdin's pawn can be beaten: Jafar's pawn leaps over Aladdin's pawn, taking two steps in the chosen direction and removing Aladdin's pawn from the board. Jarar can beat Aladdin's pawn in this way only when the field beyond Aladdin's pawn is empty.
After beating Aladdin's pawn, Jafar can continue his turn and make another move, but only if he will again beat another one of Aladdin's pawns. Of course, after this additional move, Jafar can continue his turn again by beating another of Aladdin's pawns, and so on for as long as there are further pawns to beat. When it is no longer possible to beat one of Aladdin's pawns, Jafar's turn ends.
For example, in the situation depicted below where Jafar's pawn is white and Aladdin's pawns are black:
Jafar can beat one of Aladdin's pawns by moving his pawn two steps ir the upright direction, and then he can make an additional move, beatin another of Aladdin's pawns in the upleft direction. After this move ther are no more of Aladdin's pawns available to beat, so Jafar's turn ends.
In the following situations:
Jafar cannot beat Aladdin's pawn. In the first case, the field two steps in the upright direction from Jafar's pawn white is occupied by one of Aladdin's pawns black; in the second case, this field is placed outside the board; in the third case, Jafar's pawn cannot move directly upwards; and finally, in the fourth case, Jafar's pawn cannot move in the downright direction.
What is the maximum number of pawns owned by Aladdin that Jafar can beat in his turn?
Write a function:
def solutionB
which, given a square board of size describing Aladdin's and Jafar's pawns, returns the maximum number of pawns Jafar can beat in one turn. If none of Aladdin's pawns can be beaten, the function should return
Jafar's pawn is described by the character, Aladdin's pawns by sharanters and omntv fiplds hvdnts The hnard is descrihed from
nanges saved
Jafar's pawn is described by the character, Aladdin's pawns by characters and empty fields by dots The board is described from top to bottom and from left to right.
For example, given:
dots dots
dots...
dots..
dots.
dotsx.
dotsdots
the function should return Jafar can beat Aladdin's pawn in the upright direction and then another one in the upleft direction
Given:
dots...
xdots
dotsdots
dots..
dots..
the function should return
Assume that:
is an integer within the range ;
all strings in B are made only of the following characters: X andor O;
the board is square;
the board contains exactly one pawn owned by Jafar.
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