schrum2 / EvoCraft-SCOPE

0 stars 0 forks source link

Refining USE_MIN_BLOCK_REQUIREMENT, especially for snakes #68

Closed schrum2 closed 2 years ago

schrum2 commented 2 years ago

This issue has multiple parts. First, the code for USE_MIN_BLOCK_REQUIREMENT when generating "standard" shapes needs to be refined a bit. Next, the snake evolution code needs to be changed to incorporate the USE_MIN_BLOCK_REQUIREMENT option as well. The code in cppn_generation.py is where most of the changes need to happen.

First, in query_cppn_for_shape, there is a magic number 500 that needs to become a command line parameter MIN_BLOCK_FAILSAFE_ITERATIONS. It's the number of chances given to creating a minimum number of blocks before the presence threshold is just set to negative infinity (meaning that every block will generate).

Next, the minimum block requirement needs to be added to query_cppn_for_snake_shape. The way it works in query_cppn_for_shape is that there is a while loop on the variable done, but the snake code already has this. To incorporate the min block requirement for the snakes, and additional while loop is needed using a different variable than done (it basically serves the same purpose, but the name is already taken). Essentially, you need to put all of the following code from query_cppn_for_snake_shape into the new loop:

    # Used to scale the point
    xi = int(position_information["xrange"]/2)
    yi = int(position_information["yrange"]/2)
    zi = int(position_information["zrange"]/2)

    snake = []
    while not done:
        number_of_iterations += 1
        x = util.scale_and_center(xi,position_information["xrange"])
        y = util.scale_and_center(yi,position_information["yrange"])
        z = util.scale_and_center(zi,position_information["zrange"])
        scaled_point = (x, y, z)
        initial_position = (xi, yi, zi)

        (block, direction, stop) = generate_block(net, position_information, corner, args, block_options, scaled_point, initial_position, presence_threshold)

        if block is not None:
            snake.append(block)

        # Once it has reach the maximum length, it should stop
        if stop or number_of_iterations == args.MAX_SNAKE_LENGTH:
            done = True
        else:
            xi += direction[0]
            yi += direction[1]
            zi += direction[2]

Then, you need to add code similar to what is in query_cppn_for_shape for tracking the number of attempts, decreasing the presence_threshold, and checking if snake generation is actually done (remember that you cannot use the variable done here ... make another one).

alejmedinajr commented 2 years ago

I added the new command line parameter with the time I had left today.

alejmedinajr commented 2 years ago

Placed everything into a new while loop. Seems to be working, no invisible sneks and no more infinite loop.