Модуль NEAT в python. В чём ошибка?
Подскажите пожалуйста в чём ошибка в коде. Решил написать змейку которая играет сама в себя с помощью модуля neat. Вот код на питон и вот код конфигурации.
import random
import neat
# Глобальные переменные
max_score = 0
box_height = 20 # Высота поля игры
box_width = 40 # Ширина поля игры
snake = [(1, 1), (1, 2), (1, 3)] # Начальное положение змейки
food = (5, 10) # Начальное положение еды
# Функция для создания новой еды
def create_food(snake):
food = None
while food is None:
food = (random.randint(1, box_height - 2), random.randint(1, box_width - 2))
if food in snake:
food = None
if food is None:
food = (1, 1) # Задаем координаты еды по умолчанию
return food
# Функция для движения змейки
def move(direction, snake):
head = snake[0]
y, x = head
if direction == "UP":
new_head = (y - 1, x)
elif direction == "DOWN":
new_head = (y + 1, x)
elif direction == "LEFT":
new_head = (y, x - 1)
elif direction == "RIGHT":
new_head = (y, x + 1)
return [new_head] + snake[:-1]
# Функция для проверки столкновений
def check_collision(snake):
head = snake[0]
if head in snake[1:] or head[0] in [0, box_height - 1] or head[1] in [0, box_width - 1]:
return True
return False
# Основная функция игры
def run_game(genomes, config):
global max_score
max_score = 0
for genome_id, genome in genomes:
net = neat.nn.FeedForwardNetwork.create(genome, config)
direction = "RIGHT"
score = 0
snake = [(1, 1), (1, 2), (1, 3)] # Начальное положение змейки
food = create_food(snake)
while True:
inputs = [snake[0][0], snake[0][1], food[0], food[1]]
output = net.activate(inputs)
direction_index = output.index(max(output))
if direction_index == 0:
direction = "UP"
elif direction_index == 1:
direction = "DOWN"
elif direction_index == 2:
direction = "LEFT"
elif direction_index == 3:
direction = "RIGHT"
snake = move(direction, snake)
if check_collision(snake):
break
if snake[0] == food:
snake.append(snake[-1])
food = create_food(snake)
score += 1
max_score = max(max_score, score)
genome.fitness = score
# Настройка NEAT
config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
'config.txt')
population = neat.Population(config)
# Запуск NEAT
population.run(run_game, 50)
[NEAT]
fitness_criterion = max
fitness_threshold = 3.9
pop_size = 150
reset_on_extinction = False
[DefaultGenome]
# node activation options
activation_default = sigmoid
activation_mutate_rate = 0.0
activation_options = sigmoid
# node aggregation options
aggregation_default = sum
aggregation_mutate_rate = 0.0
aggregation_options = sum
# node bias options
bias_init_mean = 0.0
bias_init_stdev = 1.0
bias_max_value = 30.0
bias_min_value = -30.0
bias_mutate_power = 0.5
bias_mutate_rate = 0.7
bias_replace_rate = 0.1
# genome compatibility options
compatibility_disjoint_coefficient = 1.0
compatibility_weight_coefficient = 0.5
# connection add/remove rates
conn_add_prob = 0.5
conn_delete_prob = 0.5
# connection enable options
enabled_default = True
enabled_mutate_rate = 0.01
feed_forward = True
initial_connection = full
# node add/remove rates
node_add_prob = 0.2
node_delete_prob = 0.2
# network parameters
num_hidden = 0
num_inputs = 4
num_outputs = 1
# node response options
response_init_mean = 1.0
response_init_stdev = 0.0
response_max_value = 30.0
response_min_value = -30.0
response_mutate_power = 0.0
response_mutate_rate = 0.0
response_replace_rate = 0.0
# connection weight options
weight_init_mean = 0.0
weight_init_stdev = 1.0
weight_max_value = 30
weight_min_value = -30
weight_mutate_power = 0.5
weight_mutate_rate = 0.8
weight_replace_rate = 0.1
[DefaultSpeciesSet]
compatibility_threshold = 3.0
[DefaultStagnation]
species_fitness_func = max
max_stagnation = 20
species_elitism = 2
[DefaultReproduction]
elitism = 2
survival_threshold = 0.2
и вся эта история выдаёт ошибку '>' not supported between instances of 'NoneType' and 'NoneType'. Буду очень признателен если поможете)))