On Thu, Aug 11, 2011 at 3:11 AM, Swindells, Thomas <TSwindells(a)nds.com> wrote:
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.
I've been playing around with this further but I'm still running into
issues. I guess here's the crux of the matter:
As a player I have:
- a list of badges I am in progress of completing
- something I've just done that could go towards one or more of these badges
Within the game there are:
- a list of potential badges that a player could earn
- with a set of things to do to earn each badge (what I'm considering the rules)
In short I don't want to have to go through each thing each player has
done and try and determine which rule to run, I just want to pass in:
- their set of badges (with steps they've completed so far)
- what badges are available to earn (to match against)
- what they just did
Maybe I'm thinking about this the wrong way and there's an easier way
to do this. Still trying to figure the best implementation of the rule
and rule set. My goal is to load all the rules at load time (and
reload when I add a new badge) so that I have a full knowledgebase and
can just run it whenever someone does something in the game.
Thank you for any help, it is much appreciated.
-warner (Drools/Rules newbie)
Thomas
> -----Original Message-----
> From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-
> bounces(a)lists.jboss.org] On Behalf Of Warner Onstine
> Sent: 11 August 2011 05:59
> To: rules-users(a)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(a)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 postmaster(a)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(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users