You are thinking too procedurally.
You shouldn't be using lists, or collections within the rules, instead 
generally the thing within the list should be inserted into the working memory.
Rather than having the function you can then right something like the following:
//person has earned the badge
p : Person()
badge : EarnedBadge(owner == p, name == "Foo")

or
//person has not earned the badge
p : Person()
not EarnedBadge(owner == p, name == "Foo")

For getting their progress you'd probably keep a list of BadgeTasks that a 
person has completed,
You'd then use count/accumulate to add up the progress and update the 
EarnedBadge.

Thomas

> -----Original Message-----
> From: rules-users-boun...@lists.jboss.org [mailto:rules-users-
> boun...@lists.jboss.org] On Behalf Of Warner Onstine
> Sent: 11 August 2011 05:59
> To: rules-users@lists.jboss.org
> Subject: [rules-users] best way to write this rule?
>
> I am new to Drools and I've been trying to figure this out through the user
> guide and examples I've been finding, but I'm not sure what the best way is
> to write this rule (or set of rules).
>
> What I'm trying to write is a set of rules for determining when someone has
> earned (or is starting to earn) a badge. I want to be able to show their
> progress on badge completion as well as when they finally complete said
> badge.
>
> I'm passing in the following to the rule:
> - Player
> - Earned Badges (list)
> - All possible badges
>
> The first rule only deals with one specific badge. So I have something like 
> this
> in my when:
> $badge : Badge(name == "Something") //my assumption is that Badge comes
> from the list of all possible badges I've just passed in
>
> Then, I decided to split the rule into two. One rule for when they had not
> earned it yet:
> and I call a function
> function earnedBadge(List<EarnedBadge> badges, String name) {
>     boolean found = false;
>     for(EarnedBadge badge : badges) {
>         if(badge.getBadge().getName().equals(name)) {
>             found = true;
>         }
>     }
>     return found;
> }
>
> when:
> earnedBadge(badges, $badge (name))
>
> Then I got stuck. If they have completed one or more tasks I would like to
> create (or use the badge they've started to earn) to track their progress. So,
> If I have 5 possible things they need to do and they've done three of those
> I'd like to create a new EarnedBadge for the one they are earning and give it
> a percentage of 60%. What would be the best way to do something like this?
>
> Thanks for helping out the newbie, it's greatly appreciated :).
>
> -warner
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


**************************************************************************************
This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
postmas...@nds.com and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes. To protect the environment please do not 
print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, 
United Kingdom. A company registered in England and Wales. Registered no. 
3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to