#keine KI
import random
from block_class import Block


def get_highest(block_list):
    lowest_y_node = block_list[0] 
    for i in range(len(block_list)):
        if block_list[i].return_y() < lowest_y_node.return_y():
            lowest_y_node = block_list[i]
    return lowest_y_node
    
    
def gen(blocks, player_pos_y, jump_height, platform_width, platform_spread):
    highest = min(blocks, key=lambda b: b.return_y())
    if player_pos_y < highest.return_y():
        left = max(-36, int(highest.return_x()) - platform_spread)
        right = min(500, int(highest.return_x()) + platform_spread)

        if left >= right:
            left = -36
            right = 500

        new_x = random.randint(left, right)
        new_y = highest.return_y() - 50 + jump_height*0.8
        blocks.append(Block(new_x, new_y, random.randint(1, 50), w=platform_width))
    return blocks