wesnoth-wiki-changes
[Top][All Lists]
Advanced

[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   传奇私服登陆器]
+
+
+






reply via email to

[Prev in Thread] Current Thread [Next in Thread]