It is currently 19 Apr 2024, 04:54
   
Text Size

Combat Refactoring

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Combat Refactoring

Postby elcnesh » 18 Oct 2014, 09:01

As I mentioned, I've been working on constructing an algorithm to determine a legal set of attackers, taking into account all restrictions and requirements (including those of cards we currently don't have implemented, like Viashino Bey). After messing around with code for weeks, I decided it'd be better to just put the entire algorithm in words first, discuss it until we get something that works, and implement that. So, I've put together a Google Docs document detailing the algorithm I've come up with so far: https://docs.google.com/document/d/1XPZdVWQptA-vTnsFQU-IohfvAOT4z3g1RPc3sk4xgBE/edit?usp=sharing

Not everything works completely, as annotated in red, but I think the general structure should be able to cover that as well. The restrictions and requirements mentioned cover all cards ever printed as far as I know. I do want it to work with all the cards, because otherwise we might have to go back and restructure it again later. For the obvious cases I've also put some O-notation running times next to them.

Please feel free to comment, either here or directly in the document (it should be open for comments), about what you think about the structure, specific cases, things that might not work in certain corner cases, missing cards, etc. Please keep in mind that this hasn't been implemented, let alone tested.

Reference

Master Attack List | Open
Attack requirements:
Attacks this/each combat if able: appears on Hellraiser Goblin, Illusionist's Gambit, Marauding Maulhorn and Zurgo Helmsmasher. Creates one general requirement for the creature to attack.
Attacks this/each turn if able: common effect (eg. Juggernaut). Creates one general requirement for the creature to attack unless the creature was already declared as an attacker earlier this turn.
Attacks <defender> this/each combat if able: appears on Ruhan of the Fomori and scheme cards Rotted Ones, Lay Siege and The Dead Shall Serve. Creates a requirement for the creature to attack a specific defender.
Attacks <defender> this/each turn if able: appears on Alluring Siren, Gideon Jura and Taunt (I presume) and scheme card My Crushing Masterstroke. Creates a requirement for the creature to attack a specific defender unless it already attacked that defender earlier this turn.
Attacks or blocks this combat if able: appears on Boros Battleshaper. Creates a general requirement for the creature to attack. In case the creature attacks and then is stolen by the defender, it would no longer be required to block as the requirement was already fulfilled, but for purpose of attacking, it behaves exactly like "Attacks each/this combat if able."
Cogwork Tracker: Creates a requirement for the creature to attack any player from a defined set of players, if that set is non-empty.
Ekundu Cyclops: Creates a requirement on itself that is satisfied if either Ekundu Cyclops attacks or if NO creatures attack. It's not satisfied if there's a non-empty set of attackers that doesn't include Ekundu Cyclops. If Ekundu Cyclops is generally incapable of attacking, the requirement should not be created (otherwise strange situations might result).
Magnetic Web: Creates a requirement on each creature with at least one magnet counter that is satisfied if either that creature attacks or if NO creatures with at least one magnet counter attack. If some creatures with magnet counters attack and some don't, the requirements for those not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
Viashino Bey: Creates a requirement on each creature that is satisfied if either that creature attacks or if Viashino Bey does NOT attack. If Viashino Bey attacks, the requirements for creatures that are not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
War's Toll: Creates a requirement on each creature controlled by the active opponent(s) that is satisfied if either that creature attacks or if NO creatures controlled by that opponent attack. If some opponent's creatures attack and some don't, the requirements for those not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.

Individual attack restrictions:
Can't attack: common effect. Creature can't be declared as attacker at all. Creatures with defender belong here unless they are able to ignore defender (from Animate Wall, Rolling Stones, Wakestone Gargoyle, Warmonger's Chariot or from innate abilities of Colossus of Akros, Dark Maze, Mirror Wall, Mobile Fort, Nivix Cyclops, Ogre Jailbreaker, Pillar of War, Prison Barricade, Returned Phalanx, Slithering Shade, Spire Serpent, Vodalian War Machine, Walking Wall or Wall of Wonder). Detained creatures belong here. Creatures with summoning sickness belong here unless they have haste or are capable of attacking as though they had haste (Chaos Lord/Instill Energy). Conditional effects like Blind-Spot Giant belong here if the condition is not dependent on other declarations OR on the defender (they are simply checked once and then it's decided whether they apply or not).
Can't attack <defender>: appears on Arboria, Blazing Archon, Chronomantic Escape, Elephant Grass, Form of the Dragon, Illusionist's Gambit, Island Sanctuary, Mystic Barrier, Reverence, Teferi's Moat, Vow of Duty, Vow of Flight, Vow of Lightning, Vow of Malice, Vow of Wildness, Web of Inertia and plane card Agyrem. Removes specific defender(s) from the set of defenders a creature can attack. Creatures with defender-dependent attack condition like Armored Galleon belong here; if the condition is not satisfied for a particular player, the creature can't attack that player or any of his planeswalkers. In case of 2HG (not implemented yet), a team can be attacked if any player on the team satisfies a "can't attack unless" condition, but not if any player satisfies a "can't attack if" condition; I presume that an individual player must still satisfy the condition if a planeswalker is attacked.
"Can't attack unless" defender-dependent conditions: Armored Galleon, Bog Serpent, Chained Throatseeker, Dandan, Deep-Sea Serpent, Dreamwinder, Ethereal Whiskergill, Floodchaser, Giant Shark, Goblin Goon, Goblin Rock Sled, Godhunter Octopus, Gorilla Pack, Hammerhead Shark, Island Fish Jasconius, Kukemssa Serpent, Manta Ray, Marjhan, Merchant Ship, Mogg Toady, Monstrous Hound, Pirate Ship, Red Cliffs Armada, Ronom Serpent, Sea Monster, Sea Serpent, Sealock Monster, Serpent of the Endless Sea, Slipstream Eel, Slipstream Serpent, Steam Frigate, Veiled Serpent, Vodalian Knights, Vodalian Serpent, Whimwader, Wu Warship, Zhou Yu, Chief Commander
"Can't attack if" defender-dependent conditions: Branded Brawlers, Goblin Mutant, Mogg Jailer, Orgg, Veteran Brawlers

Predicate restrictions:
"Can't attack alone": appears on Ember Beast, Jackal Familiar, Loyal Pegasus, Mogg Flunkies and Sightless Brawler. Attack sets which contain only this creature are impossible. If combined with "Can only attack alone", the creature can't attack at all.
"Can only attack alone": appears on Errantry and Master of Cruelties. Attack sets which contain this creature and any other creature are impossible. If combined with "Can't attack alone" or with Okk, Orcish Conscripts or Scarred Puma, the creature can't attack at all.
Okk: Attack sets where Okk is the creature with the highest power or one of the creatures with the highest power are impossible. If combined with "Can only attack alone", Okk can't attack at all.
Orcish Conscripts: Attack sets which contain only Orcish Conscripts or Orcish Conscripts and exactly one other creature are impossible. If combined with "Can only attack alone", Orcish Conscripts can't attack at all.
Scarred Puma: Attack sets that include Scarred Puma, but no other creature of specified color(s) (which can be modified through sleight effects or Swirl the Mists) are impossible. Gatherer rulings indicate that Scarred Puma can never satisfy its own condition even if it has the required color(s). If combined with "Can only attack alone", Scarred Puma can't attack at all.

Global attack limiters:
Astral Arena - lowers global maximum of attackers to 1 if higher.
Caverns of Despair - lowers global maximum of attackers to 2 if higher.
Crawlspace - lowers maximum amount of creatures attacking Crawlspace's controller to 2.
Dueling Grounds - lowers maximum amount of attackers to 1 if higher. In addition, if this is not the first combat of the turn and any creatures have been declared as atackers on previous combats, no other creature is permitted to attack. (Not 100% sure what happens if multiple creatures attack, then Dueling Grounds enters the battlefield, and there's another combat, but I think you could attack with one of the creatures that attacked previously.)
Silent Arbiter - lowers global maximum of attackers to 1 if higher.

Attack costs (total cost of {0} is still functionally distinct from no cost as the creature is still unaffected by attack requirements since you may choose to "not pay" {0}):
Brainwash - adds cost of {3} for the creature to attack.
Collective Restraint - adds cost of {X} equal to number of basic land types controlled by Collective Restraint's controller for the creature to attack the controller of Collective Restraint.
Cowed by Wisdom - adds cost of mana equal to amount of cards in hand of Cowed by Wisdom's controller for the creature to attack.
Elephant Grass - adds cost of {2} for the creature to attack the controller of Elephant Grass.
Exalted Dragon - adds cost of "sacrifice a land" for Exalted Dragon to attack.
Flooded Woodlands - adds cost of "sacrifice a land" for the creature to attack.
Floodtide Serpent - adds cost of "return an enchantment you control to its owner's hand" for Floodtide Serpent to attack.
Ghostly Prison - adds cost of {2} for the creature to attack the controller of Ghostly Prison.
Hollow Warrior - adds cost "tap an untapped creature you control not declared as an attacking or blocking creature this combat" for Hollow Warrior to attack.
Koskun Falls - adds cost of {2} for the creature to attack the controller of Koskun Falls.
Leviathan - adds cost of "sacrifice two Islands" (can be hacked) for Leviathan to attack.
Myr Prototype - adds cost of {X} equal to number of +1/+1 counters on Myr Prototype for Myr Prototype to attack.
Norn's Annex - adds cost of {P/W} for the creature to attack the controller of Norn's Annex or one of his or her planeswalkers.
Oppressive Rays - adds cost of {3} for the creature to attack.
Phyrexian Marauder - adds cost of {X} equal to number of +1/+1 counters on Phyrexian Marauder for Phyrexian Marauder to attack.
Propaganda - adds cost of {2} for the creature to attack the controller of Propaganda.
Reclamation - adds cost of "sacrifice a land" for the creature to attack.
Sphere of Safety - adds cost of {X} equal to number of enchantments controlled by Sphere of Safety's controller for the creature to attack the controller of Sphere of Safety or one of his or her planeswalkers.
War Tax - adds cost of {X} for the creature to attack.
Whipgrass Entangler - adds cost of {X} equal to the number of Cleric permanents on the battlefield (can be artifically evolved) for the creature to attack.
Windborn Muse - adds cost of {2} for the creature to attack the controller of Windborn Muse.


Master Block List | Open
Blocking algorithm is more complicated than attacking one because some blockers can block multiple attackers.

The basic thing would be to determine, for each blocker, a set of creatures it could block (analogical to set of defenders an attacker could attack). Each blocker has a "blocking limit" which sets maximum amount of creatures it can block (can't be more than all possible attackers it could block). If a blocker has no limit on blocking, its limit is set as the number of attackers it can block.

Creatures that are tapped can't block unless specifically allowed to by Masako the Humorless. This list won't attempt to show various evasion abilities, blocking limitations (including "can't block") or "evasion ignoring" like Wall of Diffusion or Staff of the Ages; it will be more concerned with predicate restrictions and requirements. This also includes attacker-dependent restrictions like Goblin Goon; those simply remove possible blocking assignments depending on attacking creature's controller (or maybe they make creature able or unable to block based on stats of all attacking players? But that's only relevant in 2HG anyway).

As for banding, that seems to not come into effect during blocking declarations. Creature that blocks one member of the band will automatically become a blocker of the others after the declaration is complete. This presumably means that these automatic blocks can't be used to fulfill requirements.

Blocking requirements:
<creature1> must block <creature2> if able: This is the basic requirement that occurs in many forms, from focused provoke ability to global Lure effects or even something like Blaze of Glory. If creature1 can conceivably block creature2, it gets a requirement to do so.
Effects that create temporary effects of this kind can set them to last for a turn (Auriok Siege Sled) or for a combat (Avalanche Tusker). Presumably, if the effect lasts for the turn, it only needs to be satisfied once. Not sure what happens when effect is created AFTER it was already satisfied. (Not sure what happens in the attacking case here, either.)
<creature> blocks each/this turn if able: appears on Courtly Provocateur, Culling Mark, Grand Melee, Invasion Plans, Mark for Death, Nacatl Hunt-Pride, Predatory Rampage, Provoke, Razorgrass Screen, Spirespine and Watchdog. Creates a general requirement for the creature to block unless it was already declared as a blocker this turn. Ignored if the creature can't block anything.
<creature> must be blocked each/this turn if able: appears on Deadly Allure, Enlarge, Goblin Fire Fiend, Goldenhide Ox, Hinterland Hermit/Hinterland Scourge, Inescapable Brute, Irresistible Prey, Loathsome Catoblepas, Satyr Piper and vanguard card Sisters of Stone Death Avatar. Creates a general requirement for any creature to block this creature unless it was already blocked earlier this turn. Ignored if nothing can block it.
Boros Battleshaper - creates a general requirement for the creature to block, unless it was somehow declared as an attacker this combat. Ignored if the creature can't block anything.
Nacatl War-Pride - creates a requirement for Nacatl War-Pride which is satisfied only if Nacatl War-Pride is blocked by exactly one creature. If the creature is not blocked or if it's blocked by two or more creatures, the requirement is not satisfied. If nothing can block Nacatl War-Pride, the requirement is ignored. The requirement is also ignored if Nacatl War-Pride combines with "Can't be blocked except by two or more creatures" or "Can't be blocked except by three or more creatures".

Predicate restrictions:
On attackers:
Can't be blocked by more than one creature: Appears on Alpha Authority, Familiar Ground, Huang Zhong, Shu General, Ironhoof Ox, Krosan Vorine, Norwood Riders, Stalking Tiger, Vorrac Battlehorns and Yuan Shao, the Indecisive. Blocking sets where a creature with this power is blocked by two or more creatures are impossible. If combined with "Can't be blocked except by two or more creatures" or "Can't be blocked except by three or more creatures", it's treated as unblockable.
Can't be blocked except by two or more creatures: Appears on Belligerent Sliver, Caterwauling Boggart, Demoralize, Goblin War Drums, Gorilla War Cry, Gruul Nodorog, Gruul War Chant, Horde of Boggarts, Imposing Visage, Iroas, God of Victory, Kederekt Creeper, Kruin Outlaw/Terror of Kruin Pass, Madcap Skills, Purphoros's Emissary, Pyreheart Wolf, Ripscale Predator, Searing Spear Askari, Stormblood Berserker, Summit Apes, Two-Headed Dragon, Two-Headed Sliver, Viashino Runner, Vine Kami, Wind Spirit and vanguard card Two-Headed Giant of Foriys Avatar. Blocking sets where a creature with this power is blocked by exactly one creature are impossible. If only one creature could block this creature, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", it's treated as unblockable.
Can't be blocked except by three or more creatures: Appears on Gorilla Berserkers, Guile, Pathrazer of Ulamog, Phyrexian Colossus and Underworld Cerberus. Blocking sets where a creature with this power is blocked by exactly one creature or exactly two creatures are impossible. If only one or two creatures could block this creature, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", it's treated as unblockable.
Tromokratis - If defending player controls n creatures, where n >= 2, blocking sets where Tromokratis is blocked by 1 - (n-1) creatures are impossible. If defending player controls at least 1 creature that is not able to block Tromokratis for whatever reason, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", Tromokratis is treated as unblockable if defending player controls at least 2 creatures.

On blockers:
Can't block alone: Appears on Ember Beast, Jackal Familiar, Loyal Pegasus and Mogg Flunkies. Blocking sets where only this creature blocks are impossible.
Okk - Blocking sets where Okk is the creature with the highest power or one of the creatures with the highest power are impossible.
Orcish Conscripts - Blocking sets which contain only Orcish Conscripts or Orcish Conscripts and exactly one other creature are impossible.

Global limitations:
Astral Arena - sets global maximum of blockers to 1 if higher.
Caverns of Despair - sets global maximum of blockers to 2 if higher.
Dueling Grounds - lowers global maximum of blockers to 1 if higher. In addition, if this is not the first combat of the turn and any creatures have been declared as blockers on previous combats, no other creature is permitted to block. (Similar caveat as in the attack scenario.)
Silent Arbiter - sets global maximum of blockers to 1 if higher.

Blocking costs (similar caveat about {0} cost as in attacking case; in addition, it seems that it's generally only required to pay for the blocker once, even if it blocks multiple attackers):
Awesome Presence - adds cost of {3} for the creature to block the creature enchanted with Awesome Presence. (Payment is of course valid only for one creature with Awesome Presence.)
Cowed by Wisdom - adds cost of {X} equal to amount of cards in hand of Cowed by Wisdom's controller for the creature to block.
Heat Wave - adds cost of "1 life" for the creature to block creatures controlled by the controller of Heat Wave.
Hipparion - adds cost of {1} for Hipparion to block creatures with power 3 or greater.
Hollow Warrior - adds cost "tap an untapped creature you control not declared as an attacking or blocking creature this combat" for Hollow Warrior to block.
Myr Prototype - adds cost of {X} equal to number of +1/+1 counters on Myr Prototype for Myr Prototype to block.
Oppressive Rays - adds cost of {3} for the creature to block.
War Cadence - adds cost of {X} for the creature to block.
Whipgrass Entangler - adds cost of {X} equal to the number of Cleric permanents on the battlefield (can be artifically evolved) for the creature to block.
Last edited by elcnesh on 20 Oct 2014, 07:32, edited 2 times in total.
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby Marek14 » 18 Oct 2014, 17:30

Basically, what you're doing is to combine attackers with predicate restrictions into "pseudo-attackers", groups that satisfy all such restrictions for their members, right?

The first problem is -- what to do about attack costs? If a cost is not paid, then a creature cannot be forced to attack, but if a cost IS paid, then the creature could, for example, be a part of a base chain -- and the problem is that you pay the costs afterwards, so when the algorithm selects the attackers, it basically can't know whether it's possible to pay the costs associated with a particular set of attackers.

I'll make a list of relevant cards to see better what's needed.

Also note that at some point during the algorithm, it will determine whether a creature is capable of attacking or not. If this information is retain somewhere, it would allow implementing Season of the Witch.
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Re: Combat Refactoring

Postby Marek14 » 18 Oct 2014, 19:13

OK, I parsed the whole card list for "attack" and wrote out the relevant cards. Please let me know if I should do the same for "block".

Attack requirements:
Attacks this/each combat if able: appears on Hellraiser Goblin, Illusionist's Gambit, Marauding Maulhorn and Zurgo Helmsmasher. Creates one general requirement for the creature to attack.
Attacks this/each turn if able: common effect. Creates one general requirement for the creature to attack unless the creature was already declared as an attacker earlier this turn.
Attacks <defender> this/each combat if able: appears on Ruhan of the Fomori and scheme cards Rotted Ones, Lay Siege and The Dead Shall Serve. Creates a requirement for the creature to attack a specific defender.
Attacks <defender> this/each turn if able: appears on Alluring Siren, Gideon Jura and Taunt (I presume) and scheme card My Crushing Masterstroke. Creates a requirement for the creature to attack a specific defender unless it already attacked that defender earlier this turn.
Attacks or blocks this combat if able: appears on Boros Battleshaper. Creates a general requirement for the creature to attack. In case the creature attacks and then is stolen by the defender, it would no longer be required to block as the requirement was already fulfilled, but for purpose of attacking, it behaves exactly like "Attacks each/this combat if able."
Cogwork Tracker: Creates a requirement for the creature to attack any player from a defined set of players, if that set is non-empty.
Ekundu Cyclops: Creates a requirement on itself that is satisfied if either Ekundu Cyclops attacks or if NO creatures attack. It's not satisfied if there's a non-empty set of attackers that doesn't include Ekundu Cyclops. If Ekundu Cyclops is generally incapable of attacking, the requirement should not be created (otherwise strange situations might result).
Magnetic Web: Creates a requirement on each creature with at least one magnet counter that is satisfied if either that creature attacks or if NO creatures with at least one magnet counter attack. If some creatures with magnet counters attack and some don't, the requirements for those not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
Viashino Bey: Creates a requirement on each creature that is satisfied if either that creature attacks or if Viashino Bey does NOT attack. If Viashino Bey attacks, the requirements for creatures that are not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
War's Toll: Creates a requirement on each creature controlled by the active opponent(s) that is satisfied if either that creature attacks or if NO creatures controlled by that opponent attack. If some opponent's creatures attack and some don't, the requirements for those not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.

Individual attack restrictions:
Can't attack: common effect. Creature can't be declared as attacker at all. Creatures with defender belong here unless they are able to ignore defender (from Animate Wall, Rolling Stones, Wakestone Gargoyle, Warmonger's Chariot or from innate abilities of Colossus of Akros, Dark Maze, Mirror Wall, Mobile Fort, Nivix Cyclops, Ogre Jailbreaker, Pillar of War, Prison Barricade, Returned Phalanx, Slithering Shade, Spire Serpent, Vodalian War Machine, Walking Wall or Wall of Wonder). Detained creatures belong here. Creatures with summoning sickness belong here unless they have haste or are capable of attacking as though they had haste (Chaos Lord/Instill Energy). Conditional effects like Blind-Spot Giant belong here if the condition is not dependent on other declarations OR on the defender (they are simply checked once and then it's decided whether they apply or not).
Can't attack <defender>: appears on Arboria, Blazing Archon, Chronomantic Escape, Elephant Grass, Form of the Dragon, Illusionist's Gambit, Island Sanctuary, Mystic Barrier, Reverence, Teferi's Moat, Vow of Duty, Vow of Flight, Vow of Lightning, Vow of Malice, Vow of Wildness, Web of Inertia and plane card Agyrem. Removes specific defender(s) from the set of defenders a creature can attack. Creatures with defender-dependent attack condition like Armored Galleon belong here; if the condition is not satisfied for a particular player, the creature can't attack that player or any of his planeswalkers. In case of 2HG (not implemented yet), a team can be attacked if any player on the team satisfies a "can't attack unless" condition, but not if any player satisfies a "can't attack if" condition; I presume that an individual player must still satisfy the condition if a planeswalker is attacked.
"Can't attack unless" defender-dependent conditions: Armored Galleon, Bog Serpent, Chained Throatseeker, Dandan, Deep-Sea Serpent, Dreamwinder, Ethereal Whiskergill, Floodchaser, Giant Shark, Goblin Goon, Goblin Rock Sled, Godhunter Octopus, Gorilla Pack, Hammerhead Shark, Island Fish Jasconius, Kukemssa Serpent, Manta Ray, Marjhan, Merchant Ship, Mogg Toady, Monstrous Hound, Pirate Ship, Red Cliffs Armada, Ronom Serpent, Sea Monster, Sea Serpent, Sealock Monster, Serpent of the Endless Sea, Slipstream Eel, Slipstream Serpent, Steam Frigate, Veiled Serpent, Vodalian Knights, Vodalian Serpent, Whimwader, Wu Warship, Zhou Yu, Chief Commander
"Can't attack if" defender-dependent conditions: Branded Brawlers, Goblin Mutant, Mogg Jailer, Orgg, Veteran Brawlers

Predicate restrictions:
"Can't attack alone": appears on Ember Beast, Jackal Familiar, Loyal Pegasus, Mogg Flunkies and Sightless Brawler. Attack sets which contain only this creature are impossible. If combined with "Can only attack alone", the creature can't attack at all.
"Can only attack alone": appears on Errantry and Master of Cruelties. Attack sets which contain this creature and any other creature are impossible. If combined with "Can't attack alone" or with Okk, Orcish Conscripts or Scarred Puma, the creature can't attack at all.
Okk: Attack sets where Okk is the creature with the highest power or one of the creatures with the highest power are impossible. If combined with "Can only attack alone", Okk can't attack at all.
Orcish Conscripts: Attack sets which contain only Orcish Conscripts or Orcish Conscripts and exactly one other creature are impossible. If combined with "Can only attack alone", Orcish Conscripts can't attack at all.
Scarred Puma: Attack sets that include Scarred Puma, but no other creature of specified color(s) (which can be modified through sleight effects or Swirl the Mists) are impossible. Gatherer rulings indicate that Scarred Puma can never satisfy its own condition even if it has the required color(s). If combined with "Can only attack alone", Scarred Puma can't attack at all.

Global attack limiters:
Astral Arena - lowers global maximum of attackers to 1 if higher.
Caverns of Despair - lowers global maximum of attackers to 2 if higher.
Crawlspace - lowers maximum amount of creatures attacking Crawlspace's controller to 2.
Dueling Grounds - lowers maximum amount of attackers to 1 if higher. In addition, if this is not the first combat of the turn and any creatures have been declared as atackers on previous combats, no other creature is permitted to attack. (Not 100% sure what happens if multiple creatures attack, then Dueling Grounds enters the battlefield, and there's another combat, but I think you could attack with one of the creatures that attacked previously.)
Silent Arbiter - lowers global maximum of attackers to 1 if higher.

Attack costs (total cost of {0} is still functionally distinct from no cost as the creature is still unaffected by attack requirements since you may choose to "not pay" {0}):
Brainwash - adds cost of {3} for the creature to attack.
Collective Restraint - adds cost of {X} equal to number of basic land types controlled by Collective Restraint's controller for the creature to attack the controller of Collective Restraint.
Cowed by Wisdom - adds cost of mana equal to amount of cards in hand of Cowed by Wisdom's controller for the creature to attack.
Elephant Grass - adds cost of {2} for the creature to attack the controller of Elephant Grass.
Exalted Dragon - adds cost of "sacrifice a land" for Exalted Dragon to attack.
Flooded Woodlands - adds cost of "sacrifice a land" for the creature to attack.
Floodtide Serpent - adds cost of "return an enchantment you control to its owner's hand" for Floodtide Serpent to attack.
Ghostly Prison - adds cost of {2} for the creature to attack the controller of Ghostly Prison.
Hollow Warrior - adds cost "tap an untapped creature you control not declared as an attacking or blocking creature this combat" for Hollow Warrior to attack.
Koskun Falls - adds cost of {2} for the creature to attack the controller of Koskun Falls.
Leviathan - adds cost of "sacrifice two Islands" (can be hacked) for Leviathan to attack.
Myr Prototype - adds cost of {X} equal to number of +1/+1 counters on Myr Prototype for Myr Prototype to attack.
Norn's Annex - adds cost of {P/W} for the creature to attack the controller of Norn's Annex or one of his or her planeswalkers.
Oppressive Rays - adds cost of {3} for the creature to attack.
Phyrexian Marauder - adds cost of {X} equal to number of +1/+1 counters on Phyrexian Marauder for Phyrexian Marauder to attack.
Propaganda - adds cost of {2} for the creature to attack the controller of Propaganda.
Reclamation - adds cost of "sacrifice a land" for the creature to attack.
Sphere of Safety - adds cost of {X} equal to number of enchantments controlled by Sphere of Safety's controller for the creature to attack the controller of Sphere of Safety or one of his or her planeswalkers.
War Tax - adds cost of {X} for the creature to attack.
Whipgrass Entangler - adds cost of {X} equal to the number of Cleric permanents on the battlefield (can be artifically evolved) for the creature to attack.
Windborn Muse - adds cost of {2} for the creature to attack the controller of Windborn Muse.
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Re: Combat Refactoring

Postby elcnesh » 18 Oct 2014, 19:31

Wow. :shock: I don't know what to say, except a huge "THANK YOU"!!!! That's amazing :D =D>

Edit: A blocking list would also be amazing, but that'll become relevant once we've figured out the attack stuff ;)
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby timmermac » 18 Oct 2014, 19:38

Marek14 wrote:OK, I parsed the whole card list for "attack" and wrote out the relevant cards. Please let me know if I should do the same for "block".

Attack requirements:
Attacks this/each combat if able: appears on Hellraiser Goblin, Illusionist's Gambit, Marauding Maulhorn and Zurgo Helmsmasher. Creates one general requirement for the creature to attack.
Attacks this/each turn if able: common effect. Creates one general requirement for the creature to attack unless the creature was already declared as an attacker earlier this turn.
Attacks <defender> this/each combat if able: appears on Ruhan of the Fomori and scheme cards Rotted Ones, Lay Siege and The Dead Shall Serve. Creates a requirement for the creature to attack a specific defender.
Attacks <defender> this/each turn if able: appears on Alluring Siren, Gideon Jura and Taunt (I presume) and scheme card My Crushing Masterstroke. Creates a requirement for the creature to attack a specific defender unless it already attacked that defender earlier this turn.
Attacks or blocks this combat if able: appears on Boros Battleshaper. Creates a general requirement for the creature to attack. In case the creature attacks and then is stolen by the defender, it would no longer be required to block as the requirement was already fulfilled, but for purpose of attacking, it behaves exactly like "Attacks each/this combat if able."
Cogwork Tracker: Creates a requirement for the creature to attack any player from a defined set of players, if that set is non-empty.
Ekundu Cyclops: Creates a requirement on itself that is satisfied if either Ekundu Cyclops attacks or if NO creatures attack. It's not satisfied if there's a non-empty set of attackers that doesn't include Ekundu Cyclops. If Ekundu Cyclops is generally incapable of attacking, the requirement should not be created (otherwise strange situations might result).
Magnetic Web: Creates a requirement on each creature with at least one magnet counter that is satisfied if either that creature attacks or if NO creatures with at least one magnet counter attack. If some creatures with magnet counters attack and some don't, the requirements for those not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
Viashino Bey: Creates a requirement on each creature that is satisfied if either that creature attacks or if Viashino Bey does NOT attack. If Viashino Bey attacks, the requirements for creatures that are not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.
War's Toll: Creates a requirement on each creature controlled by the active opponent(s) that is satisfied if either that creature attacks or if NO creatures controlled by that opponent attack. If some opponent's creatures attack and some don't, the requirements for those not attacking are not satisfied. Creatures generally unable to attack shouldn't get requirements.

Individual attack restrictions:
Can't attack: common effect. Creature can't be declared as attacker at all. Creatures with defender belong here unless they are able to ignore defender (from Animate Wall, Rolling Stones, Wakestone Gargoyle, Warmonger's Chariot or from innate abilities of Colossus of Akros, Dark Maze, Mirror Wall, Mobile Fort, Nivix Cyclops, Ogre Jailbreaker, Pillar of War, Prison Barricade, Returned Phalanx, Slithering Shade, Spire Serpent, Vodalian War Machine, Walking Wall or Wall of Wonder). Detained creatures belong here. Creatures with summoning sickness belong here unless they have haste or are capable of attacking as though they had haste (Chaos Lord/Instill Energy). Conditional effects like Blind-Spot Giant belong here if the condition is not dependent on other declarations OR on the defender (they are simply checked once and then it's decided whether they apply or not).
Can't attack <defender>: appears on Arboria, Blazing Archon, Chronomantic Escape, Elephant Grass, Form of the Dragon, Illusionist's Gambit, Island Sanctuary, Mystic Barrier, Reverence, Teferi's Moat, Vow of Duty, Vow of Flight, Vow of Lightning, Vow of Malice, Vow of Wildness, Web of Inertia and plane card Agyrem. Removes specific defender(s) from the set of defenders a creature can attack. Creatures with defender-dependent attack condition like Armored Galleon belong here; if the condition is not satisfied for a particular player, the creature can't attack that player or any of his planeswalkers. In case of 2HG (not implemented yet), a team can be attacked if any player on the team satisfies a "can't attack unless" condition, but not if any player satisfies a "can't attack if" condition; I presume that an individual player must still satisfy the condition if a planeswalker is attacked.
"Can't attack unless" defender-dependent conditions: Armored Galleon, Bog Serpent, Chained Throatseeker, Dandan, Deep-Sea Serpent, Dreamwinder, Ethereal Whiskergill, Floodchaser, Giant Shark, Goblin Goon, Goblin Rock Sled, Godhunter Octopus, Gorilla Pack, Hammerhead Shark, Island Fish Jasconius, Kukemssa Serpent, Manta Ray, Marjhan, Merchant Ship, Mogg Toady, Monstrous Hound, Pirate Ship, Red Cliffs Armada, Ronom Serpent, Sea Monster, Sea Serpent, Sealock Monster, Serpent of the Endless Sea, Slipstream Eel, Slipstream Serpent, Steam Frigate, Veiled Serpent, Vodalian Knights, Vodalian Serpent, Whimwader, Wu Warship, Zhou Yu, Chief Commander
"Can't attack if" defender-dependent conditions: Branded Brawlers, Goblin Mutant, Mogg Jailer, Orgg, Veteran Brawlers

Predicate restrictions:
"Can't attack alone": appears on Ember Beast, Jackal Familiar, Loyal Pegasus, Mogg Flunkies and Sightless Brawler. Attack sets which contain only this creature are impossible. If combined with "Can only attack alone", the creature can't attack at all.
"Can only attack alone": appears on Errantry and Master of Cruelties. Attack sets which contain this creature and any other creature are impossible. If combined with "Can't attack alone" or with Okk, Orcish Conscripts or Scarred Puma, the creature can't attack at all.
Okk: Attack sets where Okk is the creature with the highest power or one of the creatures with the highest power are impossible. If combined with "Can only attack alone", Okk can't attack at all.
Orcish Conscripts: Attack sets which contain only Orcish Conscripts or Orcish Conscripts and exactly one other creature are impossible. If combined with "Can only attack alone", Orcish Conscripts can't attack at all.
Scarred Puma: Attack sets that include Scarred Puma, but no other creature of specified color(s) (which can be modified through sleight effects or Swirl the Mists) are impossible. Gatherer rulings indicate that Scarred Puma can never satisfy its own condition even if it has the required color(s). If combined with "Can only attack alone", Scarred Puma can't attack at all.

Global attack limiters:
Astral Arena - lowers global maximum of attackers to 1 if higher.
Caverns of Despair - lowers global maximum of attackers to 2 if higher.
Crawlspace - lowers maximum amount of creatures attacking Crawlspace's controller to 2.
Dueling Grounds - lowers maximum amount of attackers to 1 if higher. In addition, if this is not the first combat of the turn and any creatures have been declared as atackers on previous combats, no other creature is permitted to attack. (Not 100% sure what happens if multiple creatures attack, then Dueling Grounds enters the battlefield, and there's another combat, but I think you could attack with one of the creatures that attacked previously.)
Silent Arbiter - lowers global maximum of attackers to 1 if higher.

Attack costs (total cost of {0} is still functionally distinct from no cost as the creature is still unaffected by attack requirements since you may choose to "not pay" {0}):
Brainwash - adds cost of {3} for the creature to attack.
Collective Restraint - adds cost of {X} equal to number of basic land types controlled by Collective Restraint's controller for the creature to attack the controller of Collective Restraint.
Cowed by Wisdom - adds cost of mana equal to amount of cards in hand of Cowed by Wisdom's controller for the creature to attack.
Elephant Grass - adds cost of {2} for the creature to attack the controller of Elephant Grass.
Exalted Dragon - adds cost of "sacrifice a land" for Exalted Dragon to attack.
Flooded Woodlands - adds cost of "sacrifice a land" for the creature to attack.
Floodtide Serpent - adds cost of "return an enchantment you control to its owner's hand" for Floodtide Serpent to attack.
Ghostly Prison - adds cost of {2} for the creature to attack the controller of Ghostly Prison.
Hollow Warrior - adds cost "tap an untapped creature you control not declared as an attacking or blocking creature this combat" for Hollow Warrior to attack.
Koskun Falls - adds cost of {2} for the creature to attack the controller of Koskun Falls.
Leviathan - adds cost of "sacrifice two Islands" (can be hacked) for Leviathan to attack.
Myr Prototype - adds cost of {X} equal to number of +1/+1 counters on Myr Prototype for Myr Prototype to attack.
Norn's Annex - adds cost of {P/W} for the creature to attack the controller of Norn's Annex or one of his or her planeswalkers.
Oppressive Rays - adds cost of {3} for the creature to attack.
Phyrexian Marauder - adds cost of {X} equal to number of +1/+1 counters on Phyrexian Marauder for Phyrexian Marauder to attack.
Propaganda - adds cost of {2} for the creature to attack the controller of Propaganda.
Reclamation - adds cost of "sacrifice a land" for the creature to attack.
Sphere of Safety - adds cost of {X} equal to number of enchantments controlled by Sphere of Safety's controller for the creature to attack the controller of Sphere of Safety or one of his or her planeswalkers.
War Tax - adds cost of {X} for the creature to attack.
Whipgrass Entangler - adds cost of {X} equal to the number of Cleric permanents on the battlefield (can be artifically evolved) for the creature to attack.
Windborn Muse - adds cost of {2} for the creature to attack the controller of Windborn Muse.
You didn't mention Juggernaut. Oversight or intentional?
"I just woke up, haven't had coffee, let alone a pee in 7 days, and I find out you stole my ass and made a ...mini-me! Carter, I should be irked currently, yes?" - Jack O'Neill
User avatar
timmermac
Tester
 
Posts: 1512
Joined: 17 May 2010, 20:36
Has thanked: 18 times
Been thanked: 95 times

Re: Combat Refactoring

Postby Marek14 » 18 Oct 2014, 19:53

timmermac wrote:You didn't mention Juggernaut. Oversight or intentional?
I mentioned this:

Attacks this/each turn if able: common effect.

Basically, since there are tons of effects that force creatures to attack each turn or that stop them from attacking at all, I decided to not give a full list since it would be probably counterproductive.
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Re: Combat Refactoring

Postby Marek14 » 18 Oct 2014, 21:20

Master blocking list:

Blocking algorithm is more complicated than attacking one because some blockers can block multiple attackers.

The basic thing would be to determine, for each blocker, a set of creatures it could block (analogical to set of defenders an attacker could attack). Each blocker has a "blocking limit" which sets maximum amount of creatures it can block (can't be more than all possible attackers it could block). If a blocker has no limit on blocking, its limit is set as the number of attackers it can block.

Creatures that are tapped can't block unless specifically allowed to by Masako the Humorless. This list won't attempt to show various evasion abilities, blocking limitations (including "can't block") or "evasion ignoring" like Wall of Diffusion or Staff of the Ages; it will be more concerned with predicate restrictions and requirements. This also includes attacker-dependent restrictions like Goblin Goon; those simply remove possible blocking assignments depending on attacking creature's controller (or maybe they make creature able or unable to block based on stats of all attacking players? But that's only relevant in 2HG anyway).

As for banding, that seems to not come into effect during blocking declarations. Creature that blocks one member of the band will automatically become a blocker of the others after the declaration is complete. This presumably means that these automatic blocks can't be used to fulfill requirements.

Blocking requirements:
<creature1> must block <creature2> if able: This is the basic requirement that occurs in many forms, from focused provoke ability to global Lure effects or even something like Blaze of Glory. If creature1 can conceivably block creature2, it gets a requirement to do so.
Effects that create temporary effects of this kind can set them to last for a turn (Auriok Siege Sled) or for a combat (Avalanche Tusker). Presumably, if the effect lasts for the turn, it only needs to be satisfied once. Not sure what happens when effect is created AFTER it was already satisfied. (Not sure what happens in the attacking case here, either.)
<creature> blocks each/this turn if able: appears on Courtly Provocateur, Culling Mark, Grand Melee, Invasion Plans, Mark for Death, Nacatl Hunt-Pride, Predatory Rampage, Provoke, Razorgrass Screen, Spirespine and Watchdog. Creates a general requirement for the creature to block unless it was already declared as a blocker this turn. Ignored if the creature can't block anything.
<creature> must be blocked each/this turn if able: appears on Deadly Allure, Enlarge, Goblin Fire Fiend, Goldenhide Ox, Hinterland Hermit/Hinterland Scourge, Inescapable Brute, Irresistible Prey, Loathsome Catoblepas, Satyr Piper and vanguard card Sisters of Stone Death Avatar. Creates a general requirement for any creature to block this creature unless it was already blocked earlier this turn. Ignored if nothing can block it.
Boros Battleshaper - creates a general requirement for the creature to block, unless it was somehow declared as an attacker this combat. Ignored if the creature can't block anything.
Nacatl War-Pride - creates a requirement for Nacatl War-Pride which is satisfied only if Nacatl War-Pride is blocked by exactly one creature. If the creature is not blocked or if it's blocked by two or more creatures, the requirement is not satisfied. If nothing can block Nacatl War-Pride, the requirement is ignored. The requirement is also ignored if Nacatl War-Pride combines with "Can't be blocked except by two or more creatures" or "Can't be blocked except by three or more creatures".

Predicate restrictions:
On attackers:
Can't be blocked by more than one creature: Appears on Alpha Authority, Familiar Ground, Huang Zhong, Shu General, Ironhoof Ox, Krosan Vorine, Norwood Riders, Stalking Tiger, Vorrac Battlehorns and Yuan Shao, the Indecisive. Blocking sets where a creature with this power is blocked by two or more creatures are impossible. If combined with "Can't be blocked except by two or more creatures" or "Can't be blocked except by three or more creatures", it's treated as unblockable.
Can't be blocked except by two or more creatures: Appears on Belligerent Sliver, Caterwauling Boggart, Demoralize, Goblin War Drums, Gorilla War Cry, Gruul Nodorog, Gruul War Chant, Horde of Boggarts, Imposing Visage, Iroas, God of Victory, Kederekt Creeper, Kruin Outlaw/Terror of Kruin Pass, Madcap Skills, Purphoros's Emissary, Pyreheart Wolf, Ripscale Predator, Searing Spear Askari, Stormblood Berserker, Summit Apes, Two-Headed Dragon, Two-Headed Sliver, Viashino Runner, Vine Kami, Wind Spirit and vanguard card Two-Headed Giant of Foriys Avatar. Blocking sets where a creature with this power is blocked by exactly one creature are impossible. If only one creature could block this creature, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", it's treated as unblockable.
Can't be blocked except by three or more creatures: Appears on Gorilla Berserkers, Guile, Pathrazer of Ulamog, Phyrexian Colossus and Underworld Cerberus. Blocking sets where a creature with this power is blocked by exactly one creature or exactly two creatures are impossible. If only one or two creatures could block this creature, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", it's treated as unblockable.
Tromokratis - If defending player controls n creatures, where n >= 2, blocking sets where Tromokratis is blocked by 1 - (n-1) creatures are impossible. If defending player controls at least 1 creature that is not able to block Tromokratis for whatever reason, it's treated as unblockable. If combined with "Can't be blocked by more than one creature", Tromokratis is treated as unblockable if defending player controls at least 2 creatures.

On blockers:
Can't block alone: Appears on Ember Beast, Jackal Familiar, Loyal Pegasus and Mogg Flunkies. Blocking sets where only this creature blocks are impossible.
Okk - Blocking sets where Okk is the creature with the highest power or one of the creatures with the highest power are impossible.
Orcish Conscripts - Blocking sets which contain only Orcish Conscripts or Orcish Conscripts and exactly one other creature are impossible.

Global limitations:
Astral Arena - sets global maximum of blockers to 1 if higher.
Caverns of Despair - sets global maximum of blockers to 2 if higher.
Dueling Grounds - lowers global maximum of blockers to 1 if higher. In addition, if this is not the first combat of the turn and any creatures have been declared as blockers on previous combats, no other creature is permitted to block. (Similar caveat as in the attack scenario.)
Silent Arbiter - sets global maximum of blockers to 1 if higher.

Blocking costs (similar caveat about {0} cost as in attacking case; in addition, it seems that it's generally only required to pay for the blocker once, even if it blocks multiple attackers):
Awesome Presence - adds cost of {3} for the creature to block the creature enchanted with Awesome Presence. (Payment is of course valid only for one creature with Awesome Presence.)
Cowed by Wisdom - adds cost of {X} equal to amount of cards in hand of Cowed by Wisdom's controller for the creature to block.
Heat Wave - adds cost of "1 life" for the creature to block creatures controlled by the controller of Heat Wave.
Hipparion - adds cost of {1} for Hipparion to block creatures with power 3 or greater.
Hollow Warrior - adds cost "tap an untapped creature you control not declared as an attacking or blocking creature this combat" for Hollow Warrior to block.
Myr Prototype - adds cost of {X} equal to number of +1/+1 counters on Myr Prototype for Myr Prototype to block.
Oppressive Rays - adds cost of {3} for the creature to block.
War Cadence - adds cost of {X} for the creature to block.
Whipgrass Entangler - adds cost of {X} equal to the number of Cleric permanents on the battlefield (can be artifically evolved) for the creature to block.
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Re: Combat Refactoring

Postby elcnesh » 20 Oct 2014, 07:33

I've copied your two amazing posts to the first post for easy reference :)
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby Marek14 » 20 Oct 2014, 19:07

elcnesh wrote:I've copied your two amazing posts to the first post for easy reference :)
No problem :)
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Re: Combat Refactoring

Postby elcnesh » 21 Oct 2014, 20:21

I just figured out an algorithm to do everything much simpler and much more elegantly; see the google docs (last page, starts after all the initial checks). I'm not sure if it works, but it's a lot cleaner and a lot faster than everything I had so far. Can someone have a look whether it makes sense? If so, it's almost trivial to implement. The only thing it doesn't do yet is allow you ignore costs when determining requirements, but I think this can be achieved by just skipping those requirements when traversing the list.

Lesson learned for me: don't try to come with clever algorithms while being ill :P
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby Marek14 » 22 Oct 2014, 08:16

Had a look at it; it's a bit complicated -- would it, for example, resolve a situation where there's Master of Cruelties with three attacking requirements and two normal creatures with two requirements? If you attack with Master of Cruelties, it has to attack alone and satisfies three requirements, but when you attack with other two creatures, you will satisfy four. I.e. the maximum amount of satisfied requirements doesn't involve the creature with most requirements at all.

As for ignoring costs, there's a case when you have, say, Mogg Flunkies and a creature with attack cost -- would your approach cause Mogg Flunkies to not be able to attack at all?

Maybe a solution here would be to build the legal attack list for each combination of paid costs separately, but that would get too problematic in situations like token deck versus Propaganda when there's lots of creatures with attack costs.

Ekundu Cyclops, Magnetic Web, Viashino Bey and War's Toll look like they would all work in this framework. Ekundu Cyclops adds requirement to attack each defender after another creature is chosen, Magnetic Web adds requirement to each creature with a magnet counter after one is chosen, Viashino Bey adds requirement to each creature after it's chosen and War's Toll adds requirement to each creature once one is chosen.

Basically, any set of attackers would belong to one of three categories:
1. Legal set which can be selected by itself.
2. Pre-legal set which can't be selected but can be made legal by selecting more attackers.
3. Illegal set which can't be selected and can't be made legal by selecting more attackers.
This is important because players don't select the whole set at once; they select attackers sequentially. At each point, only such assignments which makes the whole set legal or pre-legal can be selected. (Perhaps the potential attackers could get a color overlay signifying which would make the attack set legal, pre-legal or illegal, and that by itself would be dependent on the currently selected defender.)
This would also mean that the current practice of making creatures like Juggernaut attack automatically should be abandoned and they should be selected manually like all other creatures, which would also made attacking planeswalkers with them easier.

And it could be adapted to blocking as well, if you can remove requirements as well as adding them:
<creature1> must block <creature2> if able: a simple requirement for creature1 to block creature2.
<creature> must block if able: a requirement for creature to block everything it can if it's currently not blocking anything; removed once the creature blocks
<creature> must be blocked if able: a requirement for every creature that can block it to block this creature if it's currently unblocked; removed once something blocks this creature
Nacatl War-Pride: a requirement for every creature that can block Nacatl War-Pride to block it; once one creature blocks it, there's a NEGATIVE requirement for every creature to block it (since this will break one requirement); once two or more creatures block it, there are no more requirements, positive or negative.

With the predicate requirements, care must be taken to never create them on creatures that are incapable of attacking/blocking since this would throw the math into disarray.

Also, be careful about this scenario:

Ekundu Cyclops and a random creature can attack. Attack with the random creature itself satisfies no requirements, while attack with Ekundu Cyclops and the creature satisfies one; this is correct. But your algorithm might also determine that not attacking at all, or attacking only with Ekundu Cyclops satisfies no requirements either (since the Ekundu Cyclops requirement is not created in this case).

But Ekundu Cyclops actually creates a requirement in all cases, and because it's a logical implication it's satisfied when either the second term is true or when the first term is false.

This means that you might need the negative requirements even in attacking case:
Ekundu Cyclops: If no creatures are selected, selecting anything but the Ekundu Cyclops has -1 requirement as it breaks the EC's requirement. If at least one creature is selected, selecting Ekundu Cyclops has +1 requirement.
Viashino Bey: If Viashino Bey is not selected, selecting it has -n requirements where n is the total amount of possible remaining attackers. If Viashino Bey is selected, selecting any creature has +1 requirement.
Magnetic Web: If no creature with a magnet counter is selected, selecting one has -n requirements where n is the total amount of possible remaining attackers with magnet counters. If at least one such creature is selected, selecting any other creature with a magnet counter has +1 requirement.
War's Toll: If no creature controlled by a particular player are selected, selecting one has -n requirements where n is the total amount of possible remaining attackers controlled by that player. If at least one such creature is selected, selecting any other creature controlled by that player has +1 requirement.
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Re: Combat Refactoring

Postby elcnesh » 22 Oct 2014, 13:41

Marek14 wrote:Had a look at it; it's a bit complicated
Thanks! It is complicated; that's why I'm asking for help ;)

Marek14 wrote:Would it, for example, resolve a situation where there's Master of Cruelties with three attacking requirements and two normal creatures with two requirements? If you attack with Master of Cruelties, it has to attack alone and satisfies three requirements, but when you attack with other two creatures, you will satisfy four. I.e. the maximum amount of satisfied requirements doesn't involve the creature with most requirements at all.
"can only attack alone" restrictions are handled as before, ie. they're checked separately. The final set chosen also checks those, so this should be fine.

Marek14 wrote:As for ignoring costs, there's a case when you have, say, Mogg Flunkies and a creature with attack cost -- would your approach cause Mogg Flunkies to not be able to attack at all?
No, mainly because the approach only searches for a set of attackers fulflilling the most requirements. If Mogg Flunkies has a requirement in your scenario, it won't be forced to attack; but you still can (provided you pay the cost for the other creature).

Marek14 wrote:Maybe a solution here would be to build the legal attack list for each combination of paid costs separately, but that would get too problematic in situations like token deck versus Propaganda when there's lots of creatures with attack costs.
That'd definitely be too slow... I'll implement and test it with costs, just to see how well it works.

Marek14 wrote:Ekundu Cyclops, Magnetic Web, Viashino Bey and War's Toll look like they would all work in this framework. Ekundu Cyclops adds requirement to attack each defender after another creature is chosen, Magnetic Web adds requirement to each creature with a magnet counter after one is chosen, Viashino Bey adds requirement to each creature after it's chosen and War's Toll adds requirement to each creature once one is chosen.

Basically, any set of attackers would belong to one of three categories:
1. Legal set which can be selected by itself.
2. Pre-legal set which can't be selected but can be made legal by selecting more attackers.
3. Illegal set which can't be selected and can't be made legal by selecting more attackers.
This is important because players don't select the whole set at once; they select attackers sequentially. At each point, only such assignments which makes the whole set legal or pre-legal can be selected. (Perhaps the potential attackers could get a color overlay signifying which would make the attack set legal, pre-legal or illegal, and that by itself would be dependent on the currently selected defender.)
This would also mean that the current practice of making creatures like Juggernaut attack automatically should be abandoned and they should be selected manually like all other creatures, which would also made attacking planeswalkers with them easier.
The plan was to abandon that anyway. Selecting attackers will no longer suffer from any requirements, those'll only be checked once you complete your declaration (as the comp rules also specify). Except creatures that can't attack anyway this combat (like tapped ones), it makes sense not to be able to select those.

Marek14 wrote:And it could be adapted to blocking as well, if you can remove requirements as well as adding them:
<creature1> must block <creature2> if able: a simple requirement for creature1 to block creature2.
<creature> must block if able: a requirement for creature to block everything it can if it's currently not blocking anything; removed once the creature blocks
<creature> must be blocked if able: a requirement for every creature that can block it to block this creature if it's currently unblocked; removed once something blocks this creature
Nacatl War-Pride: a requirement for every creature that can block Nacatl War-Pride to block it; once one creature blocks it, there's a NEGATIVE requirement for every creature to block it (since this will break one requirement); once two or more creatures block it, there are no more requirements, positive or negative.
I'll think about blocking later, but I think you're right :)

Marek14 wrote:With the predicate requirements, care must be taken to never create them on creatures that are incapable of attacking/blocking since this would throw the math into disarray.
I'm not entirely sure what you mean here...

Marek14 wrote:Also, be careful about this scenario:

Ekundu Cyclops and a random creature can attack. Attack with the random creature itself satisfies no requirements, while attack with Ekundu Cyclops and the creature satisfies one; this is correct. But your algorithm might also determine that not attacking at all, or attacking only with Ekundu Cyclops satisfies no requirements either (since the Ekundu Cyclops requirement is not created in this case).

But Ekundu Cyclops actually creates a requirement in all cases, and because it's a logical implication it's satisfied when either the second term is true or when the first term is false.

This means that you might need the negative requirements even in attacking case:
Ekundu Cyclops: If no creatures are selected, selecting anything but the Ekundu Cyclops has -1 requirement as it breaks the EC's requirement. If at least one creature is selected, selecting Ekundu Cyclops has +1 requirement.
Viashino Bey: If Viashino Bey is not selected, selecting it has -n requirements where n is the total amount of possible remaining attackers. If Viashino Bey is selected, selecting any creature has +1 requirement.
Magnetic Web: If no creature with a magnet counter is selected, selecting one has -n requirements where n is the total amount of possible remaining attackers with magnet counters. If at least one such creature is selected, selecting any other creature with a magnet counter has +1 requirement.
War's Toll: If no creature controlled by a particular player are selected, selecting one has -n requirements where n is the total amount of possible remaining attackers controlled by that player. If at least one such creature is selected, selecting any other creature controlled by that player has +1 requirement.
You're right, I should take more care concerning these cards. I'll have a look at these negative requirements.
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby Marek14 » 22 Oct 2014, 14:24

elcnesh wrote:
Marek14 wrote:With the predicate requirements, care must be taken to never create them on creatures that are incapable of attacking/blocking since this would throw the math into disarray.
I'm not entirely sure what you mean here...
Imagine this scenario: You have a creature and a tapped Ekundu Cyclops which is not capable of attacking. In this case, the requirement on Ekundu Cyclops shouldn't be created no matter what happens otherwise.

You see, for a creature like Juggernaut, this doesn't really matter because even if it always has a requirement, it can be never fulfilled, and a requirement that can't be fulfilled is for all purposes nonexistent. But with Ekundu Cyclops, a wrong implementation could result in requirement being fulfilled when nothing attacks and not fulfilled when the other creature attacks, and so the player would be forced to not attack just for controlling Ekundu Cyclops that is unable to attack.
Since the requirement says "if able", it should be considered automatically fulfilled when Ekundu Cyclops is unable to attack in order to get the same number of requirements for all possible scenarios.

So:
No attackers selected -- Ekundu Cyclops requirement is considered fulfilled.
Some attackers selected, including Ekundu Cyclops -- Ekundu Cyclops requirement is considered fulfilled.
Some attackers selected, not including Ekundu Cyclops, and Ekundu Cyclops is not capable of attacking -- Ekundu Cyclops requirement is considered fulfilled.
Some attackers selected, not including Ekundu Cyclops, and Ekundu Cyclops is capable of attacking -- Ekundu Cyclops requirement is NOT considered fulfilled.

This might seem counter-intuitive, but it's equivalent to selecting not for highest amount of fulfilled requirements but for least amount of BROKEN ones. If you look at it this way, you'll see that the fourth situation is really the only one Ekundu Cyclops is not "happy" with.
Marek14
Tester
 
Posts: 2759
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 296 times

Re: Combat Refactoring

Postby elcnesh » 23 Oct 2014, 08:10

I've got it working!!!! :D

I implemented it in the "new" way, and it works like a charm. I've resolved some of the possible issues mentioned by Marek14 (thanks, most of them were indeed an issue) and changed it to use minimum breaking restriction rather than most fulfilling (IMO the comp rules should be updated in that way also), and it seems to work, at least with the stuff I've tested, including Ekundu Cyclops, Viashino Bey, War's Toll, Scarred Puma, Okk. The only thing that really needs to be done is AI, but I'm a complete noob when it comes to the AI code... Maybe I'll just add a safeguard for now, so that the AI always has a legal way of attacking, and other people can optimise that later.
elcnesh
 
Posts: 290
Joined: 16 May 2014, 15:11
Location: Netherlands
Has thanked: 34 times
Been thanked: 92 times

Re: Combat Refactoring

Postby lujo » 23 Oct 2014, 16:48

Huge salute for this! One important bit - how does this all reflect on banding? Banding is possibly the biggest white ability, and probably the biggest ever non-evasion combat ability there's ever been in the game and having it work or grounds to even develop decent AI for it would be huge for getting older sets to play right?
---

My Shandalar deck pack folder is avaliable here:Dropbox
Leave feedback on particular decks here: Google doc
Ask for instructions, give feedback and complaints here: Thread
User avatar
lujo
 
Posts: 557
Joined: 20 Nov 2013, 13:17
Has thanked: 224 times
Been thanked: 70 times

Next

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 45 guests


Who is online

In total there are 45 users online :: 0 registered, 0 hidden and 45 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 45 guests

Login Form