PythonAISampleCode
From Wesnoth
Contents |
PythonAISampleCode
This page contains some code samples for the Python AI.
Attack or move sample AI
A small sample AI which will either attack an enemy or move to a fixed location is posted in the following forum thread http://www.wesnoth.org/forum/viewtopic.php?t=12655.
Reload a module sample code
Imagine the following two scripts:
ai_main.py
#!WPY
import wesnoth, ai_helper
class AI:
def __init__( self ):
foo = ai_helper.bar()
AI()
ai_helper.py
class bar:
def __init__( self ):
print 'Hello wrold' # (yes, there's a typo)
After fixing the typo in ai_helper.py after the first turn the AI will from turn 2 on switch to printing the corrected message. This was different in previous versions of the AI where only the main script would be reloaded. In the future, the main script as well as imported scripts may get cached, in which case a debug commando will be introduced to reload all scripts.
See also
This page was last modified on 20 March 2008, at 14:40.
