cair / deep-rts

A Real-Time-Strategy game for Deep Learning research
MIT License
205 stars 36 forks source link

Cannot use custom maps #13

Open marcocspc opened 4 years ago

marcocspc commented 4 years ago

Hello! I'm not being able to use custom maps on DeepRTS.

If I try to load a map that is not inside the default maps folder, it fails. I took a look at the code and saw that the game will only run maps that are inside that directory.

Even if I copy my custom map to DeepRTS/python/assets/maps, the game won't load. The error I'm getting is this one:

"RuntimeError: File Error: Could not find: 32.json (/home/marcocspc/git/drts/DeepRTS/python/assets/maps/32.json). Ensure that the data directory exists!"

But the file is there:

"$ls /home/marcocspc/git/drts/DeepRTS/python/assets/maps/ -l total 52 -rw-r--r-- 1 marcocspc marcocspc 1253 jan 21 10:12 10x10-2v2.json -rw-r--r-- 1 marcocspc marcocspc 1881 jan 21 10:12 15x15-2v2.json -rw-r--r-- 1 marcocspc marcocspc 2937 jan 21 10:12 21x21-2v2.json -rw-r--r-- 1 marcocspc marcocspc 5497 jan 21 10:12 31x31-2v2.json -rw-r--r-- 1 marcocspc marcocspc 5495 jan 21 10:12 31x31-4v4.json -rw-r--r-- 1 marcocspc marcocspc 5493 jan 21 10:12 31x31-6v6.json -rw-rw-r-- 1 marcocspc marcocspc 5493 jan 21 16:10 32.json -rw-rw-r-- 1 marcocspc marcocspc 5493 jan 21 16:01 simple_32_32.json"

I tried to reinstall DeepRTS with the custom maps inside the folder, but to no avail. I thought that the installation "freezes" the files inside the folder and won´t "see" the new files that I added there, so If I reinstalled the module, maybe the maps would be included.

Thank you for your support!

marcocspc commented 4 years ago

I tried replacing my custom map with a default one, the game refuses to start with the same error:

"RuntimeError: File Error: Could not find: 10x10-2v2.json (/home/marcocspc/git/drts/DeepRTS/python/assets/maps/10x10-2v2.json). Ensure that the data directory exists!"

Again, the file is there:

"marcocspc@marcocspc-desktop-linux:~/git/drts/DeepRTS/python/assets/maps$ ls -l total 48 -rw-rw-r-- 1 marcocspc marcocspc 5493 jan 21 16:01 10x10-2v2.json -rw-r--r-- 1 marcocspc marcocspc 1881 jan 21 10:12 15x15-2v2.json -rw-r--r-- 1 marcocspc marcocspc 2937 jan 21 10:12 21x21-2v2.json -rw-r--r-- 1 marcocspc marcocspc 5497 jan 21 10:12 31x31-2v2.json -rw-r--r-- 1 marcocspc marcocspc 5495 jan 21 10:12 31x31-4v4.json -rw-r--r-- 1 marcocspc marcocspc 5493 jan 21 10:12 31x31-6v6.json -rw-rw-r-- 1 marcocspc marcocspc 5493 jan 21 16:10 32.json"

perara commented 4 years ago

Hi, How did you run DeepRTS? Are you using it as a library or directly from the git repo?

On Tue, Jan 21, 2020, 21:03 Marco Antonio notifications@github.com wrote:

I tried replacing my custom map with a default one, the game refuses to start with the same error:

"RuntimeError: File Error: Could not find: 10x10-2v2.json (/home/marcocspc/git/drts/DeepRTS/python/assets/maps/10x10-2v2.json). Ensure that the data directory exists!"

Again, the file is there:

"marcocspc@marcocspc-desktop-linux:~/git/drts/DeepRTS/python/assets/maps$ ls -l total 48 -rw-rw-r-- 1 marcocspc marcocspc 5493 jan 21 16:01 10x10-2v2.json -rw-r--r-- 1 marcocspc marcocspc 1881 jan 21 10:12 15x15-2v2.json -rw-r--r-- 1 marcocspc marcocspc 2937 jan 21 10:12 21x21-2v2.json -rw-r--r-- 1 marcocspc marcocspc 5497 jan 21 10:12 31x31-2v2.json -rw-r--r-- 1 marcocspc marcocspc 5495 jan 21 10:12 31x31-4v4.json -rw-r--r-- 1 marcocspc marcocspc 5493 jan 21 10:12 31x31-6v6.json -rw-rw-r-- 1 marcocspc marcocspc 5493 jan 21 16:10 32.json"

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cair/deep-rts/issues/13?email_source=notifications&email_token=AA4ZS7WO6FPG7BRAG7JVXKLQ65IJPA5CNFSM4KJZFYHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJRCCXY#issuecomment-576856415, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4ZS7U3JPJ5B5DIWDMCSSTQ65IJPANCNFSM4KJZFYHA .

marcocspc commented 4 years ago

Hello! I've installed it using pip, running the commands from the Dockerfile in a real Ubuntu installation.

The script I'm using to test the game is the one here: https://github.com/marcocspc/AI_Laboratory/blob/master/DeepRTS/scripts/drts_test.py

As you can see, I'm using DeepRTS as a system module.

perara commented 4 years ago

If you install DeepRTS, it will be installed in site-packages. This means that the custom map must be added to this location. I'm not 100% sure where this would be, but something like

(https://github.com/cair/deep-rts/tree/master/DeepRTS/python/assets/maps) venv/lib/python3.7/site-packages/DeepRTS/python/assets/maps/32.json

What you could do is to fork the project and add the map to your fork, then install your fork via pip. Another method would be to copy the files to the location above in your dockerfile

I havent found a good way of doing this, because the "Engine", which runs in C++ is not very friendly when it comes to paths. Currently the process is as follows:

  1. DeepRTS python instance change directory to the location of the library https://github.com/cair/deep-rts/blob/master/DeepRTS/python/_py_deeprts.py#L15

  2. Then the C++ side loads the map relatevly from this location https://github.com/cair/deep-rts/blob/master/src/loaders/ResourceLoader.cpp#L51

A fix for this could perhaps be to allow absolute paths. But I would have to investigate.

marcocspc commented 4 years ago

I'm using a Ubuntu VM on this scenario because I need to visualize the map on the gui (I wasn't able to see the main window using docker, even forwarding my x session. But I am able to run DRTS with no gui inside a container). Anyway, using the same commands in the Dockerfile on your repo, DRTS is installed on "its own folder" inside the VM. I don't why this happened, but the game keeps referencing the directory into which the repo was cloned.

It is installed as a system-wide module (I'm not using venv, since it's a VM), I am able to import DeepRTS anywhere on the system, even inside Python 3 terminal. I will try to reinstall from scratch with my custom maps included to see if I am able to load the custom maps.

A way to allow absolute paths on the referenced code (https://github.com/cair/deep-rts/blob/master/src/loaders/ResourceLoader.cpp#L51) would be:

I know almost nothing about C++, but I may try to alter the code a little bit to see if it works if reinstalling DRTS fails.

Thank you again for your support!

perara commented 4 years ago

Ill take a look for possible solutions tonight ,+1GMT

On Wed, Jan 22, 2020, 14:14 Marco Antonio notifications@github.com wrote:

I'm using a Ubuntu VM on this scenario because I need to visualize the map on the gui (I wasn't able to see the main window using docker, even forwarding my x session. But I am able to run DRTS with no gui inside a container). Anyway, using the same commands in the Dockerfile on your repo, DRTS is installed on "its own folder" inside the VM. I don't why this happened, but the game keeps referencing the directory into which the repo was cloned.

It is installed as a system-wide module (I'm not using venv, since it's a VM), I am able to import DeepRTS anywhere on the system, even inside Python 3 terminal. I will try to reinstall from scratch with my custom maps included to see if I am able to load the custom maps.

A way to allow absolute paths on the referenced code ( https://github.com/cair/deep-rts/blob/master/src/loaders/ResourceLoader.cpp#L51) would be:

  • Check if the map is inside the maps folder. If it is, load it;
  • If not, try to use the mapFile variable as an absolute path.

I know almost nothing about C++, but I may try to alter the code a little bit to see if it works if reinstalling DRTS fails.

Thank you again for your support!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cair/deep-rts/issues/13?email_source=notifications&email_token=AA4ZS7SL3XD3R4LTHWI5FMTQ7BBCDA5CNFSM4KJZFYHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJTQCHI#issuecomment-577175837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4ZS7V4DFMDVLEUOVNVJBDQ7BBCDANCNFSM4KJZFYHA .

marcocspc commented 4 years ago

Quick update, installing from scratch using the command: "pip3 install ./drts" (I removed the "-e" option), I was able to install it to my venv default lib folder (the map was included in the installation, as you suggested).

Still, the error persists:

RuntimeError: File Error: Could not find: 32.json (/home/osboxes/envs/drts/lib/python3.6/site-packages/DeepRTS/python/assets/maps/32.json).
Ensure that the data directory exists!
(drts) osboxes@osboxes:~/git/AI_Laboratory/DeepRTS/scripts$ ls -l /home/osboxes/envs/drts/lib/python3.6/site-packages/DeepRTS/python/assets/maps/
total 44
-rw-rw-r-- 1 osboxes osboxes 1253 Jan 22 20:08 10x10-2v2.json
-rw-rw-r-- 1 osboxes osboxes 1881 Jan 22 20:08 15x15-2v2.json
-rw-rw-r-- 1 osboxes osboxes 2937 Jan 22 20:08 21x21-2v2.json
-rw-rw-r-- 1 osboxes osboxes 5497 Jan 22 20:08 31x31-2v2.json
-rw-rw-r-- 1 osboxes osboxes 5495 Jan 22 20:08 31x31-4v4.json
-rw-rw-r-- 1 osboxes osboxes 5493 Jan 22 20:08 31x31-6v6.json
-rw-rw-r-- 1 osboxes osboxes 5493 Jan 22 20:08 32.json
perara commented 4 years ago

Figured it out! Your file is not valid json.

[per@phd-laptop maps]$ file -bi 32x32-2v2.json 
text/plain; charset=us-ascii
[per@phd-laptop maps]$ file -bi 31x31-2v2.json 
application/json; charset=us-ascii

There is a missing " at the start as well as a random 1 in the file, Remove these and the map will work

perara commented 4 years ago

You can now also run games with main.py --map=32.json to run custom maps, however, they must be added to the assets directory

marcocspc commented 4 years ago

Yay! It worked! I've tested copying one of the default maps as "32.json" file and the game ran without any problems.

One last question: is this main.py file this one? https://github.com/cair/deep-rts/blob/master/coding/main.py

I'll try to fix my map and to copy it to the venv/lib/python3.6/site-packages/DeepRTS/python/assets/maps/ and see if it works after the installation. Reinstalling DeepRTS every time I make a modification to the map would be painful. :P

Again, thank you for your support!

perara commented 4 years ago

Usually, when doing custom stuff and doing research, I would reccomend that you git clone the whole project and do your work from the coding directory

If you run the main.py from drts/coding/ with the working dir as drts it should resolve itself Another thing you will have to do is to run:

python3 setup.py clean build and copy the resulting Engine.so (from build dir) to the DeepRTS directory

I reccomend that you fork DeepRTS to your own repository and do changes this way :) This way you can do whatever without having hassles with copying all the time :)

Hope this helps