jleclanche / fireplace

A Hearthstone simulator in Python
https://hearthsim.info
GNU Affero General Public License v3.0
673 stars 150 forks source link

Black Knight allows destruction of any target #8

Closed theintz closed 9 years ago

theintz commented 9 years ago

While it should only be minions that have taunt.

jleclanche commented 9 years ago

The way it works is by using the PlayRequirements of the game files to an advantage so that I don't have to implement targeting at all.

See for yourself:

  <Entity version="2" CardID="EX1_002">
    <MasterPower>9c704757-1b1a-423e-86a3-ec023aa78b81</MasterPower>
    <Tag enumID="185" type="String">The Black Knight</Tag>
    <Tag enumID="321" type="" value="1" />
    <Tag enumID="183" type="" value="3" />
    <Tag enumID="203" type="" value="5" />
    <Tag enumID="202" type="" value="4" />
    <Tag enumID="48" type="" value="6" />
    <Tag enumID="47" type="" value="4" />
    <Tag enumID="45" type="" value="5" />
    <Tag enumID="184" type="String">&lt;b&gt;Battlecry:&lt;/b&gt; Destroy an enemy minion with &lt;b&gt;Taunt&lt;/b&gt;.</Tag>
    ...
    <ReferencedTag name="Taunt" enumID="190" type="Bool" value="1" />
    <Power definition="9c704757-1b1a-423e-86a3-ec023aa78b81">
      <PlayRequirement reqID="22" param="" />
      <PlayRequirement reqID="1" param="" />
      <PlayRequirement reqID="46" param="" />
      <PlayRequirement reqID="3" param="" />
    </Power>
</Entity>

If you look at the PlayReqs, 1 is REQ_MINION_TARGET, 3 is REQ_ENEMY_TARGET, 22 is REQ_TARGET_IF_AVAILABLE and 46 is REQ_MUST_TARGET_TAUNTER.

So fireplace immediately knows that TBK's action can only target enemy minions with taunt and must target them if one is on the field.

theintz commented 9 years ago

Very cool. Well done.

jleclanche commented 9 years ago

I'll try to document it on the wiki. PlayReqs are a very cool system indeed and they save me a lot of time. See targeting.py for the targeting part of the implementation.