Complete.Org: Mailing Lists: Archives: freeciv-ai: June 2003:
[freeciv-ai] Re: Hi, I'm back. aiclient

[freeciv-ai] Re: Hi, I'm back. aiclient

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Raimar Falke <i-freeciv-lists@xxxxxxxxxxxxx>
Cc: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: Hi, I'm back. aiclient
From: Manuel Gutierrez Algaba <stemanolo@xxxxxxxx>
Date: Mon, 30 Jun 2003 11:37:31 +0200

El Lun 30 Jun 2003 10:31, escribió:

> int base_get_attack_power(Unit_Type_id type, bool veteran, int moves_left)
> {
>   int power;
>   power = get_unit_type(type)->attack_strength * POWER_FACTOR;
>   if (veteran) {
>     /* Veterans get +50% bonus. */
>     power = (power * 3) / 2;
>   }
>   if (!unit_type_flag(type, F_IGTIRED) && moves_left < SINGLE_MOVE) { ; I 
don't understand this rule very much, I'd have to read more about 
>     power = (power * moves_left) / SINGLE_MOVE;
>   }
>   return power;
> }
Well, If I remember correctly Clips, would be:

Using Clips, an expert system language:

(defrule static-attack-power 
" This rule will trigger whenever a unit is created or its veteran-factor 
   ?w<- (unit (type ?x) (veteran-factor ?v)) ;?v value will set somewhere else
   (typeunit (type ?x) (strength ?s))
   (modify (?w (staticattack-power (* ?v ?s))

(defrule dinamic-attack-power
  (unit (tired 0))
  (constsinglemove ?v)
 ?w <- (unit (type ?x) (movesleft ?m:(< ?m  ?v) )
 (?w <-(unit ) ...)

(defrule base-get-attack-power
        ( attacking-unit (unit-id ?u) (type ?x))
        ?w <- ( unit (staticattack-power ?p) (dynamicattack-power ?d)))         
       (assert (attack-power (unit-id ?u) (power....  )))

Perhaps the code would not be thus, since I'm not totally fresh on Clips, may 
be (unit (ljlkj) ) things would be reworked in mulitple facts so the rules 
don't retrigger themselves. But the idea can be that. Or perhaps it can be 
switchd the view and have:
(veteran-factor (unit-id ?u ) (value ?v)) , and that sort of things.

Apparently is even more complex. But let's see it integrated in the "whole": 

- When you call the C function you have to store the "power" value and take a 
decision *promptly" somewhere. Somehow it provokes that the decission must be 
taken soon, and in an "if" branch up in the stack of calls.
- C is a model that has only the info to be used at the moment, and to use 
some info (attack power) you have to request for it. 

Now Clips mode:
- Whenever anything changes in the game (a unit becomes veteran) , all the 
related facts about it , such  base-get-attack-power, defense... become 
updated at the moment. That provides a pool of asserted facts ready to be 
included in some rules of high order. Like the fact  defense-power-of-city,
attack-power-of-fleet...  I mean that in Clips model , you have all the info 
concurrently ready to be used, you don't have to call any function to work 
out values and then produce a single "isolated" value, that most likely will 
be consumed within a "chain" of decision. 
In Clips you'd have "tree" of decisions and "trees" of reactions. A single 
change will recreate a tree of facts.

Needless to say, this model is richer and thought-provoking. The logic may 
seem the same , the difference is in the data: more and more interrelated and 
The difference (C-Clips) doesn't come in isolated rules, but in the behaviour 
of sets of rules. In C they're line-chained, call-by-call, in Clips are 
"explosion"-like , a single change trigger changes in many variables 
(decissions to be taken). In C you focus on the "function" the call, in Clips 
you focus on the state, the fact. C is imperative, Clips "logic" or better 
"stative". With the same effort, because the logic for producing a value/fact 
is the same in C or Clips (you somehow must generate the value with if's or 
defrules), in Clips you keep a "trace" of facts and a set of facts, that in C 
would had remained as local variables or returned values, hard to relate, 
once the "initial call" has ended. 

Prolog would be pretty much the same, and better, since Prolog can "fill" the 
gaps and "search for" a solution, not simply fact-making.


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