How to run ViZDoom on Windows 10

ViZDoom is a Doom-based AI research platform for machine learning from raw visual information with a yearly competition of AI bots fighting in a Deathmatch format.

You can learn more about ViZDoom here: http://vizdoom.cs.put.edu.pl

This tutorial explains how to run ViZDoom and Linux based ViZDoom Docker images on a Windows 10 Pro host running Docker CE for Windows.

Before you start please ensure you have Windows 10 Professional 64-bit installed as you need Pro for Hyper-V support to use Docker for Windows. You can upgrade a copy of Windows 10 Home to Pro in the Windows Store without re-installing Windows but you will need to pay $99 for the privilege. This tutorial does not cover attempting to use the legacy Docker Toolbox to run Docker containers on Win 10 Home or Win 7.

Please be also aware that Nvidia CUDA is currently not supported inside a Docker Container when the Docker host is running on Windows 10. If your goal is to train AI bots using GPU/CUDA accelerated versions of Tensorflow and/or OpenCV you will be able to do so on the Windows 10 host system (provided you have a suitable GPU and drivers) but when your AI bot runs inside a Docker container you will be bound to CPU only when you host it via Docker for Windows.

How to install and start ViZDoom 

  • Download ViZDoom Python 3.6 (64bit) 1.1.5pre
  • Create the folder “C:\vizdoom\vizdoom115pre”
  • Extract the content of the vizdoom folder in the ZIP into “C:\vizdoom\vizdoom115pre”
  • Run “C:\vizdoom\vizdoom115pre\vizdoom.exe” for a quick check
  • You should see Freedoom 0.11.3 launch. Quit the game again

How to us VizDoom with Python 

  • Download and install Python 3.6.4 (64bit) – be sure to use 64bit!
  • Open the Windows System Properties dialog (search for “Edit the system environment variables” in Windows Search) and Click on “Environment Variables…”
  • Create a new environment variable called PYTHONPATH with the value C:\vizdoom\vizdoom115pre
    This will enable your Python installation to find and import the ViZDoom library.
    Reboot – technically closing all Windows Shells should be enough to propagate new environment variables but a reboot makes sure this is really the case.
  • Open a Windows PowerShell, type python to open Python’s interactive mode and enter
    import vizdoom
    game = vizdoom.DoomGame()
    game.init()
    You should see ViZDoom come up in a small window. It might crash after a few seconds but that is ok as long as it started up at all. Hit CTRL-BREAK to terminate the game and python script otherwise.If you get errors when trying to import vizdoom ensure that you have the correct Python and ViZDoom versions, that both are 64bit and that the PYTHONPATH is set correctly. Open python and use the following to check “C:\vizdoom\vizdoom115pre” is truly a folder Python checks in for the ViZDoom libray:
    import sys
    print(sys.path)
  • Now edit “C:\vizdoom\vizdoom115pre\examples\basic.py” with a text or Python editor of your choice and change
    game.set_doom_scenario_path(“../../scenarios/basic.wad”) to
    game.set_doom_scenario_path(“../scenarios/basic.wad”)
    Note: All examples seem to use one “folder up” too much so do this before testing any example
  • Open c:\vizdoom\vizdoom115pre\examples in Windows PowerShell and type python basic.py
  • You should see ViZDoom come up in a small window executing the basic random demo.
    Hit CTRL-BREAK to terminate the game and python script.
  • Congratulations: You can now use all examples and begin to build your own AI

How to run the ViZDoom inside Docker for Windows

To be able to participate in a (potential) future ViZDoom competition you will most likely need to supply your AI bot build-able via a Dockerfile as you needed for ViZDoom 2017. You can find the sample submission, some past submissions of actual bots and the Linux guide here: https://github.com/mihahauke/vizdoom_cig2017

In a nutshell the way the competition works is that you run a “host” Docker Container which hosts an instance of ViZDoom as a spectator and you have another Docker container with another instance of ViZDoom for each participating AI. All instances of ViZDoom create a network game on port 5029 via UDP and the match autostarts when the pre-configured amount of players joined. Using the submission template you can create your own little competition among one or multiple instances of your own AI, a (fairly random) test AI and some of the AI’s submitted to previous competitions (although i only managed to get “clyde” to work in Docker for Windows).

Docker step 1: Install Docker and download the ViZDoom submission template project

  • Download and install Docker CE for Windows (e.g. 17.12.0-ce-win47)
  • You might need to enable Hyper-V in your BIOS and reboot a couple times
  • Test Docker via “docker run hello-world”
  • Download the entire ViZDoom submission template project ZIP from Github
  • Create (if needed) the folder C:\vizdoom\ and extract the ZIP into it
  • Rename the “vizdoom_cig2017-master” folder to “vizdoomcig2017” for ease of use

Docker step 2: Build host and “random” docker image
The submission template includes build.sh and run.sh files to ease the creation and execution of Docker images. Unfortunately they are not easily executed on Windows so we will need to do some things manually

  • Let’s build the server Docker image
    • Copy C:\vizdoom\vizdoomcig2017\_vizdoom.cfg and C:\vizdoom\vizdoomcig2017\cig2017.wad to C:\vizdoom\vizdoomcig2017\host\
    • Open PowerShell and go to c:\vizdoom\vizdoomcig2017\host\
    • type docker build -t cig2017_host . (do not forget the dot at the end)
    • The build process can take minutes to hours depending on your PC and internet speed
  • Let’s build the “random” AI
    • Copy C:\vizdoom\vizdoomcig2017\_vizdoom.cfg and C:\vizdoom\vizdoomcig2017\cig2017.wad to C:\vizdoom\vizdoomcig2017\random\
    • Edit _vizdoom.cfg game_args += -join 10.0.75.2 (more on this below)
    • Open Shell and go to c:\vizdoom\vizdoomcig2017\random\
    • type docker build -t cig2017_random . (do not forget the dot at the end)
    • The build process can take minutes to hours depending on your PC and internet speed

Docker step 3: Running the docker images as containers

  • Open a PowerShell and execute
    docker run -it –rm –network=”host” –name cig2017_host cig2017_host -li 1
  • You should see a bunch of console output followed by:
    Press ‘Q’ to abort network game synchronization.
    Waiting for players: . [ 1/ 2]
  • Make sure this is the first and only docker container running. It should automatically connect to the DockerNAT host network on the IP 10.0.75.2. Try to ping the machine to be sure. If your DockerNAT is on a different IP range adjust the “join” parameter in the _vizdoom.cfg of the random AI accordingly
  • Open another PowerShell and execute
    docker run -it –rm –network=”host” –name cig2017_random cig2017_random
  • You should see a bunch of console output talking about the two ViZDoom instances connecting and starting to play. Every minute there should be a status update on the scores (with not much happening given there is only one random AI)
  • Kill the docker containers via CTRL-BREAK. Thanks to the “–rm” parameter they should clean up after themselves

Docker step 4: See the GUI of a container

  • The AI boilerplate code has a build-in approach to let a Linux Docker host see the GUI of the containers. With Docker for Windows we need to create our own approach.
  • First download and install Xming
  • Open the install directory (“C:\Program Files (x86)\Xming” by default)
  • Edit the file “X0.hosts” with a text editor and add a line for the local IP address of your machine (not 10.0.75.1 on the DockerNAT – your local IP like 192.168.1.100. Look it up in ipconfig.)
  • This allows all services on your local machine to auto-connect even if not using the local loopback IP 127.0.0.1/localhost
  • Restart Xming
  • Open a PowerShell and execute set-variable -name DISPLAY -value 192.168.1.100:0.0 (or whatever your local IP is – keep the :0.0 at the end though)
  • In the same PowerShell start the host container via
    docker run -it –rm –network=”host” -e DISPLAY=$DISPLAY cig2017_host -li 1 -w
    Notice the change of adding the -e parameter to connect to the Xming display and the -w parameter at the end to render a GUI in the container
  • Add an instance of the “random” AI to start the game e.g. via
    docker run -it –rm –network=”host” –name cig2017_random cig2017_random
  • You should see the two containers connect as usual but you should also see the GUI of the host come up. You should be able to fly around as a spectator (WASD controls and mouse) and find the random AI on the map doing random things. Note that random really just means randomly shooting and turning left/right. The AI will basically just fire all rockets until out of ammo while turning in place.

Docker step 5: Have your local Windows 10 ViZDoom play with the containers

  • Remember the local ViZDoom we installed at the very beginning? We can join the network of containers and play along
  • First let’s start a ViZDoom host in a container but add a parameter to have two AI’s playing
    docker run -it –rm –network=”host” cig2017_host -li 1 -p 2
  • Add an instance of the “random” AI via
    docker run -it –rm –network=”host” –name cig2017_random cig2017_random
  • Copy C:\vizdoom\vizdoomcig2017\cig2017.wad to C:\vizdoom\vizdoom115pre\scenarios\cig2017.wad
    We need to make sure your local installation has the correct wad file (the correct map in other words). Otherwise you will get an out-of-sync message in the ViZDoom GUI.
  • Edit C:\vizdoom\vizdoom115pre\examples\cig.py and change
    • game.load_config(“../../scenarios/cig.cfg”) to
      game.load_config(“../scenarios/cig.cfg”)
    • game.add_game_args(“-join localhost”) to
      game.add_game_args(“-join 10.0.75.2”)
    • game.set_mode(Mode.ASYNC_PLAYER) to
      game.set_mode(Mode.SPECTATOR)
  • Edit C:\vizdoom\vizdoom115pre\scenarios\cig.cfg and change
    • doom_scenario_path = cig.wad to
      doom_scenario_path = cig2017.wad
  • Open a PowerShell, go to C:\vizdoom\vizdoom115pre\examples\ and type python cig.py
  • Your local copy of ViZDoom should start and you should be playing a match against the random AI

Docker step 6: Getting the “clyde” AI to work

  • Download the clyde source files (it’s too large for Github but linked from there)
  • Extract to C:\vizdoom\vizdoomcig2017\clyde\
  • Copy C:\vizdoom\vizdoomcig2017\_vizdoom.cfg and C:\vizdoom\vizdoomcig2017\cig2017.wad to C:\vizdoom\vizdoomcig2017\clyde\
  • Edit _vizdoom.cfg game_args += -join 10.0.75.2
  • Open Shell and go to c:\vizdoom\vizdoomcig2017\clyde\
  • Edit the Dockerfile with a text editor and change
    • zlib1g-dev to
      zlib1g-dev \
      libsdl2-2.0-0 \
      libgles2-mesa-dev \
      libglu1-mesa-dev
    • COPY CLYDE_track1 . to
      COPY clyde_track1 .
  • type docker build -t cig2017_clyde . (do not forget the dot at the end)
  • The build process can take minutes to hours depending on your PC and internet speed
  • You can run “clyde” just as the random AI via
    docker run -it –rm –network=”host” –name cig2017_clyde cig2017_clyde
  • The container throws all kinds of warnings both during build and during run but the “clyde” AI plays and acts as one would expect (it navigates through the level and shoots enemies)

Final thoughts

Getting ViZDoom and Docker for Windows to work together is fairly straight forward assuming you have some previous experience with Docker and Linux.

You might have noticed that i am forcing the containers to use –network=”host” and therefore have to tweak the ip addresses. In a Linux based Docker host environment you can connect port 5029 of a container to the same host port via 127.0.0.1/localhost. This feature does not work in the current Windows 10 stable release. Microsoft made a blog post that Windows Insider Build 17025 has this feature enabled but i did not try upgrading to a preview release of Windows 10.

The inability of Containers running on Docker for Windows to take advantage of CUDA is disappointing and limits the feasibility of the overall approach. I could not get F1 and Intelact AI Dockerfiles to build properly. Either they don’t work properly with Docker for Windows, are incompatible with newer versions of Docker in general and/or can’t get properly build without the Container supporting CUDA.

Last but not least huge shout-out to the entire ViZDoom team around Michał Kempka, Grzegorz Runc, Jakub Toczek, Marek Wydmuch and Wojciech Jaśkowski. This is a really fun and well documented project – especially if you are not making your life more complicated than it needs to be and choose a Linux based operating system to get started. I really hope there will be a ViZDoom 2018 competition!

Anyhow, i hope this little guide is helpful to some of you. For questions and feedback please reach out in the ViZDoom user group https://groups.google.com/forum/#!forum/vizdoom