Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def splitting(board): #<--splitting board on 2D matrix
- for row in range(len(board)):
- board[row]=list(board[row])
- print(board)
- return board
- def find_char(matrix,char): #<-- looking for position of jaffar's pawn
- jaffars_pawn = [(index, row.index(char)) for index, row in enumerate(matrix) if char in row]
- print(jaffars_pawn)
- return jaffars_pawn #<-- return as tupel in list, in case of many pawns but only one in signle row
- def attack(jaffar_position,board): #<- main function which ger points when Jaffar's pawn are able to beat Aladdin pawn
- board = splitting(board)
- len_board = len(board)
- y , x = jaffar_position[0]
- points = 0
- play = True
- while play: #<-loop until next beat dosen't occur
- if ((x+2<len_board-1 or x-2 >= 0) and y-2>=0): #<- chceking that attack jaffar's pawn dosen't move to the outside of board
- if (board[y-1][x+1] == "X" and not board[y-2][x+2] == "X"):#<- checking if jaffar's pawn can attack up-right direction
- points+=1
- x , y = x + 2, y - 2
- continue
- if (board[y-1][x-1] == "X" and not board[y-2][x-2] == "X"): #<- checking if jaffar's pawn can attack up-left direction
- points+=1 #<- counting points
- x ,y = x - 2, y - 2 #<- move jaffar's pawn
- continue
- else: play=False #<- when Jaffar's pawn can't attack next Aladdin's pawn
- else: play=False
- return points
- def solution(B):
- jaffar_char="O"
- return attack(find_char(splitting(B),jaffar_char),B)
- A =['.X.....',
- '..X.X..',
- '.X..X..',
- '....X..',
- '...X...',
- '..X.X.X',
- '...O...']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement