[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-wiki-changes] WritingYourOwnAI
From: |
wiki |
Subject: |
[Wesnoth-wiki-changes] WritingYourOwnAI |
Date: |
Thu, 4 Nov 2004 10:50 +0100 |
UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041102
Firefox/1.0RC1
IP: 168.209.98.67
URI: http://wesnoth.slack.it/?WritingYourOwnAI
- - - - -
Index: WritingYourOwnAI
===================================================================
RCS file: /home/wesnoth/cvsroot/wikiroot/WritingYourOwnAI,v
retrieving revision 1.11
diff -u -r1.11 WritingYourOwnAI
--- WritingYourOwnAI 4 Nov 2004 09:24:33 -0000 1.11
+++ WritingYourOwnAI 4 Nov 2004 09:50:38 -0000
@@ -1,7 +1,7 @@
Wesnoth supports a pluggable AI system that allows programmers to write their
own AIs in C++.
-To write an AI, you need to derive a class from ''ai_interface'' (defined in
''ai.hpp''),
-and implement the function ''play_turn()''
+To write an AI, you need to derive a class from ''ai_interface''
+(defined in ||ai.hpp||), and implement the function ''play_turn()''
which will be called every time your AI is expected to play a turn.
Class ''ai_interface'' contains three important functions
@@ -17,20 +17,20 @@
the types of units your side can recruit,
and information about your allies and enemies.
-Firstly, a type 'location' is defined, which defines any location on the map.
-It has members 'x' and 'y'. In ''pathfind.hpp'' there are a number of functions
+Firstly, a type ''location'' is defined, which defines any location on the map.
+It has members ''x'' and ''y''. In ||pathfind.hpp|| there are a number of
functions
which will tell you useful things about locations -- whether two locations
are adjacent, all the locations adjacent to a certain location,
and the distance between locations.
-A type ''move_map'' is defined as a ''std::multimap<location,location>''.
-''std::multimap'' is of course a standard C++ container,
+A type ''move_map'' is defined as a ''std::multimap< location,location >''.
+Note that ''std::multimap'' is of course a standard C++ container,
and cannot be documented here. http://www.sgi.com/tech/stl/ is
a good reference on standard C++ containers.
The purpose of a ''move_map'' is to show all the possible moves for a side.
-It can either be a 'source -> destination' map, which
+It can either be a //source -> destination// map, which
associates the locations of all the units a side has to all the possible
-places they can move to, or a 'destination -> source' map,
+places they can move to, or a //destination -> source// map,
which associates all the locations all the units a side has can get to,
to all the places they are now.
@@ -40,27 +40,27 @@
can move when it's their turn. This is a very important
function to use to work out all the possible places your units can move to.
-''ai_interface'' also defines an 'info' type.
+''ai_interface'' also defines an ''info'' type.
This type contains a number of references to various game objects which you
will need access to in order to make moves.
The two most important of these objects are the unit map (unit_map units)
and the game map (gamemap map).
-The unit map is of type ''std::map<location,unit>''
+The unit map is of type ''std::map< location,unit >''
and associates locations with units.
This object can be used to find the
location of, and information about, every unit on the board.
-See ''unit.hpp'' for a definition of the 'unit' object.
+See ||unit.hpp|| for a definition of the ''unit'' object.
The game map allows you to inspect the dimensions and layout of the playing
board.
Given a location, it can tell you the
terrain type at that location.
-See ''map.hpp'' for a definition of this object.
+See ||map.hpp|| for a definition of this object.
You can combine this class with use of the
-functions in ''pathfind.hpp'' to find various
+functions in ||pathfind.hpp|| to find various
information about where units can move to.
-The team class (defined in ''team.hpp'') is also very important.
+The team class (defined in ||team.hpp||) is also very important.
Each side is represented by a ''team'' object. The team
object can tell you the gold balance of a team, which villages
(note that internally, villages are often called 'towers')
@@ -82,7 +82,7 @@
---
Finally, when you have your AI ready to go,
-you can add it to the ''create_ai()'' function in ''ai.cpp''. Suppose you
called
+you can add it to the ''create_ai()'' function in ||ai.cpp||. Suppose you
called
your class ''killer_ai'', you could add it like so:
if(name == "killer_ai")
@@ -114,8 +114,8 @@
In the following example, I will place all functions in-line
rather than in the cpp file. To do this properly, of
course you should put them in the cpp file.
-The entire definition of this AI can be found in ''ai.cpp/ai.hpp'' in the
-source distribution.
+The entire definition of this AI can be found
+in ||ai.cpp|| and ||ai.hpp|| in the source distribution.
We start the definition,
@@ -212,7 +212,7 @@
assert(un != get_info().units.end());
We can assume that the unit is in that location (hence the assert),
-because ''calculate_possible_moves'' said that it's the possible source of a
move.
+because ''calculate_possible_moves()'' said that it's the possible source of a
move.
Let's find out the type of terrain we're planning to move to:
const gamemap::TERRAIN terrain =
get_info().map.get_terrain(dst);
@@ -306,16 +306,16 @@
A rather complicated function call, but most of
the parameters can be pulled straight from ''get_info()''.
-The last two parameters are a little confusing:
-the first one, ''attacker_terrain_override'' is used
+The last two parameters are a little confusing.
+The first one of these, ''attacker_terrain_override'', is used
if we wanted to know what the combat would look like
if the attacker was on different terrain to what it is on now.
If this is non-0, the function will assume
the attacker is on the type of terrain given.
This is useful if you want to test the possibility of moving
to many different hexes without actually moving there.
-
-The last parameter is false, meaning that strings won't be included in the
results.
+The last parameter is false, meaning that
+strings won't be included in the results.
Strings are useful for showing to a player in a dialog,
but not useful for an AI, and are expensive to calculate,
so this should always be false from within AI algorithms.
@@ -414,7 +414,7 @@
}
}
-If closest_distance is not -1, we've found a valid move that'll take
+If ''closest_distance'' is not -1, we've found a valid move that'll take
one of our units toward the enemy leader. We can make the move and recurse
if(closest_distance != -1) {
@@ -446,7 +446,7 @@
};
That's it! We've made our ''sample_ai''.
-All we have to do is add it to ''create_ai'' in ''ai.cpp'' and we're done!
+All we have to do is add it to ''create_ai'' in ||ai.cpp|| and we're done!
||AI - specific parameters||