Skip to content

Commit

Permalink
Fixed a loophole in the locus calculations whereby agents would gain …
Browse files Browse the repository at this point in the history
…big bonuses by stacking wildcards in excess of their target's tag length. Wildcards now always receive the proper weight regardless of their position in a tag.
  • Loading branch information
andrewanderson committed Sep 18, 2010
1 parent ab47e74 commit 5058e9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Cas/Core/Interactions/LocusInteractionBase.cs
Expand Up @@ -16,7 +16,7 @@ public enum InteractionLocusIndecies
Match = 0,
Mismatch = 1,
Wildcard = 2,
Extra = 3
Extra = 3,
}

/// <summary>
Expand All @@ -42,13 +42,21 @@ protected int CalculateInteractionResult(Tag actorTag, Tag targetTag)

for (int actorIndex = 0; actorIndex < actorTag.Data.Count; actorIndex++)
{
Resource actorData = actorTag.Data[actorIndex];

if (actorIndex >= targetTag.Data.Count)
{
result += InteractionLocus[(int)InteractionLocusIndecies.Extra];
if (actorData.Equals(Resource.WildcardResource))
{
result += InteractionLocus[(int)InteractionLocusIndecies.Wildcard];
}
else
{
result += InteractionLocus[(int)InteractionLocusIndecies.Extra];
}
continue;
}

Resource actorData = actorTag.Data[actorIndex];
Resource targetData = targetTag.Data[actorIndex];

if (actorData.Equals(Resource.WildcardResource) && targetData.Equals(Resource.WildcardResource))
Expand Down
8 changes: 8 additions & 0 deletions Cas/TestCore/Interactions/LocusInteractionBaseTest.cs
Expand Up @@ -97,6 +97,14 @@ public void Interact_LongerAttacker()
Assert.AreEqual(MatchValue * 1 + ExtraValue * 1, result);
}

[TestMethod]
public void Interact_LongerAttackerWithWildcards()
{
int result = Interaction.Interact(Tag.New("aa##"), Tag.New("a"));

Assert.AreEqual(MatchValue * 1 + ExtraValue * 1 + WildcardValue * 2, result);
}

[TestMethod]
public void Interact_LongerTarget()
{
Expand Down

0 comments on commit 5058e9a

Please sign in to comment.