-1

I can't get the NEAT algo. Need someone to take my simple game made for human and add NEAT to it using NEAT-python library.

Game - neural network must write a number that should be close to the randomly generated number in each round. Closer guess = better score and higher fitness. If you select randomly generated number you get punishment. Simple, right? But can't understand how to implement the NEAT.

Here in the code the smaller the number the better. Here is the code:

import os
import math
import sys
import neat
import random
#idea = closer user input to the random number the better;
#if input of the user is the number itself it is bad;

class Agent():

    def __init__(self):
        super().__init__()
        self.my_fitness = 0

    def input(self):
        user_input = int(input())
        if target_n[0] > user_input:
            dif = target_n[0] - user_input
        else:
            dif = user_input - target_n[0]
        self.my_fitness = self.my_fitness - dif



bro1 = Agent() #make Agent

def eval_genomes():

    #main loop
    run = True
    while run == True:

        #set up
        global target_n
        target_n = random.sample(range(1,100),1)
        print(target_n,'is the target')

        #input
        bro1.input()
        
        print()
        print('new round')
        print(bro1.my_fitness)
        print()

eval_genomes() #run the loop

How to implement NEAT?

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • I would suggest you see [this](https://neat-python.readthedocs.io/en/latest/xor_example.html) tutorial (I think it's a great starting point, used it too) and then rewrite to code. You can learn stuff better if you do it yourself. – Aynos Dec 06 '21 at 15:15

1 Answers1

0

I am also just starting my deep-in NL and interested in learning.

First: Would recommend first to get in details with 2 good examples that are well implemented and explained:

  1. Flappy Bird 2. Google Dinosaur. Both have game code + NEAT implementation tied together. Google search will give plenty of examples.

Second: as per your question. Per my mind no any NL would be able to solve it in such example. Just because there are no 'good and enough' input data. It will always be just 50/50 per poor probability theory.

In order to make NEAT work, need to have some input data and some type of output data, and that output data should be a consequence of a 'choise' based on input data, hope it not get too complicated, but in one word should be some kind of dependency of input data and actions that should be taken to achieve valuable output data.

More exactly: in your case, as input data you have a choosed random number - that ok. But you have no any data, parameters based on which that random number is actually choosed. This data needed in order to let NEAT create genomes that will make tries, calculations, fits...in order to find best parameters for its model, to get a good guess. That why NL model can not be constructed.

Hope all makes sense and happy to discuss if interested.

Crazzy626
  • 1
  • 1