[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: |
Sun, 3 Oct 2004 04:44 +0200 |
UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
IP: 218.18.46.247
URI: http://wesnoth.slack.it/?WritingYourOwnAI
- - - - -
Index: WritingYourOwnAI
===================================================================
RCS file: /home/wesnoth/cvsroot/wikiroot/WritingYourOwnAI,v
retrieving revision 1.5
diff -u -r1.5 WritingYourOwnAI
--- WritingYourOwnAI 22 Apr 2004 01:27:00 -0000 1.5
+++ WritingYourOwnAI 3 Oct 2004 02:44:57 -0000
@@ -1,6 +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.
ai_interface contains three important functions which allow you to execute the
three basic types of move available in
@@ -18,7 +19,8 @@
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>.
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
associates the locations of all the units a side has to all the possible
places they can move to, or a 'destination ->
@@ -32,10 +34,12 @@
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> and associates locations with
units. This object can be used to find the
+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.
-The game map allows you to inspect the dimensions and layout of the playing
board. Given a location, it can tell you the
+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 You
can combine this class with use of the
functions in pathfind.hpp to find various information about where units can
move to.
@@ -73,11 +77,13 @@
best defensive terrain next to them. Attacks should be made with the weapon
for which damage*strikes*chance to hit is
the highest
- if there are no enemies in range, it should move units onto villages that
don't already belong to it
-- if there are no enemies or villages in range, it should move toward the
enemy leader along the shortest possible route.
+- if there are no enemies or villages in range, it should move toward the
enemy leader along the shortest possible
+route.
- at the end of its turn, it should recruit random units until it runs out of
money or doesn't have any space
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
+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.
We start the definition,
@@ -108,7 +114,8 @@
calculate_possible_moves(possible_moves,srcdst,dstsrc,false);
Note that the 'possible_moves' thing is of little direct interest. It contains
details of exactly which tiles the unit
-moves along to get from one tile to another. This is useful for the display to
know about when it draws the unit moving,
+moves along to get from one tile to another. This is useful for the display to
know about when it draws the unit
+moving,
but as an AI programmer, it's likely you'll ever care about what it contains.
Just pass it along to the move_unit()
function so it can draw the unit moving along the correct path.
@@ -126,7 +133,8 @@
location adjacent_tiles[6];
get_adjacent_tiles(i->first,adjacent_tiles);
-This kind of call is very common in the game's code -- make an array of 6
locations, and fill them up with the locations
+This kind of call is very common in the game's code -- make an array of 6
locations, and fill them up with the
+locations
adjacent to a certain location. We actually want to find the position to
attack from which gives our unit the best
possible defense. So, we initialize some variables to find the best possible
defense:
@@ -196,7 +204,8 @@
const int weapon =
choose_weapon(best_movement.first,i->first);
attack_enemy(best_movement.first,i->first,weapon);
-This will implement our attack. What now? We've attacked once, but we want to
attack with as many units as we can attack
+This will implement our attack. What now? We've attacked once, but we want to
attack with as many units as we can
+attack
with, right? We can't use the same move_maps again, because they'll be invalid
now that we've moved and attacked. What
we'll do is we'll call do_attacks() all over again, recursively, and return
immediately. This way all our maps will be
recalculated.
@@ -208,7 +217,8 @@
}
}
-That's the entire function done. It'll keep attacking while it finds attacks,
and when it finally runs out of attacks to
+That's the entire function done. It'll keep attacking while it finds attacks,
and when it finally runs out of attacks
+to
execute, it'll return nicely. Let's write that choose_weapon() function now:
int choose_weapon(const location& attacker, const location& defender) {
@@ -224,11 +234,13 @@
int best_attack = -1;
for(int n = 0; n != attacks.size(); ++n) {
-There is a nice function called evaluate_battle_stats() in actions.hpp which
will give us all sorts of information about
+There is a nice function called evaluate_battle_stats() in actions.hpp which
will give us all sorts of information
+about
a potential battle. We make use of it here:
const battle_stats stats =
-evaluate_battle_stats(get_info().map,attacker,defender,n,get_info().units,get_info().state,get_info().gameinfo,0,false);
+evaluate_battle_stats(get_info().map,attacker,defender,n,get_info().units,get_info().state,get_info
+().gameinfo,0,false);
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 if we wanted to know what the
@@ -237,7 +249,8 @@
to many different hexes without actually moving there.
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
+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.
Let's use our stats to come up with a rating for this attack:
@@ -368,3 +381,281 @@
||See Also||
* HomePage
+
+
+http://wesnoth.slack.it/?HomePage
+**************Please do not delete,I send this message only one time,in order
to introduce some china website.IF you
+delete,I will publish every day.***************
+
+I am from china,I want to introduce some very good chinese sites to you ,so
you can find something about china
+cluture,people.
+
+[http://www.ec51.com/ importers]
+[http://www.ec51.com/ distributors]
+[http://www.ec51.com/ buyers]
+[http://www.ec51.com/sitemap.htm EC51 sitemap]
+[http://www.58798309dyb.com/ å
¬å¸æ³¨åï¼æ³¨åå
¬å¸]
+[http://www.ec198.com/ ç½ç«æ¨å¹¿]
+[http://www.ec198.com/ ç½ç«æå]
+[http://www.ec51.cn/ Googleæå]
+[http://www.ec51.cn æç´¢å¼ææå]
+[http://www.ec51.org/ ç½ç«å»ºè®¾]
+[http://www.58798309dyb.com/ å
¬å¸æ³¨å]
+[http://www.58798309dyb.com/ 注åå
¬å¸]
+[http://www.58798309dyb.com/ ä¸æµ·å
¬å¸æ³¨å]
+[http://www.58798309dyb.com/ æµ·å¤å
¬å¸æ³¨å]
[http://www.ec51.com/index1.php å¤è´¸]
+[http://glassfurniture.ec51.net glass furniture]
+[http://officefurniture.ec51.net/ office furniture]
+[http://washer.ec51.net/ washer]
+[http://padlock.ec51.net/ padlock]
+[http://handbag.ec51.net/ handbags]
+[http://diamond-saw-blades.ec51.net/ Diamond Saw Blades]
+[http://backpack.ec51.net/ backpack]
+[http://briefcase.ec51.net/ briefcase]
+[http://jewellery.ec51.net/ jewellery]
+[http://www.xmtmdart.com Dartboard]
+[http://www.ec51.com/info.php ä¾æ±ä¿¡æ¯]
+[http://www.ec51.com/com.php å
¬å¸åº]
+[http://www.ec51.com/pro.php 产ååº]
+[http://www.ec51.com/en/info.php tradeleads]
+[http://www.ec51.com/en/com.php company diretory]
+[http://www.ec51.com/en/pro.php products]
+[http://www.58798309dyb.com/news.asp?id=188 ç½ç»ç§æå
¬å¸æ³¨å]
+[http://www.58798309dyb.com/news.asp?id=185 åä¸è´¸æå
¬å¸æ³¨å]
+[http://www.58798309dyb.com/news.asp?id=184 é
åºç®¡çå
¬å¸æ³¨å]
+[http://www.ec51.com/en/info.php/ B2B offers]
+[http://www.ec51.com/en/com.php/ china suppliers]
+[http://www.ec51.com/en/pro.php/ china products]
+[http://www.ec198.com ç½ç«æ¨å¹¿]
+[http://www.ec51.cn èæ主æºï¼ç½ç«å»ºè®¾]
+[http://www.ec51.cn/web.htm ç½é¡µè®¾è®¡]
+[http://www.ec51.cn/isp.htm ç½ç«ç©ºé´]
+[http://www.ec91.com ç½å大å
¨]
+[http://www.ec91.com/chat.htm è天]
+[http://www.ec91.com/love.htm 交å]
+[http://www.ec51.com/wz ç½å大å
¨]
+[http://www.ec91.com/program.htm ç§æ]
+[http://www.ec91.com/fcys.htm æ¿äº§]
+[http://www.ec91.com/szsm.htm æ¶è£
åè´¸]
+[http://www.ec91.com/zjzz.htm æ¿åºç»ç»]
+[http://www.ec91.com/nav.htm çä¼åå¸]
+[http://www.ec51.com/link.htm åæ
é¾æ¥]
+[http://www.ec51.cn ç½é¡µè®¾è®¡]
+[http://www.ec51.org yahooæå]
+[http://www.ec91.com ç½åç²¾é]
+[http://www.58798309dyb.com/ å¤è´¸å
¬å¸æ³¨å]
+[http://www.58798309dyb.com/ ä¸æµ·æ³¨åå
¬å¸]
+[http://www.58798309dyb.com/ é«ç§æå
¬å¸æ³¨å]
+[http://www.58798309dyb.com/ ç¾å½å
¬å¸æ³¨å] ã
+[http://www.58798309dyb.com/ å·¥å注å]
+[http://www.58798309dyb.com/ ä¸æµ·å·¥å注å] ã
+[http://hotel.ec51.net é
åºé¢è®¢]
+[http://datahf.ec51.net æ°æ®æ¢å¤]
+[http://ticket.ec51.net æºç¥¨]
+[http://translate.ec51.net ç¿»è¯å
¬å¸]
+[http://manger.ec51.net 管çå¨è¯¢]
+[http://marketing.ec51.net ç½ç»è¥é]
+[http://meeting.ec51.net è§é¢ä¼è®®]
+[http://notebook.ec51.net ç¬è®°æ¬çµè]
+[http://zippo.ec51.net Zippoæç«æº]
+[http://projector.ec51.net æå½±æº]
+[http://projector.ec51.net æ影仪]
+[http://figer.ec51.net èå¤æº]
+[http://figer.ec51.net æ纹èå¤æº]
+[http://brank.ec51.net åæ 注å] ã
+[http://brank.ec51.net ç¾å½åæ 注å]
+[http://lawyer.ec51.net å¾å¸]
+[http://lawyer.ec51.net å¾å¸äºå¡æ]
+[http://safety.ec51.net å®é²]
+[http://safety.ec51.net çæ§]
+[http://adult.ec51.net æ人ç¨å]
+[http://adult.ec51.net æ§ç¨å] ã
+[http://adult.ec51.net æ
趣ç¨å]
+[http://toy.ec51.net ç©å
·]
+[http://toy.ec51.net çµåç©å
·]
+[http://toy.ec51.net çæºç©å
·]
+[http://toy.ec51.net æ¯ç»ç©å
·]
+[http://toy.ec51.net å¡«å
ç©å
·]
+[http://gate.ec51.net é¨ç¦ç³»ç»]
+[http://gate.ec51.net é¨ç¦]
+[http://solar.ec51.net 太é³è½çæ°´å¨]
+[http://solar.ec51.net 太é³è½]
+[http://saftey.ec51.net å®é²è®¾å¤]
+[http://office.ec51.net æ·±å³åå楼]
+[http://office.ec51.net åå楼åºç§]
+[http://office.ec51.net åå楼åºå®]
+[http://washer.ec51.net/ washer]
+[http://padlock.ec51.net/ padlock]
+[http://setm.ec51.com Industrial Lighting Fitting]
+[http://binoculars.ec51.com binocular]
+[http://qimingkeji.ec51.com paint&pigment]
+[http://HANSEN202.ec51.com TEXTILES & GARMENTS]
+[http://sunnywang.ec51.com glasses]
+[http://reasonlee.ec51.com lawn mower]
+[http://sunrise.ec51.com wood]
+[http://chinalj.ec51.com chairs]
+[http://bead.ec51.com evening dress]
+[http://chemshine.ec51.com chemicals]
+[http://henryfoo.ec51.com Digital Vidicon]
+[http://xmtm.ec51.com dart&dartboard]
+[http://zhh0406.ec51.com silicon metal]
+[http://yzgt.ec51.com Fiberglass]
+[http://sztyh.ec51.com Bowling equipment]
+[http://realtex.ec51.com GRIPPER HEAD]
+[http://jamezhang.ec51.com sports]
+[http://dove.ec51.com golf ball]
+[http://ttichina.ec51.com pocket bike]
+[http://eastgrace.ec51.com kid's garment]
+[http://gjjgzjl.ec51.com Building hoist]
+[http://greattorch.ec51.com consumer electronics]
+[http://allproducts.ec51.com security products]
+[http://bath-duschy.ec51.com bath & shower products]
+[http://bowei.ec51.com wiring accessories]
+[http://shininess.ec51.com socket&switch]
+[http://fujin.ec51.com Solar module]
+[http://PeterHang.ec51.com textiles]
+[http://Micro.ec51.com Mobile Phone Accessories & parts]
+[http://lynnleng.ec51.com Diamond Tools]
+[http://morgancb.ec51.com wader&raincoat]
+[http://markckj.ec51.com home accessories]
+[http://cntbc.ec51.com Fabric]
+[http://gdbasex.ec51.com toys]
+[http://FSQuince.ec51.com Photo frame]
+[http://admetus.ec51.com lighting glass]
+[http://huyunbei.ec51.com home supplies]
+[http://mtglobal.ec51.com Mini Radio]
+[http://aschem.ec51.com DETERGENT PODWER]
+[http://yztscl.ec51.com Knitted T-shirts]
+[http://craft-st.ec51.com Decorations]
+[http://romy.ec51.com jewelry]
+[http://yiqing.ec51.com steam cleaner]
+[http://winchem.ec51.com glass beads]
+[http://salina.ec51.com outerwear]
+[http://zhouxun.ec51.com DVD&VCD player]
+[http://rainton.ec51.com INJECTION PUMPS]
+[http://hmbusiness.ec51.com pharmaceutical machinery]
+[http://linuosh.ec51.com crystal glass]
+[http://cymotor.ec51.com UNIVERSAL MOTOR]
+[http://cccrystal.ec51.com crystal pendant]
+[http://aduis.ec51.com glasses]
+[http://zkl955151.ec51.com shower cabin]
+[http://zmzhang77.ec51.com textiles]
+[http://oceanwd.ec51.com Stationery]
+[http://yufeng168.ec51.com Detergent powder]
+[http://zytrading.ec51.com light decoration]
+[http://Shinestar.ec51.com Shinestar]
+[http://cnyuanda.ec51.com air purifiers]
+[http://sunyard.ec51.com ribbon bow]
+[http://hbzili.ec51.com PVC Doormats]
+[http://cjwxx.ec51.com chemical]
+[http://fine520.ec51.com phytic acid]
+[http://cmechubei.ec51.com diesel engine]
+[http://SPC_GROUP.ec51.com jointing equipment]
+[http://cosmor.ec51.com auto accessories & parts]
+[http://Mondorocn.ec51.com home furniture]
+[http://jsglass008.ec51.com Thermomete]
+[http://goodwin.ec51.com CANDLES]
+[http://kugo.ec51.com stationery]
+[http://dan9.ec51.com socks]
+[http://harmonygmt.ec51.com Leather Garment]
+[http://hongji88.ec51.com ZIPPER&button]
+[http://yoingjiang.ec51.com tableware]
+[http://duori.ec51.com electromechanical equipment]
+[http://newtime01.ec51.com home supplies]
+[http://wjc922.ec51.com ELECTRONIC&plastic]
+[http://powtele.ec51.com PROJECTOR]
+[http://xmhny.ec51.com oxygen bar series]
+[http://shwztrade.ec51.com Fiberglass products]
+[http://weiasdhong.ec51.com dress]
+[http://salebattery.ec51.com Nimh batteries&chargers]
+[http://decomin.ec51.com Fan]
+[http://Hitrade.ec51.com Gifts and decorative items ]
+[http://fhsy888.ec51.com steel glass]
+[http://fc320.ec51.com 广交ä¼]
+[http://homesourcing.ec51.com Sourcing products]
+[http://tcgy.ec51.com WOODEN PHOTO FRAMES]
+[http://jsue01.ec51.com camera]
+[http://kaipengcz.ec51.com spun bond fabric]
+[http://hctysyb.ec51.com sodium antimonate]
+[http://janet1207.ec51.com oil filter]
+[http://swwsd.ec51.com bromic acid natrium]
+[http://mikewolf.ec51.com fabrics products]
+[http://molina.ec51.com faucet&valve]
+[http://Anglo-Thai.ec51.com Clothing]
+[http://unitrans.ec51.com Ceramic Tile]
+[http://tqcj1972.ec51.com steel cutlery]
+[http://Shiny.ec51.com Electric Tools]
+[http://yhjhzg.ec51.com Gifts & Crafts]
+[http://suzyzheng.ec51.com Remote Control toys]
+[http://sdmark.ec51.com PE&PO&PP]
+[http://qiangmin.ec51.com Leather Shoes]
+[http://zgybsh.ec51.com medicine]
+[http://cjacja.ec51.com sweater]
+[http://cnscooter.ec51.com Electric Scooter]
+[http://kwanwa.ec51.com digital watch]
+[http://tiane.ec51.com artificial Crafts]
+[http://sintecasia.ec51.com boot]
+[http://sunko.ec51.com SPEAKER]
+[http://zhongdan.ec51.com Bamboo ]
+[http://walget.ec51.com glass&ceramic]
+[http://ykstx.ec51.com POCKET BIKE]
+[http://yk1107.ec51.com power tools]
+[http://sunwayltd.ec51.com plastic]
+[http://linksino.ec51.com LS brand products ]
+[http://shichangzhou.ec51.com wooden easel]
+[http://huangzx.ec51.com reflective vest]
+[http://checkout.ec51.com Luggage]
+[http://Johnyuan.ec51.com sport shoe]
+[http://crystal8098.ec51.com MCB&RCCB]
+[http://alex.ec51.com Bedspread]
+[http://risinginstru.ec51.com pressure gauge]
+[http://www.ec51.cn/newsweb ç½ç«æ¨å¹¿]
+[http://www.ec51.cn/newsweb/gr ç½ç«æå]
+[http://www.ec51.cn/newsweb/sr googleæå]
+[http://www.ec51.cn/newsweb/dzsw æç´¢å¼ææ¨å¹¿]
+[http://tomshi.ec51.com è¿åºå£]
+[http://binoculars.ec51.net/ æè¿é]
+[http://binoculars.ec51.net/ é«åæè¿é]
+[http://www.nodsoft.com/newsweb é®ä»¶ç³»ç»]
+[http://www.nodsoft.com/newsweb/dzsw ä¼ä¸é®å±]
+[http://www.nodsoft.com/newsweb/gr æ ¡åç½]
+[http://www.nodsoft.com/newsweb/index9 çµåæ¿å¡]
+[http://dart.freewebpage.org dartboard]
+[http://stationary.ec51.net æå
·]
+[http://lighting.ec51.net ç¯é¥°ï¼ç¯å
·]
+[http://ec.ec51.net äºçº§ç®¡,ä¸æ管]
+[http://louder.ec51.net æ¬å£°å¨]
+[http://crafts.ec51.net å·¥èºå]
+[http://switch.ec51.net å¼å
³]
+[http://charger.ec51.net çµæ± ]
+[http://generator.ec51.net åçµæº]
+[http://wire.ec51.net çµçº¿ãçµç¼]
+[http://ic.ec51.net éæçµè·¯]
+[http://capacitor.ec51.net çµå®¹å¨]
+[http://transformer.ec51.net ååå¨]
+[http://linker.ec51.net è¿æ¥å¨]
+[http://sensor.ec51.net ä¼ æå¨]
+[http://accumulator.ec51.net èçµæ± ]
+[http://of.ec51.net åå
¬å®¶å
·]
+[http://dishware.ec51.net é¤å
·]
+[http://con.ec51.net 建æ]
+[http://leather.ec51.net ç®é©]
+[http://sports.ec51.net ä½è²ç¨å]
+[http://camera.ec51.net æ°ç ç¸æº]
+[http://dyb.freewebpage.org 注åå
¬å¸]
+[http://www.ec61.com ãæç´¢å¼ææå]
+[http://www.ec31.com ç½ç«æ¨å¹¿]
+[http://wiki.ec51.org EC51 wiki]
+[http://shop.ec51.net ç½ä¸è´ç©]
+[http://mall.ec51.net ç½ä¸åå]
+[http://buy.ec51.net ç½ä¸æå]
+[http://shop.ec51.net æ趣è´ç©]
+[http://mall.ec51.net æ趣åå]
+[http://buy.ec51.net æ趣æå]
+[http://www.kuangye.net ä¼ å¥ç§æ]
+[http://www.kuangye.net ä¼ å¥ä¸çç§æ]
+[http://www.kuangye.net ä¼ å¥ç§æ论å]
+[http://www.kuangye.net ä¼ å¥ç§æç»éå¨]
+
+
+
- [Wesnoth-wiki-changes] WritingYourOwnAI,
wiki <=