def is_position_enemy_or_empty(pos: Position, colour: Colour, board: Board) -> bool: """Check if position occupied with enemy piece or empty. Return False if pos is out of the board. """ # Check if pos locates on the board. return Board.is_position_on_board( pos, board) and (PositionsUnderThreat.is_position_enemy( pos, colour, board) or board.is_position_empty(pos))
def is_move_possible(game: Game, move: Move) -> bool: """Check if move possible.""" # Get piece at start position piece = game.board.get_piece(move.start) # Check if figure exists. if piece is None: return False # Check if colours match. if game.turn != piece.colour: return False # Check if x and y vary between 0 (included) and 7 (included) if not Board.is_position_on_board(move.finish, game.board): return False # Make move further_game = GameLogic.make_move(move, game) # Check if check occurs after making move return not GameLogic.is_check(further_game.board, Colour.change_colour(further_game.turn))