Noob - questions
Moderator: OpenTTD Developers
Noob - questions
Hey there,
I have some basic questions concerning AI-writing.
1) How can you get the squareroot from a number, exists there a command like "sqrt{9}"?
2) When I use the noAI-build, set speed to fast forward and look how my AI is developing, after some time the game flow slows down and gets unsteady. Sometimes noAI-TTD hang-up. Where's the problem?
3) How do you use the transaction mode correctly? Until now I avioded using it, but it would be very helpful and make thinks easier.
My prolem is the following:
local scout = 0;
AISign.BuildSign(tileindex1, "Hello1");
scout = AITransactionMode();
AISign.BuildSign(tileindex2, "Hello2");
scout.Execute();
AISign.BuildSign(tileindex3, "Hello3");
The result is a "Hello1" sign, a "Schild"* sign and no third sign. (*I use German as ingame language: Schild = sign)
In transaction mode the sign isn't labeled, why?
The Execute() command should end the transaction mode and switch back to the normal mode or not?
I would be happy if someone could help me...
I have some basic questions concerning AI-writing.
1) How can you get the squareroot from a number, exists there a command like "sqrt{9}"?
2) When I use the noAI-build, set speed to fast forward and look how my AI is developing, after some time the game flow slows down and gets unsteady. Sometimes noAI-TTD hang-up. Where's the problem?
3) How do you use the transaction mode correctly? Until now I avioded using it, but it would be very helpful and make thinks easier.
My prolem is the following:
local scout = 0;
AISign.BuildSign(tileindex1, "Hello1");
scout = AITransactionMode();
AISign.BuildSign(tileindex2, "Hello2");
scout.Execute();
AISign.BuildSign(tileindex3, "Hello3");
The result is a "Hello1" sign, a "Schild"* sign and no third sign. (*I use German as ingame language: Schild = sign)
In transaction mode the sign isn't labeled, why?
The Execute() command should end the transaction mode and switch back to the normal mode or not?
I would be happy if someone could help me...
Re: Noob - questions
Hello and welcome to the forums.Eton wrote:Hey there,
I have some basic questions concerning AI-writing.
You can't, but you shouldn't need to. Why do you want to do this?1) How can you get the squareroot from a number, exists there a command like "sqrt{9}"?
What revision of NoAI are you running? If you have this problem with the latest build, can you post your AI somewhere? (Or in case you don't want to reveal it, pm it privatly to TrueBrain so he can try to reproduce / fix it.2) When I use the noAI-build, set speed to fast forward and look how my AI is developing, after some time the game flow slows down and gets unsteady. Sometimes noAI-TTD hang-up. Where's the problem?
The Execute() command does indeed stop recording commands into 'scout', but it does not switch back to execute mode. To do that, either let the object scout go out of scope or create an AIExecMode object.3) How do you use the transaction mode correctly? Until now I avioded using it, but it would be very helpful and make thinks easier.
My prolem is the following:
local scout = 0;
AISign.BuildSign(tileindex1, "Hello1");
scout = AITransactionMode();
AISign.BuildSign(tileindex2, "Hello2");
scout.Execute();
AISign.BuildSign(tileindex3, "Hello3");
The result is a "Hello1" sign, a "Schild"* sign and no third sign. (*I use German as ingame language: Schild = sign)
In transaction mode the sign isn't labeled, why?
The Execute() command should end the transaction mode and switch back to the normal mode or not?
That the second sign reads "Sign" (or "Schild" in your case) instead of "Hello2" is an error, I'm looking into that now.
Edit: it's clearly a bug, I'm not sure how it can be fixed though.
Re: Noob - questions
Thanks for your fast reply.
Sign "Hello2" is a bug? Ok, maybe other things building is ok...
I wanted to use it with AITile.GetSquareDistance(). Now I use it to valuate, but it would be fine to have the exact distance...Yexo wrote:You can't, but you shouldn't need to. Why do you want to do this?Eton wrote: 1) How can you get the squareroot from a number, exists there a command like "sqrt{9}"?
I use r14122-noai and the computer power should be sufficient. The AI is in an early stadium, but I try to post it later.What revision of NoAI are you running? If you have this problem with the latest build, can you post your AI somewhere? (Or in case you don't want to reveal it, pm it privatly to TrueBrain so he can try to reproduce / fix it.2) When I use the noAI-build, set speed to fast forward and look how my AI is developing, after some time the game flow slows down and gets unsteady. Sometimes noAI-TTD hang-up. Where's the problem?
How can I let the object scout go out of scope??The Execute() command does indeed stop recording commands into 'scout', but it does not switch back to execute mode. To do that, either let the object scout go out of scope or create an AIExecMode object.3) How do you use the transaction mode correctly? Until now I avioded using it, but it would be very helpful and make thinks easier.
My prolem is the following:
local scout = 0;
AISign.BuildSign(tileindex1, "Hello1");
scout = AITransactionMode();
AISign.BuildSign(tileindex2, "Hello2");
scout.Execute();
AISign.BuildSign(tileindex3, "Hello3");
The result is a "Hello1" sign, a "Schild"* sign and no third sign. (*I use German as ingame language: Schild = sign)
In transaction mode the sign isn't labeled, why?
The Execute() command should end the transaction mode and switch back to the normal mode or not?
Sign "Hello2" is a bug? Ok, maybe other things building is ok...
Re: Noob - questions
If you can reproduce the problem with your AI, but not with other AIs, the best is to post your AI as it is now (no matter how much debug code or whether it works or notEton wrote:I use r14122-noai and the computer power should be sufficient. The AI is in an early stadium, but I try to post it later.
I think the following code does what your want (except for renaming the first instead of the second sign to "Hello2", but as I stated before, that is a bug of AISign.BuildSign in combination with AITransactionMode).How can I let the object scout go out of scope??
Sign "Hello2" is a bug? Ok, maybe other things building is ok...
Code: Select all
local tileindex = 10000;
AISign.BuildSign(tileindex, "Hello1");
{
local scout = AITransactionMode();
AISign.BuildSign(tileindex + 2, "Hello2");
scout.Execute();
}
AISign.BuildSign(tileindex + 4, "Hello3");
Re: Noob - questions
Most ingame distances (ie for profit) are calculated with the manhattan distance. If you want to compare the square root of AITile.GetSquareDistance() to 5, why not compare it (without square root) to 25?Eton wrote:I wanted to use it with AITile.GetSquareDistance(). Now I use it to valuate, but it would be fine to have the exact distance...Yexo wrote:You can't, but you shouldn't need to. Why do you want to do this?Eton wrote: 1) How can you get the squareroot from a number, exists there a command like "sqrt{9}"?
Re: Noob - questions
Thankfully you can approximate sqrt as follows. This is using integer mathematics so its not perfect, but its better than nothing.Eton wrote:1) How can you get the squareroot from a number, exists there a command like "sqrt{9}"?
Code: Select all
/*
* Integer square root. This function was converted from the C++ version found
* at codecodex.com.
*/
function sqrt(num) {
if (0 == num) {
return 0;
}
local n = (num / 2) + 1;
local n1 = (n + (num / n)) / 2;
while (n1 < n) {
n = n1;
n1 = (n + (num / n)) / 2;
}
return n;
}
PathZilla - A networking AI - Now with tram support.
Re: Noob - questions
Of course this is possible, but again: Why is it usefull?Zutty wrote:Thankfully you can approximate sqrt as follows. This is using integer mathematics so its not perfect, but its better than nothing.Eton wrote:1) How can you get the squareroot from a number, exists there a command like "sqrt{9}"?
Re: Noob - questions
Well, sqrt also quite useful to work out an approximate "city area" from its population.
Re: Noob - questions
It is not a problem that only concerns my ai. When I run WrightAI or Convoy the game speed also gets slower.
Especially with Convoy and it's amount of vehicles.
How should I post the AI, I can't link it and it would spam this thread...
@Yexo: Your transaction mode solution is good for me, I'll use it.
Concerning sqrt{}, it is not really useful for me, but it looks more nice in the code...
@Zutty: Thanks for the formula, but I already compare the squaredistance with i * i and it works, so i'll leave it.
Especially with Convoy and it's amount of vehicles.
How should I post the AI, I can't link it and it would spam this thread...
@Yexo: Your transaction mode solution is good for me, I'll use it.
Concerning sqrt{}, it is not really useful for me, but it looks more nice in the code...
@Zutty: Thanks for the formula, but I already compare the squaredistance with i * i and it works, so i'll leave it.
-
- Engineer
- Posts: 72
- Joined: 09 Apr 2006 23:49
- Location: UK
- Contact:
Re: Noob - questions
I already stated ages ago myself that using sqrt for calculating diagonal distances (ie; the ones planes, ships and trains can use) may help if you want to know how fast a route is, not just how physically far apart the game thinks two locations are.
Finaldeath
Re: Noob - questions
Either make a tar-file if you want to use a NoAI-comptible file format for storing your ai without needing other people to "decode" the tar-file. (tar-files are not compromized just many files in one file). Or you put them in a zip-file. But upload the archive file to the forum using post attachement. If you fail to make any archive-file then you can rename your main.nut as main.nut.txt and upload it as an attachment. And possible the same with the info.nut file.Eton wrote:How should I post the AI, I can't link it and it would spam this thread...
There is also paste-bins such as paste.openttd.org, but it is better if you use attachments as they are more permanent than paste-bins and don't rely on another system than the forum-system.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Noob - questions
Ok, here my AI, the name is still "MtestAI";-)
It has difficulties with water and a start date between 1956 and 1989 is good (because of the airport size).
I have still problems with the game speed, bud I doubt that it is because of my AI.
It builds only one air route, very simple.It has difficulties with water and a start date between 1956 and 1989 is good (because of the airport size).
I have still problems with the game speed, bud I doubt that it is because of my AI.
Who is online
Users browsing this forum: No registered users and 5 guests