How to rerun a sketch?

I'm using processing to teach an AI how to play snake. As the sketch runs, files are modified, one of which is a pde file. The problem is that the sketch only recognizes the changes made to the pde file once the sketch is closed, and so restarting the program with setup() doesn't work. The only way for the program to work is for me to close it and reopen it every time the game is over. Because I will be dealing with thousands of games, this will get quite tiresome, and I was wondering if there was a way to close and reopen the sketch from within the sketch?

Answers

  • Hm. It would be better if the learning of the AI would be stored in non-pde files or data

    In fact when you want to have 1000 or 100000 times your sketch runs and learns it would be best not to change files but only internal data

    after the 1000 times save the results of the AI

  • There are a hundred AIs per generation. Each AI is a randomly generated program saved as a text file in another folder. When I want to run an AI, I copy its text file into the project folder as a pde file so that it can be run by the sketch. Is there a better way to load programs?

  • edited February 2018

    You misunderstand. We're questioning why your AIs are files of CODE, not just DATA. What does each AI actually DO?

    We're suggesting you have data that represents what an AI does. Then you can run an AI by simulating it. You don't actually need to hand it the ability to execute code - you just need to know what it WOULD do.

  • In general (without knowing what your AI does) it would be easier and more efficient to have a lot of methods/parameters, and configuring different AIs using data as to how they access those methods. So an AI is a class that could in theory do what any AI could do, and it is configured by the constructor to be a specific AI.

    If you really need dynamic code generation at runtime embedded inside Processing then you could use Nashhorn -- you would build JavaScript file strings rather than Java, then execute them as code.

    Can you give a few examples of what the code of your Snake AIs currently looks like?

Sign In or Register to comment.