OpenAI Retro Contest – How To Install Gym Retro – Possible Problems

If you want to learn more about Machine Learning and AI there is great contest running on https://contest.openai.com/

How to install retro enviroment you can find on: https://contest.openai.com/details and on github https://github.com/openai/retro

The guide how to install all modules is great, but problems can still arise. After four days of trying i finally made it and it finally works!

System: Windows 10, 64 Bit.

So… what did i do wrong? Why did i took me so long?

– python 3.6.5 but 32- bit version

– installed gcc the wrong way

– tried to install gcc manually

– tried running throught pyCharm.

So let’s start with with Python Version:

https://github.com/openai/retro/issues/32

You can find out what kind of version of python you have by looking at the Icon name. If you have 32 Bit Version it won’t work.

https://www.python.org/downloads/windows/

You need to install 64 bit Python. My version is : Python 3.6.5 – 2018-03-28

Installing GCC

One of the requirments to run retro gym is gcc 5 or higher.

I did it throught cygwin.

Download 64 bit version from:

https://cygwin.com/install.html

And follow this tutorial:

http://preshing.com/20141108/how-to-install-the-latest-gcc-on-windows/

Possible problems:

You need to copy setup-x86_64.exe from downloads to your cygwin folder.

You run this command thorught cmd in your cygwin folder:

(Don’t forget, it is CMD not Cygwin!)

C:\cygwin64>setup-x86_64.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel won't work. Also if you are currently in the project folder you can just write: setup-x86_64.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel

If you are getting the gcc package don’t forget to change

wget http://ftpmirror.gnu.org/gcc/gcc-4.9.2/gcc-4.9.2.tar.gz

to:

wget http://ftpmirror.gnu.org/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz

We wan’t the newer version after all. The same thing here:

../gcc-4.9.2/configure --program-suffix=-4.9.2 --enable-languages=c,c++ --disable-bootstrap --disable-shared

replace with:

../gcc-7.3.0/configure --program-suffix=-7.3.0 --enable-languages=c,c++ --disable-bootstrap --disable-shared

At the end you should test the compiler. If it works we are ready to go!

Install from binary

Next you can install enviroment throught pip3:

pip3 install gym-retro

Running throught pyCharm

On the details page: https://contest.openai.com/details

There is this script:

import retro


def main():
    env = retro.make(game='Airstriker-Genesis', state='Level1')
    obs = env.reset()
    while True:
        obs, rew, done, info = env.step(env.action_space.sample())
        env.render()
        if done:
            obs = env.reset()


if __name__ == '__main__':
    main()

But if you run it thgouth IDE you get this:


C:\Users\programmer\PycharmProjects\untitled1\venv\Scripts\python.exe C:/Users/programmer/PycharmProjects/untitled1/retro-agent.py
Traceback (most recent call last):
File "C:/Users/programmer/PycharmProjects/untitled1/retro-agent.py", line 1, in <module>
import retro
ModuleNotFoundError: No module named 'retro'

Process finished with exit code 1

The thing is you need to run this script throught terminal. Just run your script in terminal :

python retro-agent.py

And you should get the ai playing the game Airstriker-Genesis on our screen.

Other Prolems:

Don’t forget to Add Python to your PATH!

GCC Needs to be 5 or Higher!

64 Bit versions of programs!

Run the retro-agent.py throught terminal!

Installing from source, possible problems:

https://github.com/openai/retro/issues/30



							

Tutorial: How to access variable from other class in Unity

I have dealt with this problem very often.

How to get variables from other Class in Unity? For example I’ve got one Class with public Variables and i want to get the same value of the Variable in other Class.

For Example it could be a Class which adds points to overall Score. But in other Class i show it using Unity UI System as Text.

Here is the Class with Variable which is calling the Function in other Class.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Score : MonoBehaviour {

  public GameObject scoreScript;
  // Use this for initialization

  public void OnTriggerEnter2D(Collider2D node)
  {
    if (node.gameObject.tag == "Apple") {
      Destroy (node.gameObject);
      ScoreMenager scorePointsScript =  scoreScript.GetComponent<ScoreMenager>();
      scorePointsScript.AddScore ();

    }
  }
}

 

And here is the Class which contains the Function where the variable points gets incremented.

using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class ScoreMenager : MonoBehaviour {
  public int points;


  Text text;

  void Awake ()
  {
    text = GetComponent<Text> ();

  }
  // Use this for initialization
  void Start () {
  }

  public void AddScore()
  {
    points++;
  }
  // Update is called once per frame
  void Update () {
    

    text.text = "Score: " + points;
  }
}

 

Don’t Forget to Add The “Score” Script to your character! And the same for ScoreMenager, which needs to be added to the UI Element.

And also don’t forget to Create the Text as GUI

Also important is the fact, that you need to change the “Tag” of your element which will be destroyed. After it increases the Score Points value.

Component > UI > Text

 

Other tutorials in the series:

How to make the objects fall in Unity

Making Objects Fall Random On The Screen in Unity

How to Speed Up (Increase Speed) Time in Unity

How to create a simple countdown Timer in Unity

Rendering Crisp Pixelart in Phaser (2017)

I had this problem while building my pixelart game in Phaser. My Pixelart was blurry. It didn’t looked nice. I was searching the web for an answer but i didn’t found one. Many of the tutorials were outdated so i decided to write my solution here.

You can find the working example here: http://www.noob-programmer.com/pixelart_example/

Example above works for Chrome and Mozilla Firefox.

Solution includes editing CSS and one line in phaser script.

Here is the CSS which you need to apply to your html element:

body {
  filter: none;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

Used it on body element.

The other line is the Phaser script:
var game = new Phaser.Game(200, 150, Phaser.AUTO, 'gameContainer', {
      preload: preload,
      create: create,
      update: update
    }, null, false, false);

The last parameter (“false”) is for antialiasing. It needs to be set to false.

What about other browsers? What do i need to change in order to get crispy Pixelart? Check this solution:

body {
  -ms-interpolation-mode: nearest-neighbor; // IE 7+ (non-standard property)
  image-rendering: -webkit-optimize-contrast; // Safari 6, UC Browser 9.9
  image-rendering: -webkit-crisp-edges; // Safari 7+
  image-rendering: -moz-crisp-edges; // Firefox 3.6+
  image-rendering: -o-crisp-edges; // Opera 12
  image-rendering: pixelated; // Chrome 41+ and Opera 26+
}

Source: https://builtvisible.com/image-scaling-in-css/

Source: https://developer.mozilla.org/en-US/docs/Games/Techniques/Crisp_pixel_art_look