What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal
RebornBuddy Forums

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

RulesEngine: Description

Coolmaster

Member
Joined
Aug 16, 2013
Messages
709
Under test

What is a Rule?
The Rules is a simple mechanism for interacting with the bot through which you can easily change the bot's behavior and play by own rules.

Should not simultaneously create a lot of rules - you can get unexpected results from the combination of the rules and you will be hard to find the cause of strange behavior.
Rules should be created step by step. Sometimes it is enough to create only a few rules that would radically change the style of playing. AI will do all the work, you should just slightly specify the correct direction.

One Rule is a single line consisting of several parameters (conditions) and a bonus.
  • If all conditions are TRUE then a Playfield gets this bonus.
  • If at least one condition is broken, the Playfield gets nothing (or gets penality only).
- The bonus must be written at the end of the rule and is separated from the main rule by a comma.
- The bonus can be positive and negative.
- The more positive bonus, the higher chance that this option will be played.
- The less negative bonus, the less chance that this scenario will be chosen (remember that -100 is less than -10).

The rule looks like:
condition,bonus=X
(where X is any number)

Conditions can be connected to each other within one rule:
&
- And (condition1&condition2,bonus=X - playfield gets this bonus if only the condition 1 AND condition 2 are true);
|| - Or (condition1||condition2,bonus=X - playfield gets this bonus if the condition 1 is true OR condition 2 is true);
You can connect as many conditions as you wish (no spaces or any extra characters between conditions).
Example: cond_1&cond_2||cond_3||cond_4&cond_5,bonus=10 - true(gets bonus) if condition_1 = true And (condition 2 or 3 or 4) = true And condition_5 = true;


There are 3 types of rules:
1. Board state rule (including cards in your hand and minions on board)
2. Play card rule.
3. Attack rule.
You can mix these rules.

There are 3 types of comparison within one condition:
1. Comparison with a number.
[hide]
Comparison operators (=, !=, >, <) !ONLY NUMERIC VALUE!
(= - equal, != - not equal, > - greater than, < - less than)

tm - turn mana (default mana at this turn);
am - available mana (at this turn);
t - turn;
overload - overload, which can cause a card in the current round;
ohhp - own hero health points;
ehhp - enemy hero health points;
owa - own weapon attack;
ewa - enemy weapon attack;
owd - own weapon durability;
ewd - enemy weapon durability;
occ - own cards count (the number of cards in own hand);
ecc - enemy cards count (the number of cards in enemy's hand);
omc - own minions count (the number of own minions on the board);
emc - enemy minions count (the number of enemy minions on the board);
For "omc" and "emc" you can use these extensions:
:Murlocs (the number own/enemy Murlocs on the board)
:Demons (the number own/enemy Demons on the board)
:Mechs (the number own/enemy Mechs on the board)
:Beasts (the number own/enemy Beasts on the board)
:Totems (the number own/enemy Totems on the board)
:Pirates (the number own/enemy Pirates on the board)
:Dragons (the number own/enemy Dragons on the board)
:SHR (the number own/enemy Silver Hand Recruits on the board)
:undamaged (the number undamaged own/enemy minions on the board)
:damaged (the number damaged own/enemy minions on the board)
:shields (the number own/enemy shields on the board)
:taunts (the number own/enemy taunts on the board)
Also you can compare "omc" and "emc"
Example:
omc>3 - means that you must have more than 3 minions on the board
omc:Murlocs>3 - means that you must have more than 3 murlocs on the board
omc>emc - means that you must have more minions than your opponent

[/hide]
2. Logical comparison.[hide]
Boolean operators (=, !=)
(= - equal/contain; != - not equal/does't contain)

ob - own board (own board must/must not contain this minion (CardID));
eb - enemy board (enemy board must/must not contain this minion (CardID));
oh - own hand (own hand must/must not contain this card (CardID));
ow - own weapon (CardID);
ew - enemy weapon (CardID);
ohero - own hero class (ALL, DRUID, HUNTER, MAGE, PALADIN, PRIEST, ROGUE, SHAMAN, WARLOCK, WARRIOR);
ehero - enemy hero class;
[/hide]
3. Unique.
[hide]
Unique:
coin - must be a coin in hand at turn start;
!coin - must not be a coin in hand at turn start;
noduplicates - if your deck contain no duplicates
p= - play - card in hand that must be played (CardID);
p2= - play 2 identical cards - 2 identical card in hand that must be played (CardID);
a= - attacker - minion on board (CardID);
[/hide]

Examples:
* Don't allow the enemy to have more than 2 Murloc on the board (if the enemy has more than 2 Murlocs on the board, give a small negative bonus):
emc:Murlocs>2,bonus=-5

* If we have own minion with Divine Shield on the board and Flametongue Totem (EX1_565) in hand, give a small positive bonus (for example if there a choice between 2 minions to play, the priority will have a minion with Divine Shield)
omc:shields>0&oh=EX1_565,bonus=2

* If we want to play Doomhammer (EX1_567) on turn 4 (with coin) we must be not overloaded in turn 3.
The rule read as: if at the end of the turn 3 we have overload (we played a card with overload) and (we play coin or we have coin in own hand) and we have Doomhammer in own hand, then completely forbids this action (big negative bonus)):
t=3&overload>0&p=coin||oh=coin&oh=EX1_567,bonus=-600

With conditions "play a card" (p=) or "attack" (a=) you can use additional rules and additional penalties if these conditions were broken.
[hide]
For "p=" and "p2=" and "a=" you can use these extensions:
:pen= (after CardID) - penalty for playing/attacking this card outside of this rule;
:tgt= - target - target for spell or for minion/weapon (CardID/hero/!hero);
If a minion/hero/spell has a target, you can use comparison operators ( =, !=, >, < !ONLY NUMERIC VALUE!) for these parameters:
:aAt - attacker's attack (mob/hero)
:aHp - attacker's health points
:tAt - target's attack
:tHp - target's health points
[/hide]
* If own Grommash Hellscream (EX1_414) have attack=4 and attacks enemy minion (target not hero) and target's hp<5 then give a small positive bonus (if attack condition is broken, give a small penality).
a=EX1_414:aAt=4:tgt=!hero:tHp<5:pen=2,bonus=3

Consider a combination of rules.
Board:
OwnHero HP = 25, No cards, Own Minion: 1)HP=5, Attack=4, Windfury (Windfury Harpy, EX1_033)
EnemyHero HP = 18, No cards, EnemyMinions: 1)Attack=3, HP=2 2)Attack=2, HP=3
Rules: (_rules.txt)
//negative bonus if Windfury Harpy attacks minions with low HP
a=EX1_033:tgt!=hero:tHp<3:pen=13,bonus=-7
//positive bonus if we have at least one minion on the board
omc>0,bonus=5
Possible actions and their bonuses:

1) 1x attack enemy hero: -13(the rule isn't broken, but additional condition tgt!=hero is broken, pen=13) + 5(omc>0 bonus) = -8
2) Attack 2/3: -13(tHp<3 broken pen=13) + 5(omc>0 bonus) = -8
3) Attack 3/2: -7(bonus) + 5(omc>0 bonus) = -2
4) 2x attack enemy hero: -13(tgt!=hero broken pen=13) + -13(tgt!=hero broken pen=13) + 5(omc>0 bonus) = -21
5) Attack enemy hero + attack 2/3: -13(tgt!=hero broken pen=13) + -13(tHp<3 broken pen=13) + 5(omc>0 bonus) = -21
6) Attack enemy hero + attack 3/2: -13(tgt!=hero broken pen=13) + -7(bonus) + 5(omc>0 bonus) = -15
7) attack 2/3 + attack 3/2: -13(tHp<3 broken pen=13) + -7(bonus) = -20
Point 3 has the highest bonus in this situation.

How to start to use the rules?
1. Create a text file _rules.txt and place it in the behavior folder (for example \Routines\DefaultRoutine\Silverfish\behavior\Control).
2. Open this file in any text editor and create a new rule.
a)Comments begin with //
b)Should not be any extra characters at the end of the rules
c)The new rule must start on a new line
3. Save the file and run the bot. Your rules will be used automatically.

If you want to debug your rules you can add this lile in the _settings.txt:
printRules = 1; //0 - off, 1 - on
The rules that were used will be displayed in files Log/UILogg and in the main window of the bot.

Currently bot includes a RulesEngine, but it's not available for users.
If you want to use your rules right now, you need to download this file.
With the next release all users will be able to use rules.



If you wish to have the new conditions - describe it in the post.
If you are faced with a situation that the rule is not used or is used incorrectly - describe it in the post and attach Log/UILogg/_rules.txt files
 
Last edited:
Cool, I couldnt give bonus to pick 3 card draw from Nourish and rules engine was my very first thought to fix it.
Also I might miss some old documents of SF, but I think there is no way to simulate board from log after adjusting _rules ... if i'm right it alone makes _rules useless as noone can test results?..
 
Iso, thanks. Check your pm and your thread

I have added to rule new parameter "owncarddraw" (extra carddraw on your turn).
You can use any comparison operators (=, !=, >, <)
You can use it separately or together with other parameters.

Examples:
1)Give a small bonus if your carddraw this turn more than 2:
owncarddraw>2,bonus=10
2)Give a small bonus if your carddraw this turn more than 2 and you have played Nourish:
p=EX1_164&owncarddraw>2,bonus=12
3)Give a negative bonus if your carddraw this turn less than 3 and you have played Nourish and you have less 4 cards in your hand: (don't forget that the rules work at the end of the turn, after all actions)
p=EX1_164&owncarddraw<3&ohc<4,bonus=-20

If you use rules, the bot logs every application of a rule (you can see it in the bot window or in the log file if printRules = 1 in your _settings.txt).
You can simulate board from your log (it uses _rules.txt)
Anyone can simulate board from your log if you add log + _rules.txt
 
Last edited:
Ahaha, one problem fixed, but I also have problem with Jade Idol - need to give bonus to Summon Jade Golem.

Temporary solution
Code:
//Jade Idol - Forbid shuffle.
p=CFM_602&omc<7&ob=CFM_712_t01,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t02,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t03,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t04,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t05,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t06,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t07,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t08,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t09,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t10,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t11,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t12,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t13,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t14,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t15,bonus=5
p=CFM_602&omc<7&ob=CFM_712_t16,bonus=5

You can simulate board from your log (it uses _rules.txt)
Anyone can simulate board from your log if you add log + _rules.txt

But how? oO
 
Last edited:
It depends on your goals and what you want to get in the end.
Describe it.

I have log with missplay that is not general one just deck specific. I have board state from log. I do changes in either _settings, _combos or _rules to fix it for my deck and I need to force bot to calculate this board state with new files and check the results.
 
hello, Coolmasker
do you know how to write a rule to make hearthbuddy to use '' marks of lotus'' to buff minions .
i try to write one like this.
// if we have more than 2 minions, play mark of the lotus.
omc>=2&p=CFM_614,bonus=10
but it does't works. can you help me ?
 
Last edited:
i try to just test your code . it also read error
006tKfTcly1ffj3ggyp4fj30w30mujs4.jpg


whats wrong with this? can you help me ?
 
1)
// if we have more than 2 minions, play mark of the lotus.
omc>=2&p=CFM_614,bonus=10
but it does't works. can you help me ?
Comparison operators (=, !=, >, <)
Wrong: emc>=2&p=CFM_614,bonus=10
Right: omc>2&p=CFM_614,bonus=10

2)Right: emc:Murlocs>2,bonus=-5
Read error means that something has blocked access to the file (maybe your text editor/antivirus/something else).

If you see strange behavior then create a post under the Support section.
In this case it was a bug that I have fixed. Check your PM.
 
2)Give a small bonus if your carddraw this turn more than 2 and you have played Nourish:
p=EX1_164&owncarddraw>2,bonus=12

Hey, Cool I took this solution of yours, bonus=20 resolved all logs I had, but I noticed we also need to neutralize this rule in case Nourish is not a best play here by
p=EX1_164&owncarddraw>2,bonus=20
p=EX1_164,bonus=-20


Resolving this I also find out that cardvalue in _combo.txt is not working anymore.
 
1)

Wrong: emc>=2&p=CFM_614,bonus=10
Right: omc>2&p=CFM_614,bonus=10

2)Right: emc:Murlocs>2,bonus=-5
Read error means that something has blocked access to the file (maybe your text editor/antivirus/something else).

If you see strange behavior then create a post under the Support section.
In this case it was a bug that I have fixed. Check your PM.
hello coolmaster,
thank you . it works.
 
hello coolmaster,
thank you . it works.
Hmm for some reason this didn't work for me.
Had board full, and 1 free mana, with CFM_614 in hand. Debug rule only mentioned the default rule since i had innervate 'rule: 0 broken rule:eek:hero=DRUID&t=1&p=EX1_169&am>0,bonus=-6'
I'm using exactly
omc>2&p=CFM_614,bonus=10

Not sure if it has something to do with the fact that the board was made up of living mana treants, maybe those don't count?

Edit: nvm the bonus wasn't large enough.
 
Last edited:
Back
Top