Jump to content

Trying to improve PETRA Bot


ramtzok1
 Share

Recommended Posts

Hello,

You may remember me from past threads related to implementing ML on 0 A.D.

We made huge progress since last thread.

 

I'm now trying to compare old PETRA and our new PETRA to see if there are any improvements and I can't figure out how to make it right.

What I tried:

1. I created a new folder called PetraML and copy and pasted all the files of PETRA.

2. I edited the file data.json where the name of PETRA is: PetraML. The description is different from the old PETRA. The moduleName is now "PETRAML" and the constructor is now "PetraBotML"

3. I changed on every file in PetraML where:

var PETRA = function(m)

is now:

var PETRAML = function(m)

4. I changed on every file in PetraML where:

}(PETRA);

is now:

}(PETRAML);

5. I changed on _petrabot.js from:

m.PetraBot = function PetraBot(settings)

to:

m.PetraBotML = function PetraBotML(settings)

 

I don't know what to look for more than that.

I'm getting errors from the game when I trying to make a game  (Picture attached).

Can anyone help me solve this? thank you!

unknown.png

Link to comment
Share on other sites

29 minutes ago, stanislas69 said:

The first step would be to look the interestinglog.html file in %localappdata%/0ad/logs and see whats the root cause :)

 

9 minutes ago, wowgetoffyourcellphone said:

Likely InterestingLog would output exactly what is in that screenshot 

Good to know this file exists :), however, I already looked up the errors it seems like it can't load the data from data.json, I can't figure out what is going on.

Here's data.json

{
  "name": "PetraML",
  "description": "PetraML is our work for a project about machine learning.",
  "moduleName" : "PETRAML",
  "constructor": "PetraBotML",
  "useShared": true
}

I tried to go deep into the cpp where GetAIs is called in the file "settings.js" line 101 but I can't understand what is wrong, the code seems to have no problem getting the file.

I don't know what else to attach or say in order to help you understand the cause.

Screenshot_2.png

Link to comment
Share on other sites

13 minutes ago, ramtzok1 said:

I tried to go deep into the cpp where GetAIs is called in the file "settings.js" line 101 but I can't understand what is wrong, the code seems to have no problem getting the file. 

It says b.data.name is undefined, which sounds like the json is broken, but your JSON looks fine. Perhaps that sort function has always been broken and noone noticed because noone tried two AIs?

Try warn(uneval(Engine.GetAIs())); then you can see the return value and perhaps deduce more.

Link to comment
Share on other sites

10 minutes ago, elexis said:

It says b.data.name is undefined, which sounds like the json is broken, but your JSON looks fine. Perhaps that sort function has always been broken and noone noticed because noone tried two AIs?

Try warn(uneval(Engine.GetAIs())); then you can see the return value and perhaps deduce more.

Already tried that :/, the second I run the game it crashes. I debugged where the crash is and it is inside of stdio.h.

function loadAIDescriptions()
{
	warn(uneval(Engine.GetAIs()));
	var ais = Engine.GetAIs();
	translateObjectKeys(ais, ["name", "description"]);
	return ais.sort((a, b) => a.data.name.localeCompare(b.data.name));
}

This compare is very important to our project because this what we have worked for this whole year. We have to know if we did improve PETRA with machine learning...

Link to comment
Share on other sites

18 minutes ago, elexis said:

Then investigate only parts of the object. Test if it's an array. If it is, test the first element, etc.

 warn(typeof Engine.GetAIs());

warn(Engine.GetAIs()[0].data);

warn(Object.keys(Engine.GetAIs()[0]));

etc.

warn(Engine.GetAIs()[0].data.toSource()); // BadBot - Our first ever bot
warn(Engine.GetAIs()[1].data.toSource()); // Petra
warn(Engine.GetAIs()[2].data.toSource()); // Crashes
warn(uneval(Engine.GetAIs()[2].data)); // Crashes
warn(Engine.GetAIs([2]).id); // Undefined

warn(Object.keys(Engine.GetAIs()[0])); // data, id
warn(Object.keys(Engine.GetAIs()[1])); // data, id
warn(Object.keys(Engine.GetAIs()[2])); // Doesn't crash - data, id

This is what I have found.

I think I will head back to the GetAIs CPP function. I can't determine what causes it to be undefined.

Link to comment
Share on other sites

warn(Engine.GetAIs().length);

Does [2] actually exist?

It sounds like there is some broken directory, or some "unassigned" placeholder item or something.

If the ReadJSONFile call in C++ fails, it should handle that in a somehow sane way, probably report it with a readable error.

Edit: What's the result of

warn(Object.keys(Engine.GetAIs()[2])); // Doesn't crash - data, id
  • Thanks 1
Link to comment
Share on other sites

14 hours ago, elexis said:

warn(Engine.GetAIs().length);

Does [2] actually exist?

It sounds like there is some broken directory, or some "unassigned" placeholder item or something.

If the ReadJSONFile call in C++ fails, it should handle that in a somehow sane way, probably report it with a readable error.

Edit: What's the result of


warn(Object.keys(Engine.GetAIs()[2])); // Doesn't crash - data, id

I managed to solve the problem!

After a deep understanding, what does GetAIs it's looking for every json file in the directory  simulation/ai and part of my communication between the game and the machine learning module I'm using a json file to send units to the ML (It is loaded with all the possible fighting units. Huge file).

The game picks it as part of AI and tries to load it, that's why it fails.

Thank you so much for your help! I really appreciate that!

  • Like 1
Link to comment
Share on other sites

10 minutes ago, ramtzok1 said:

GetAIs it's looking for every json file in the directory

Shet, I've come across this problem before too! It should only look for data.json!

This

		vfs::ForEachFile(g_VFS, L"simulation/ai/", Callback, (uintptr_t)this, L"*.json", vfs::DIR_RECURSIVE);

should be

Quote

        vfs::ForEachFile(g_VFS, L"simulation/ai/", Callback, (uintptr_t)this, L"data.json", vfs::DIR_RECURSIVE <- NOT);

or similar.

Link to comment
Share on other sites

53 minutes ago, ramtzok1 said:

I tried to contact them via the IRC but they never answered back.

Can you please revert this statement.

I provide you answers in PM.

You and/or your mate connect to irc. We answered the questions you asked us.

I am very disappointed.

Edited by fatherbushido
answer -> answered
Link to comment
Share on other sites

1 hour ago, fatherbushido said:

Can you please revert this statement.

I provide you answers in PM.

You and/or your mate connect to irc. We answered the questions you asked us.

I am very disappointed.

Excuse me for not mentioning you, you did help via PM.

I didn't mean to hurt anybody, you did help me, every one of you did.

I can't remember exactly and also my partner about the irc, what happened there if any, a lot has changed since I appeared on your forums for the first time and really, thank you for everything.

@(-_-) @fatherbushido @stanislas69 @elexis @Imarok

I don't take any credit of solving my problems by myself. You did a lot of the job pointing me to the right direction.

Edited by ramtzok1
For some reason I wrote "did not" O_o
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...