Topic: AI enhancement suggestion - wood
SirVer |
Posted at:
2014-01-27, 19:14 UTC+1.0
Theoretically the AI is an interface (see computer_player.cc) and creating a new one orthogonal to the existing one should be straightforward - I do not know how leaky the abstraction is though. As mentioned, the code is a mess in this part of Widelands.
No, that is a terrible idea. Remember: options are bad. They add complexity to the code, add new less used code paths that are then not properly tested and worse of all add confusing things to choose from for the player who just wants to play. A good AI should figure most things out for itself. One dimension of choices are maybe a necessary evil (weak, normal, strong). But adding more parameters is definitively not a good idea. ![]() ![]() |
Tibor Topic Opener |
Posted at:
2014-01-27, 20:27 UTC+1.0
My contribution to discussion :) :
![]() ![]() |
SirVer |
Posted at:
2014-01-27, 21:38 UTC+1.0
Some comments on this:
![]() ![]() |
Tibor Topic Opener |
Posted at:
2014-01-27, 22:06 UTC+1.0
All right, but one exemption - algorithm to create roads. It is not part of AI job, it is implemented as by now and works fine enough, so I would appreciate if some functions for road creation was made accessible from LUA
Edited:
2014-01-27, 23:48 UTC+1.0
![]() ![]() |
SirVer |
Posted at:
2014-01-28, 09:57 UTC+1.0
Well, I do not think there is an exception here. I think how the roads are build is very important for an AI and will distinguish one from another - the bigger the economy the more important become the roads in the center of it. However what you mean is probably path finding - finding a possible road from A to B. This could be exposed through the Lua interface. Maybe something like wl.map.Map.find_path(ignore_immovables) or wl.Map.find_path(start_immovable, stop_immovable, stay_or_roads). But do not expect this to be easy - the path planing inside of Widelands is quite peculiar and makes some assumptions that might not make it suitable for one-off path planning like this. In fact, writing a Lua only version might even be easier in the first place. ![]() ![]() |
einstein13![]() |
Posted at:
2014-01-28, 13:19 UTC+1.0
I was thinking a lot about some algorithms of economy for AI. Most of them are connected with saving information in a memory and using it at the other time. As I remember, the AI functions aren't parallel to the gameplay, so they are functions called by main engine(?). So the variables saved by the functions will disappear when we make a step of game. We can do all the numeric calculations every time, but it is CPU-absorbing. And probably with big empire it will end with terrible lags. Is it good? I don't think so. In my opinion we should make a parallel threads for AI (or just one, but parallel) and make it working. Is it possible to make it as a test (if not working, we can return to an old version)? The road problem is a bit complex too, but I remember that AI in the Settlers II had bad implementation of using it. That was: if you have a traffic jam -> build a road connection between points. After a while AI was building a roads far away from traffic jams. So one point is to add the function of connecting the road, but second one is to think about using it wisely. einstein13 ![]() ![]() |
teppo |
Posted at:
2014-01-28, 17:50 UTC+1.0
I guess that that would bring some interesting bugs. If you consider contributing to Widelands to be a learning opportunity, why not? Else, I think that the AI code could be improved a lot CPU consumption wise, too. ![]() ![]() |
einstein13![]() |
Posted at:
2014-01-28, 21:43 UTC+1.0
Bugs? Only by expanding a forum?
I am learning lots of different things. Widelands is a good project with lots of good people inside. I like you all and want to give some math, algorithm and physics work for you
I don't understand this sentence. Do you think that when we improve AI code, the CPU consumption would be smaller? Probably Now I have one idea: some economy problems (like wood problem here mentioned) can be recalculated with some probability. It can be like:
After that, the special function will not be recalculated every time. Some CPU time will be saved and game will be faster
Edited:
2014-01-28, 21:45 UTC+1.0
einstein13 ![]() ![]() |
SirVer |
Posted at:
2014-01-28, 22:25 UTC+1.0
I do not understand what you want to say. That does not matter if the code is threaded (i.e. parallel) or not. Of course when the simulation progresses your assumptions are immediately outdated.
You do not want to add threaded AI to Widelands. It would be desirable of course, but it will be a major headache to add threading into the simulation since we rely on many places that stuff will only happen one at a time. Adding all the locking and mutexes will make the code even more complicated. Besides, the actual simulation is pretty cheap, so multi threaded is not needed there. But that said, you can make the AI concurrent - i.e. by implementing it in a bunch of Lua coroutines or with some kind of abstraction in c++. This should make it easier to reason about it too. ![]() ![]() |
einstein13![]() |
Posted at:
2014-01-28, 23:22 UTC+1.0
You did it well:
But:
Multi threading don't mean that all those things will happen at one time. It can be like that: Major simulation wants to get AI response --> Call theAI-thread_1 --> Wait for answer --> do the return AI_thread: Wait for call --> Make computing based on the state of map & itself --> return the answer --> Wait for call I did that in one of my project. Don't know it is the best possibility and if it is a good way to make something parallel. I know only that making program multi-threaded is very hard (to make it clear and fast). This is one of possible solution of the problem (outdating assumptions for AI) Second is much more easier, but it has lots of opponents: we can build a special table as global variable where AI can hold assumptions as a numbers. But this is a global variable. It would be easy to check what new_AI is doing. Also this idea can be done as keeping this table in the simulation and giving a pointer* to the table to the AI_function (or whatever it is). *-Can we do it in C++? In pure C it is possible and used. That's about the possible solution I can see here to hold some variables for AI. I'm not a professional programmer! I don't know about all of this. Only some
Edited:
2014-01-28, 23:24 UTC+1.0
einstein13 ![]() ![]() |