Difference between revisions of "FormulaAIBaseAI"

From The Battle for Wesnoth Wiki
(My commits)
(Base Formula AI)
Line 111: Line 111:
  
 
===== Base Formula AI =====
 
===== Base Formula AI =====
As for the base Formula AI, I would divide its development into 3 stages. Each stage would be an independent AI derived from the previous one, so that scenario designers could choose whether to use a Simple, Average or Advanced Formula AI and eventually tweak it.  
+
As for the base Formula AI, I would divide its development into 3 stages. Each stage would be an independent AI derived from the previous one, so that scenario designers could choose whether to use a Simple, Average or Advanced Formula AI and eventually tweak it. I would start with basic implementation of below proposals, tweaking, improving and expanding them over a time.
  
 
Please not that the list below is a draft of this idea and a work in progress - some things may change/move between the types of AI and new proposals may appear any time.
 
Please not that the list below is a draft of this idea and a work in progress - some things may change/move between the types of AI and new proposals may appear any time.
Line 124: Line 124:
 
**importance of the leader - protect it at all cost and don't put him into risk
 
**importance of the leader - protect it at all cost and don't put him into risk
 
**awareness of the objective - kill enemy leader
 
**awareness of the objective - kill enemy leader
**ability to attack in such way, to maximize opponent's damage and minimalize damage taken - so it won't attack a mage with an archer.
+
**ability to attack in way which maximize opponent's damage and minimalize damage taken - so it won't attack a mage with an archer.
 
**ability to divide forces between parts of the map according to enemy positions
 
**ability to divide forces between parts of the map according to enemy positions
  

Revision as of 23:24, 27 March 2008

Introduction

  • Basics
    • My name is Bartek Waresiak and I'm from Poland. I'm 21 years old male interested in programming, computer science and gaming. I'm studying Information Technology, 2nd year at AGH University of Science and Technology in Cracow, Poland. By participating in Google Summer of Code I want to become C++ Battle for Wesnoth developer, gain experience in programming for an Open Source project and increase my level of C++ and object-oriented programming knowledge, have fun and earn some money. You can contact me on IRC or forum boards where my nick is Dragonking, or via mail: either dragonking_ATTT_o2_D0T_pl or b.waresiak_ATTT_gmail_D0T_com
  • Experience
    • What programs/software have you worked on before?
      • Besides projects for my university (various algorithm-testing training projects), I've been one of Battle for Wesnoth developers since September 2005.
    • Have you developed software in a team environment before? (As opposed to hacking on something on your own)
      • I'm a member of Multiplayer Developers in 'Battle for Wesnoth' project and I have experience in group decision making.
    • Have you participated to the Google Summer of Code before? As a mentor or a student? In what project? Were you successful? If not, why?
      • It is my first time applying to Google Summer of Code.
    • What development model would you use (e.g. keywords: V-model, XP programming, agile programming, iterative; with the help of prototyping, formal specifications, tests, etc.).
      • Iterative development model with Unit/Integration tests.
  • Open Source
    • Are you already involved with any open source development projects? If yes, please describe the project and the scope of your involvement.
      • As a Multiplayer Developer for 'Battle for Wesnoth' project I've been one of people responsible for unit balancing (unit statistics tweaking), multiplayer server moderation and basic administration. This work did not involve any C/C++ coding
  • Gaming experience
    • Are you a gamer?
      • Yes, I like to play various types of games: strategy games - both real time and turn-based, role-playing games and some of the first person shooters. I'm rather patient and calm player and I enjoy difficult games which require some amount of 'hard thinking'.
    • What type of opponents do you prefer?
      • I prefer human opponents much more than AI, but they have to be polite, civil and mature. I really enjoy games against experienced player, though I don't mind also tutoring new ones.
    • Are you more interested in story or gameplay?
      • I value both - IMHO to bring a game to someone's attention, it must have a decent gameplay. If it has a nice storyline as well, then chances that players will keep playing and won't leave increase.
    • Have you played Wesnoth? If so, tell us roughly for how long and whether you lean towards single player or multiplayer.
      • I have been playing Wesnoth since about 0.7 version, mainly multiplayer because I enjoy Wesnoth players community and recognize it as polite and mature one. Also, like I mentioned, multiplayer games against human opponents are for me much more enjoyable than single-player campaigns.
  • Communication skills
    • Though most of our developers are not native English speakers, English is the project's working language. Describe your fluency level in written English.
      • I have no problem with understanding written English, and describing my thoughts to the others in this language.
    • Are you good at interacting with other players? Our developer community is friendly, but the player community can be a bit rough.
      • I think I know Wesnoth developers and players community well, and I've always been trying to always be on good terms with everyone. I know whom to talk to about different issues and who can give me needed advice or support. I also have quite a lot experience with interacting with multiplayer community.
    • Do you give constructive advice?
      • When giving advice, I try to be as detailed as possible, and make sure that people who I direct advice to understand me well. I am aware that during the internet chat you can be misinterpreted and your advice may instead be received as a negative criticism, I'm trying to avoid it by being friendly towards others.
    • Do you receive advice well?
      • I know that I can be wrong and that around me many people are far more experienced than me, I consider advices from others as a good thing which helps me improve and develop my skills.
    • Are you good at sorting useful criticisms from useless ones?
      • I have to admit it is hard to receive bad criticism - if someone is telling you that you are plain wrong, but is not providing any arguments to back up his opinion, then usually this kind of criticism is a useless one. If someone can criticize what I am doing providing examples what is wrong and how it can be improved - it is definitely an example of useful and desired criticism.
  • Project
    • Did you select a project from our list? If that is the case, what project did you select?
      • I chose to develop the Formula AI.
    • Why did you choose this project?
      • AI has always been weak in Wesnoth, challenging only if provided with big amounts of gold and units. Also sometimes you can see AI-controlled units just getting stuck and not moving. I would like to contribute to creating a good and challenging AI for wesnoth, which would fix some problems with the current one.
    • Include an estimated timeline for your work on the project
      • Milestoned proposed by me are presented below. I think I can start working on the formula system rather soon, since I'm already familiar with Wesnoth community, I have a bit of knowledge about existing Formula AI code and I know gameplay side of Wesnoth really well.
    • Include as much technical detail about your implementation as you can
    • What do you expect to gain from this project?
      • Some C++ experience, knowledge about functional programming and AI.
    • What would make you stay in the Wesnoth community after the conclusion of SOC?
      • Since I am one of Wesnoth developers for 2 and half year already, I think that I'll stay with Wesnoth after SoC finishes.
  • Practical considerations
    • Are you familiar with any of the following tools?
      • Subversion
        • Yes, about 2-year experience.
      • C++
        • I have more than 1 year of C/C++ experience.
      • Python
        • No.
    • Which tools do you normally use for development? Why do you use them?
      • I'm working on Linux Gentoo,
    • What programming languages are you fluent in?
      • C/C++ and Java.
    • What spoken languages are you fluent in?
      • Polish - which is my mother tongue, and English.
    • At what hours are you awake (please specify in UTC)
      • Usually I'm awake between 8 and 23 UTC, and available on IRC betweeen 17 and 23 UTC.
    • Would you mind talking with your mentor on telephone / internet phone?
      • I wouldn't mind.

Idea Description

Required knowledge and talent

  • A minimal knowledge of C++ is required, a good knowledge of C++ is desired: I believe I have quite good knowledge of the C++, during the last few weeks when I dug into Formula AI code I managed to understand most of the code and find few bugs by code inspection (see what I commited).
  • Good social interaction with a large player community: As a Multiplayer Developer I have a lot gaming experience, knowledge about units statistics, usage, strong and weak sides. I know many tactics and strategies, both general and faction-specific. Proof of that can be fact that I was the winner of the first Wesnoth Tournament of Champions.

Detailed project description

As I see it, Formula AI project consists of 3 parts, which would be done step by step and rather concurrently. Each of these parts is important. some things can't be done before earlier completion of other goals.

C++ part

In my opinion C++ part of the project would be:

  • expanding capabilities of functional language of the Formula AI - adding needed operators, functions, implementing lazy lists etc.
  • expanding capabilities of Formula AI by adding more commands
  • writing external tools for work with Formula system:
    • Unit/Integration tests which would check if formulas return expected results and ensure that system works correctly;
    • command line so simple formulas could be evaluated without need of running them within Wesnoth
  • debugging and optimizing current and future Formula code

Formula part

Formula part would consist of 2 things:

  • pluggable Base Formula AI itself, which should be a challenging AI opponent able to fight on any kind of map
  • set of external rules/formulas - either from our 'formulas database' or user-created, which could make AI behave in a specific, preffered way

Maybe I'll start with the latter:

Plugability

First of all Formula System should be fairly easily extendable by people with no knowledge about programming. To achieve this good documentation and base with some 'official' formulas shipped with wesnoth are needed. This would allow scenario creators to do things like:

  • Improve general AI efficiency on any map, by giving advices like what to recruit/what to not recruit, how to make good opening moves, which part of map should AI focus on more etc. One of possible examples could be to make AI move leader to keep which is closer to the battlefield, so needed reinforcements could reach enemy sooner.
  • Set how aggressive/defensive the AI should be.
  • Make AI focus on a given task like protect some unit, protect some place (bridge, mountain, ...), attack some specific unit or types of units, etc. Important is to make sure that specific task could be given to one, or any number of units, or even AI as a whole.
    • EDIT: After I commited Unit Formulas it is now possible to define formula for a single unit which completely determines what this unit is supposed to do.
  • and many many more

Note that keeping in touch with scenario developers and our WML experts is important - since this system should be useful for them, they should decide about many aspects and possibilities of the Formula system, and their feedback would be more than appreciated. Also starting a thread on the forum boards with questions what other Campaign Developers would expect from the new Formula System seems to be a good idea.

Base Formula AI

As for the base Formula AI, I would divide its development into 3 stages. Each stage would be an independent AI derived from the previous one, so that scenario designers could choose whether to use a Simple, Average or Advanced Formula AI and eventually tweak it. I would start with basic implementation of below proposals, tweaking, improving and expanding them over a time.

Please not that the list below is a draft of this idea and a work in progress - some things may change/move between the types of AI and new proposals may appear any time.

  • Simple Formula AI
    • recruitment patterns - which unit is generally good against opponents units/faction on a certain map. It is important to beside opponents units consider on what kind of terrain AI is supposed to fight on, and what kind of units AI already posses - if it has 3 mages only getting another one against skeletons doesn't seem to be a good idea...
    • terrain advantages and importance of villages - make it stick to good defence terrain, and protect its villages with best units - it is important to note that strong resilient unit is better guardian than fast intelligent one of the same type.
    • importance of experience:
      • make AI kill opponents experienced units
      • make AI accumulate xp and try to deal killing blows with already experienced units
    • importance of healing and ability to retreat - if AI is in bad health shape, and opponent is in good, it is better to give up and move back
    • importance of the leader - protect it at all cost and don't put him into risk
    • awareness of the objective - kill enemy leader
    • ability to attack in way which maximize opponent's damage and minimalize damage taken - so it won't attack a mage with an archer.
    • ability to divide forces between parts of the map according to enemy positions
  • Average Formula AI:
    • know how to use of heal, cure, poison, magic, berserk abilities/weapon specials
    • knowledge about offence and defence part of the game and improving unit recruitment and positioning:
      • The basic thing that AI should know was described above - make sure that it will inflict as much damage as possible and take only a little if any. Next thing is to learn with which unit AI should defend - you put melee units against possible melee attackers, and ranged units against possible ranged attackers. AI has to decide if it is attacking or defending on certain part of a map during certain turn.
      • Somehow connected to this is recruiting. So there will be need to improve recruiting - if AI has advantage it may get mage to support attack, if it is under pressure, getting fighter could probably be the better idea ( there are dozens of examples, important is to make AI aware in what kind of situation it is and how it should react).
    • importance of experience:
      • If unit lack only few xp points it may be better to advance it by not killing enemy but by simple fighting
    • know to not "waste" any move if possible, if after whole turn some units are unmoved, calculate if there is possibility to do something with them (move to village, heal, attack to gain even 1 point of experience etc. )
  • Advanced:
    • be able to use any unit with any kind of special ability
    • be aware of fog of war/shroud
    • have option to try and "push luck" - for example at the very beginning of the MP game when initial luck can result in huge advantage

Documentation part

There isn't much to write about this part: each new Formula System functionality should be documented in the wiki, preferably with an example of usage. If new functionality implements some changes outside Formula System - for example in WML - it also should be documented. Again in this matter, close cooperation with Campaign Developers is desired.

Milestones

In my opinion, there should be plenty of milestones so it is easier to see actual progress of the work. Also smart planning and sheduling increase possibility of success. Finishing some things will take more time than the others, and some may be finished only with cooperation with other people (Multiplayer Developers, Campaign Developers,...)

  • Geting fammiliar with Formula AI code: First thing would be to get fammiliar with the current Formula AI code, and prove some knowledge about it by expanding its functionality.
  • Finish creation of Simple AI's Recruitment pattern: this step would prove understanding the Formula AI language, and would be basis for future work. The AI would use Frmula System for recruitment and DefaultAI for rest of actions. Up to this point, general idea how Formula AI and its Plugins System will look like should be ready. Note that cooperation with Multiplayer Community is needed for successful comletion of this milestone.
  • Expand Simple AI - make Simple AI move and attack on its own, be aware of the enemy and being able to make decisions in relativly short time. At this point basic customization (i.e. how agressive AI is) should be possible. This milestone is one of the most difficult ones and will most likely take a lot of time (probably good as mid-term goal).
  • Implementation of the Average AI formulas, and expanding set of possible tweaks to the AI. At this point it is far more important to be able to tweak AI as needed, than having Formula AI win agaisnt Default one. Need to remember to keep documentation up to date.
  • Finishing all formulas for the Average AI, and making it fight (in the worst possible scenario) at the equal terms with current default AI.

Later comes tweaking the existing formulas, improving documentation, writing more complex formulas...

My commits

My commits to Formula System ordered by date:

Besides above, I have been working on improving the FormulaAI documentation.