Git Product home page Git Product logo

more-i-o's Introduction

MORE I/O

What is this project?

This project is a OpenAI-powered version of SethBling's MarI/O Evolving Neural Network script for Bizhawk 1.x.

Unfortunately, Sethbling's original code relies on Bizhawk 1.x and is Windows-based. The code is also very old, dating from last edits in 2015. Trying to run the code on a newer Bizhawk instances works, but you cannot save or load your progress due to the Lua scripting runtime throwing errors.

MoreI/O aims to fill that gap using OpenAI (https://openai.com/about/) by provide a way of letting the computer do the work of playing Super Mario Bros on the NES using FCEUX emulator. Maybe one day, the AI will be able to race against the clock in speedruns in versus matches against human players.

Requirements

You'll need at least the latest version of Python 2 and/or Python 3 that comes with your distro. Ubuntu 16.04 and similar distros (probably even Debian) should ship with 2.7.x and 3.5 in their repositories.

It doesn't matter what platform you use, as long as it's Linux and you can run FCEUX and Python. A lot of this is CPU-driven, and doesn't make use of TensorFlow. It has been successfully tested on powerhouse x86-64 servers to ARM based devices like the ODROID-XU4. It might even run on the R-Pi with poor emulated framerate.

Make sure you have the following packages installed as well. Some of the commands might be incorrect, please submit a issue ticket with the correct ones.

  • fceux (Ubuntu/Debian: apt install fceux)
  • git (Ubuntu/Debian: apt install git)
  • python3.x (Ubuntu/Debian: apt install python3)
  • pip3 for python 3.x (Ubuntu/Debian: apt install python3-pip)
  • tk (Ubuntu/Debian: apt install python3-tk)
  • matplotlib (pip3 install matplotlib)
  • pymongo (pip3 install pymongo)
  • psutil (pip3 install psutil)
  • gym (pip3 install gym)
  • You might also need to install libfreetype6-dev and a few other packages if Tk throws an exception that it can't find libraries to build with.

If you wish, you can install the full OpenAI stack by going to https://gym.openai.com/docs. It is recommended you install these packages locally (don't install them as superuser or globally) because we need to edit some files.

Installing the environment

After installing the above packages, clone this repository into a empty folder using git clone [url of repo] MoreIO. You can change the directory name if you wish, but keeping it as MoreIO is easier to know what it is. After git pulls the repo, move on the next step.

Do not run any python scripts yet. You should have a folder in your $HOME/.local/lib/python3.X/site-packages/ called gym. Replace X with the minor version of python - for example, if you have python 3.5, you'd replace the X with 5. If you don't, you probably have a install error or forgot to install it. Otherwise, open a ticket or search google. In the directory you cloned the repo, run git clone https://github.com/koltafrickenfer/gym-super-mario to clone the AI environments and related data.

Now, we need to install the cloned gym environment done in the last command. Run this command, adapting the path to your needs:

ln -s [path to the just-cloned gym-super-mario repo]/ppaquette_gym_super_mario $HOME/.local/lib/python3.X/site-packages/gym/envs/gym_super_mario

Do not alter anything else. This sets up a symlink so gym can see the environments on disk, but now you need to register them by editing $HOME/.local/lib/python3.X/site-packages/gym/envs/__init__.py and putting the following at the bottom of it:

register(
	id='meta-SuperMarioBros-Tiles-v0',
	entry_point='gym.envs.gym_super_mario:MetaSuperMarioBrosEnv',
	kwargs={'draw_tiles': 1},
	reward_threshold=(3266 - 40),
	nondeterministic=True,
)	

Save the file. You're done. Let's get it started.

Running the environment

Change to the directory where you have MoreIO cloned into and then run python3 mario.py. If all goes well, you should see the control panel window, with how many jobs you want to run, and the population. The defaults are set to 2 jobs and 300 population. The graph at the bottom will be generated over time, and show you the progress of the network. The more jobs, the more CPU consumption will be used as the emulator instances running at the same time. Do not set it to absurd numbers if you have a weak CPU as that's just stupid and you're asking for a system crash.

After changing jobs and population to your liking hit "Start Run". It will then turn to "Running" to let you know it's running the AI environment. After a bit, you should see FCEUX boot and the AI start. It is normal for the AI to do nothing for a while and then reset, you need to keep in mind that it's running a evolution simulation, and there will always be child species that "do nothing" or are duds.

Right now, the AI will go through all 32 levels in Super Mario Bros. It won't do glitch levels like minus world or other levels that are accessible by exploiting logic flaws in the game unless the AI becomes aware of those strats. This might be slow, but give it about half a day and you'll see the AI start making progress at attempting to beat the levels. Keep in mind that this will be a slow evolution process.

Copyright concerns

While this project does use emulated NES hardware via emulators and a copy of the Super Mario Bros NES ROM, the term "emulator" can be disputed in some countries. The version of mario that is played is cloned from an unofficial openAI and has no mention of copyright, neither I or this project are affiliated with Nintendo, openAI, or any other company for that matter.

Things to do, in no particular order:

  1. clean up tkinter ui add in a way to save config files with mutation rates and ability to disbale rendering. basicly a bunch of boring work.
  2. write docker container that inilizes open ai.
  3. write code for inderect encoding of genes.

more-i-o's People

Contributors

kolt-mcb avatar koltmcbride avatar genuinesounds avatar softwareguy avatar

Stargazers

 avatar Robin avatar Theodore Galanos avatar Xu Chen avatar  avatar Rasool Ziafaty avatar Murat Eliby avatar  avatar  avatar Nathan RYDIN avatar mpdev avatar Tony avatar Alexey Guzey avatar Lim Yun Kai avatar Zeyu Zhang avatar  avatar Flavian Hautbois avatar  avatar  avatar Michael Miller avatar Shin avatar Teal avatar Joshua Latham avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

Forkers

softwareguy

more-i-o's Issues

Execution fails after genomes get born

Blast from the past, huh?

I tried to get this working again since I wanted to stream a bot learning SMB with Python 3.6 and Kubuntu 18.04 last weekend and didn't get very far. Everything seemed to be working until I got up to running python3 mario.py. The GUI appeared, I clicked Start Run and then.... nothing.

I got a lot of console prints, saying gen 0 genome X was born. Waited 10 minutes, no progress.

Would you have any clues as to why this isn't working as intended? FCEUX is installed, there's no Gym errors, Python seems happy.

I did try to inject some debug code into nes_env.py (some logging code) but it didn't fire for some reason. It just seems that it breaks after the genomes are created.

Oddities with this system.

Greetings,

I thought I'd provide some information on how it's going so far after I had to piece together a lot of stuff from various upstream issue tickets and whatnot to even get the thing running.

  1. On first run, I see the AI is going through the first 300 species and it's getting basic scores of 39, 40 and sometimes 300 for those "oh wow it did something" moments. I assume this is normal, because SethBling's MarI/O does this for quite some time before it starts mutating and actually playing the game.
  2. I've been keeping an eye on my machine's load average and the machine is a Core i5, 16GB of System RAM. It's averaging around 11.50 - 14. I assume this is normal as I see a lot of python3 processes running their tasks.
  3. The ROM supplied apparently does not automatically start up at World 1-1. Instead, it seems to be randomly starting at first levels in different worlds. For example, on the title screen when it's at World 5-3, I see a bullet bill fly across the screen. Is this normal, or is this ROM a "bad" dump? Other Worlds include World 3-3, 6-3, sometimes 4-3 and 1-3. I assume it will then go back to World 1-1 and play from there?
  4. Is saving and loading pools implemented? This is a important question because if not, then well... the training will be forfeited if it can't save/load.
  5. The instructions need to be improved. Please add sections about installing the specific version of gym that has 'scoreboard' contained within (refer to the ppaequiette upstream issue tracker about that)
  6. When does the tk window update? Does it update every generation or whenever it feels like it?

I will keep adding my findings in this thread as I evaluate it, however for a linux-powered variant of a learning AI, you're doing great work. Keep it up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.