Any C++ <-> Python programmers interested in contribut

Discussion of all aspects of the game engine, including development of new and existing features.

Moderator: Forum Moderators

Ryo
Inactive Developer
Posts: 18
Joined: August 23rd, 2005, 12:50 pm

Post by Ryo »

Applying it to SVN, thanks :)
User avatar
allefant
Units Database Administrator
Posts: 516
Joined: May 6th, 2005, 3:04 pm

Re: Add HP properties in ai_python

Post by allefant »

viorc wrote: Having that feature included allowed me to get my first python AI grown level2 unit 8)
Oh, someone else working on a python AI :) We must make an AI tournament at some point.. 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 :P

But, mine always wins against sample_ai already by now 8)
viorc
Posts: 130
Joined: February 22nd, 2006, 3:03 am

Re: someone else working on a python AI

Post by viorc »

allefant 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 :P
This story you tell us is painfully familiar to me :x I must say it is the same for me.
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 8) (but enemy leaders were mutually killed :lol: )
I hope it will help to burst the myth :wink:

(*) 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.
viorc
Posts: 130
Joined: February 22nd, 2006, 3:03 am

get_destinations_by_unit question

Post by viorc »

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.
User avatar
allefant
Units Database Administrator
Posts: 516
Joined: May 6th, 2005, 3:04 pm

Post by allefant »

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..
viorc
Posts: 130
Joined: February 22nd, 2006, 3:03 am

Is there any other known bugs in the python API ?

Post by viorc »

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) :cry:

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)
Yogibear
Retired Developer
Posts: 1086
Joined: September 16th, 2005, 5:44 am
Location: Hamburg, Germany

Post by Yogibear »

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.
Smart persons learn out of their mistakes, wise persons learn out of others mistakes!
User avatar
allefant
Units Database Administrator
Posts: 516
Joined: May 6th, 2005, 3:04 pm

Post by allefant »

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.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: someone else working on a python AI

Post by Sapient »

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.
3p maps are inherently unbalanced. Why are you using them to benchmark your AI?

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."
viorc
Posts: 130
Joined: February 22nd, 2006, 3:03 am

Post by viorc »

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.
I understand. I can wait - no problem. Thanks for your help.
Yogi Bear wrote:Have you tried to skip the call to get_destinations_by_unit? What happens to the memory leak then?
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: [...] there is a good chance that wesnoth still has a bug. Especially if it is something subtle as a memory leak.
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).
Sapient wrote: 3p maps are inherently unbalanced. Why are you using them to benchmark your AI?
Well I do not know, it was the one referenced on the python API wiki page. It is still quite OK as:
- 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 ! :P
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 ?
Post Reply