Any C++ <-> Python programmers interested in contribut
Moderator: Forum Moderators
Re: Add HP properties in ai_python
Oh, someone else working on a python AIviorc wrote: Having that feature included allowed me to get my first python AI grown level2 unit![]()


But, mine always wins against sample_ai already by now

Re: someone else working on a python AI
This story you tell us is painfully familiar to meallefant wrote: .. although, right now mine would not have much chance. It can usually only defend for a few turns against ai2 until my leader gets assassinated![]()

If you want a quite real benchmark(*) of my python AI for now, it is:
- level 2 units occured less than 5 times
- for most of the game, I lose between turn 10 and turn 25
- my longuest games were around 45 turns (less than 5 times)
- python AI won once


I hope it will help to burst the myth

(*) playing on scenario multiplayer3pTripleBlitz against 2 standard AI, most recently with python AI using only side3=Rebels (for elves, so I can use my leadership implementation). Played around 250 games.
get_destinations_by_unit question
I have created a wiki page http://www.wesnoth.org/wiki/GetDestinat ... itQuestion where I describe a - according to me - strange behaviour of the function get_destinations_by_unit(). Could you check and help me understand what is happening.
Thanks for your time.
Thanks for your time.
Here's how it works in my AI:
- call wesnoth.get_units(), filter out the units i want (own, enemy, allied..)
- once a valid unit location is found that way, get the possible destinations for it by calling wesnoth.get_destinations_by_unit()[location]
All other uses of get_destinations_by_unit lead to bugs. I assume, there was a performance reason for doing it that way. Of course, a nicer API in my opinion would be to remove get_desitnations_by_unit and get_units_by_destination completely, and instead have:
unit.get_reachable_locations() -> returns a list of possible locations
and
location.get_reachable_units() -> return a list of units who can reach it
But I have no idea if it would be reasonable to do this..
- call wesnoth.get_units(), filter out the units i want (own, enemy, allied..)
- once a valid unit location is found that way, get the possible destinations for it by calling wesnoth.get_destinations_by_unit()[location]
All other uses of get_destinations_by_unit lead to bugs. I assume, there was a performance reason for doing it that way. Of course, a nicer API in my opinion would be to remove get_desitnations_by_unit and get_units_by_destination completely, and instead have:
unit.get_reachable_locations() -> returns a list of possible locations
and
location.get_reachable_units() -> return a list of units who can reach it
But I have no idea if it would be reasonable to do this..
Is there any other known bugs in the python API ?
I am currently facing a problem of memory leak when running the python AI.
On any subject, I would think I am doing things wrong rather than expecting a bug. However the memory allocation in python is supposed to be completely transparent. I just can not see a way to mess up things to introduce this leak.
I noticed that the more calls I am making to the function wesnoth.get_destinations_by_unit, the bigger the leak is. I am currently calling this function roughly once per turn per unit, the wesnoth executable can reach a size of 300Mb after 50 turns (python AI having between 10 and 20 units).
That is enough to crash my computer (short of swap space)
Should I take any additional care about memory in python because the AI script is launched from a C++ process ?
Have you noticed anything similar with your own python AIs ?
Thanks for help.
(Computer running Linux Fedora Core 4 with gcc 4.0.2, python 2.4.1, wesnoth SVN version from Mar 15th)
On any subject, I would think I am doing things wrong rather than expecting a bug. However the memory allocation in python is supposed to be completely transparent. I just can not see a way to mess up things to introduce this leak.
I noticed that the more calls I am making to the function wesnoth.get_destinations_by_unit, the bigger the leak is. I am currently calling this function roughly once per turn per unit, the wesnoth executable can reach a size of 300Mb after 50 turns (python AI having between 10 and 20 units).
That is enough to crash my computer (short of swap space)

Should I take any additional care about memory in python because the AI script is launched from a C++ process ?
Have you noticed anything similar with your own python AIs ?
Thanks for help.
(Computer running Linux Fedora Core 4 with gcc 4.0.2, python 2.4.1, wesnoth SVN version from Mar 15th)
-
- Retired Developer
- Posts: 1086
- Joined: September 16th, 2005, 5:44 am
- Location: Hamburg, Germany
Have you tried to skip the call to get_destinations_by_unit? What happens to the memory leak then?
Oh and don't think we are C++ gurus writing perfect code all the time. I have seen (and probably introduced) a lot uninitialized variables, invalid pointers, crashes...
It honors you to search the failure in your code first, but there is a good chance that wesnoth still has a bug. Especially if it is something subtle as a memory leak.
Oh and don't think we are C++ gurus writing perfect code all the time. I have seen (and probably introduced) a lot uninitialized variables, invalid pointers, crashes...
It honors you to search the failure in your code first, but there is a good chance that wesnoth still has a bug. Especially if it is something subtle as a memory leak.
Smart persons learn out of their mistakes, wise persons learn out of others mistakes!
Re: someone else working on a python AI
3p maps are inherently unbalanced. Why are you using them to benchmark your AI?viorc wrote:playing on scenario multiplayer3pTripleBlitz against 2 standard AI, most recently with python AI using only side3=Rebels (for elves, so I can use my leadership implementation). Played around 250 games.
1v1 or 2v2 or even 1v1v1v1 would be better.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
I understand. I can wait - no problem. Thanks for your help.allefant wrote:The python interface won't compile at all with current SVN. I don't want to go back to an older version, so I'll watch memory consumption in my AI once it works again.
It is difficult to say as if I do not call this function, the python AI will probably be dead after 3 turns at most (or crashing due to invalid move).Yogi Bear wrote:Have you tried to skip the call to get_destinations_by_unit? What happens to the memory leak then?
The exe file is around 60Mb at start so reaching 300 Mb is quite large leak. I think it must be python AI specific otherwise some else would have complain earlier (I already played UtBS campaign where number of turns can go over 70 without problem).Yogi Bear wrote: [...] there is a good chance that wesnoth still has a bug. Especially if it is something subtle as a memory leak.
Well I do not know, it was the one referenced on the python API wiki page. It is still quite OK as:Sapient wrote: 3p maps are inherently unbalanced. Why are you using them to benchmark your AI?
- the fight is arriving quickly so it is easier to test the attack-defense code (probably the easiest part to write). After 3 turns, I can see if my leader is dead or not. Very helpful to reject bad ideas

- the villages are plenty so I can basically only implement 1- fight and 2- village search. This will be insufficient on the long term, but who can say there will be one !

However I would be happy to try another map, so if you can suggest one ...
Is 1v1v1 map more unbalanced than 1v1v1v1 ? Why is that ?