pappde / bmai

AI to play Button Men, originally developed to interface with the (now deprecated) unofficial online Button Men website.
MIT License
2 stars 1 forks source link

Skill Attacks - BMC_DieIndexStack Cycling should skip states with just one die #57

Open pappde opened 1 month ago

pappde commented 1 month ago

OBSERVED In GenerateValidAttacks() for skill (BME_ATTACK_TYPE_N_1), it uses a BMC_DieIndexStack to cycle through all combinations. However, it includes testing states with just one die.

IMPACT This is wasteful, since a lot of logic runs for each combination:

PROPOSAL

REQUIREMENTS NOTE:

danlangford commented 4 weeks ago

it is valid to make a single die skill attack FWIW

Skill Attack: Use one or more of your dice to capture one of your opponent’s dice. In this case, the values showing on your dice must add up exactly to the value showing on the die you capture. Remove the captured die from play, and re-roll all the capturing dice.

In a Skill attack, you use any number of your dice to capture a single die of mine. The numbers showing on your dice must add up to exactly the number showing on mine. Yes, you can make a skill attack with a single die showing the same number as one of my dice. You could also make a power attack. Most of the time, it doesn't matter, and you won't have to specify which type of attack you made.

and then the inference in Konstant rules

… Konstant dice can not Power Attack, and cannot perform a Skill Attack by themselves

this can be useful in a few situations. the Doppleganger skill triggers on a power attack. The Fire dice cannot perform power attacks.


https://buttonmen.fandom.com/wiki/Button_Men_Rules#The_Basics https://www.buttonweavers.com/ui/how_to_play.html https://www.buttonweavers.com/ui/skills.html#Konstant

pappde commented 4 weeks ago

The original proposal here is actually still valid - we just need some intelligence for how to set minimum_dice. For example,

   minimum_dice = attacker->SupportSingleDieSkillAttack() ? 1 : 2;

This function would return true translates to if the attacker has any Fire dice (or other dice that cannot make power attacks, for example). It's still a good optimization, since this exception is going to be uncommon.

Also, I noticed the current code already indicates an intentional awareness of the validity of single-die skill attacks. In ValidAttack() for SKILL:

            // must be using more than one
            // TODO: should allow this (important for FIRE)
            if (dice<2)
                return false;

So this check is intentional to cut out redundant branches in the search space. This check could be removed if we have the above optimization, otherwise it would have to be updated to support FIRE dice and similar (as noted in the TODO).

E.g.

  // Optimization: ignore single-die skill attacks which are redundant with power attacks, but allow if the die cannot do a power attack (e.g. Fire)
  if (dice<1 || (dice==1 && !att_die->CanDoAttack(POWER))
     return;

However, better to remove if we do end up with the optimization earlier.

danlangford commented 4 weeks ago

I see thanks for clarifying

On Thu, Oct 10, 2024 at 10:02 AM Denis Papp @.***> wrote:

The original proposal here is actually still valid - we just need some intelligence for how to set minimum_dice. For example,

minimum_dice = attacker->SupportSingleDieSkillAttack() ? 1 : 2;

This function would return true translates to if the attacker has any Fire dice (or other dice that cannot make power attacks, for example). It's still a good optimization, since this exception is going to be uncommon.

Also, I noticed the current code already indicates an intentional awareness of the validity of single-die skill attacks. In ValidAttack() for SKILL:

      // must be using more than one
      // TODO: should allow this (important for FIRE)
      if (dice<2)
          return false;

So this check is intentional to cut out redundant branches in the search space. This check could be removed if we have the above optimization, otherwise it would have to be updated to support FIRE dice and similar (as noted in the TODO).

E.g.

// Optimization: ignore single-die skill attacks which are redundant with power attacks, but allow if the die cannot do a power attack (e.g. Fire) if (dice<1 || (dice==1 && !att_die->CanDoAttack(POWER)) return;

However, better to remove if we do end up with the optimization earlier.

— Reply to this email directly, view it on GitHub https://github.com/pappde/bmai/issues/57#issuecomment-2405510540, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFQDVE6UMCPHJ5MCFNGZNLZ22QIVAVCNFSM6AAAAABPI7FBWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBVGUYTANJUGA . You are receiving this because you commented.Message ID: @.***>