sdr 0.7

net.cscott.sdr.calls
Class GeneralFormationMatcher

java.lang.Object
  extended by net.cscott.sdr.calls.GeneralFormationMatcher

public class GeneralFormationMatcher
extends Object

GeneralFormationMatcher produces a FormationMatch given an input Formation and a goal TaggedFormation. This can be used to make Matchers out of TaggedFormations, via the makeMatcher(net.cscott.sdr.calls.TaggedFormation...) method.

Author:
C. Scott Ananian

Method Summary
static FormationMatch doMatch(Formation input, List<TaggedFormation> goals, boolean allowUnmatchedDancers, boolean usePhantoms)
          Allow multiple simultaneous goal formations.
static FormationMatch doMatch(Formation input, TaggedFormation goal, boolean allowUnmatchedDancers, boolean usePhantoms)
          Attempt to match the input formation against the goal formation; you can have multiple rotated copies of the goal formation in the input.
static Matcher makeMatcher(List<TaggedFormation> goals)
           
static Matcher makeMatcher(String name, List<TaggedFormation> goals)
           
static Matcher makeMatcher(TaggedFormation... goals)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeMatcher

public static Matcher makeMatcher(TaggedFormation... goals)

makeMatcher

public static Matcher makeMatcher(List<TaggedFormation> goals)

makeMatcher

public static Matcher makeMatcher(String name,
                                  List<TaggedFormation> goals)

doMatch

public static FormationMatch doMatch(Formation input,
                                     TaggedFormation goal,
                                     boolean allowUnmatchedDancers,
                                     boolean usePhantoms)
                              throws NoMatchException
Attempt to match the input formation against the goal formation; you can have multiple rotated copies of the goal formation in the input. Allow dancers who are not part of copies of the goal formation if allowUnmatchedDancers is true; allow copies of the goal formation with phantoms in them if usePhantoms is true. Returns the best such match (ie, most copies of the goal formation).

Parameters:
input - An untagged formation to match against.
goal - A tagged goal formation
allowUnmatchedDancers - allow dancers in the input formation not to match dancers in (copies of) the goal
usePhantoms - allow dancers in the goal formation not to match dancers in the input
Returns:
the match result
Throws:
NoMatchException - if there is no way to match the goal formation with the given input
Tests:
A successful match with no phantoms or unmatched dancers:
js> FormationList = FormationList.js(this); undefined;
js> GeneralFormationMatcher.doMatch(Formation.SQUARED_SET,
  >                                 FormationList.COUPLE,
  >                                 false, false)
     AAv

BB>       CC<

     DD^
AA:
   3B^  3G^
 [3B: BEAU; 3G: BELLE]
BB:
   4B^  4G^
 [4B: BEAU; 4G: BELLE]
CC:
   2B^  2G^
 [2B: BEAU; 2G: BELLE]
DD:
   1B^  1G^
 [1B: BEAU; 1G: BELLE]
A successful match with some unmatched dancers:
js> FormationList = FormationList.js(this); undefined;
js> GeneralFormationMatcher.doMatch(FormationList.RH_TWIN_DIAMONDS,
  >                                 FormationList.RH_MINIWAVE,
  >                                 true, false)
AA>  BB>

CC^  DDv

EE<  FF<
AA: (unmatched)
   ^
BB: (unmatched)
   ^
CC:
   ^    v
 [ph: BEAU; ph: BEAU]
DD:
   ^    v
 [ph: BEAU; ph: BEAU]
EE: (unmatched)
   ^
FF: (unmatched)
   ^
When possible, symmetry is preserved in the result:
js> FormationList = FormationList.js(this); undefined;
js> GeneralFormationMatcher.doMatch(FormationList.PARALLEL_RH_WAVES,
  >                                 FormationList.RH_MINIWAVE,
  >                                 false, false)
AA^  BBv

CC^  DDv
AA:
   ^    v
 [ph: BEAU; ph: BEAU]
BB:
   ^    v
 [ph: BEAU; ph: BEAU]
CC:
   ^    v
 [ph: BEAU; ph: BEAU]
DD:
   ^    v
 [ph: BEAU; ph: BEAU]

doMatch

public static FormationMatch doMatch(Formation input,
                                     List<TaggedFormation> goals,
                                     boolean allowUnmatchedDancers,
                                     boolean usePhantoms)
                              throws NoMatchException
Allow multiple simultaneous goal formations.

Throws:
NoMatchException
Tests:
A successful match on a Siamese Diamond.
js> importPackage(net.cscott.sdr.util); // for Fraction
js> FormationList = FormationList.js(this); undefined;
js> f = Formation.SQUARED_SET; undefined
js> for each (d in StandardDancer.values()) {
  >   if (d.isHead()) continue;
  >   p = f.location(d).forwardStep(Fraction.valueOf(2), true).
  >                     turn(Fraction.valueOf(1,4), false);
  >   f = f.move(d, p);
  > }; f.toStringDiagram('|');
|3Gv  3Bv
|
|4Bv  2G^
|
|4Gv  2B^
|
|1B^  1G^
js> goals = java.util.Arrays.asList(FormationList.TANDEM,
  >                                 FormationList.COUPLE); undefined
js> GeneralFormationMatcher.doMatch(f, goals, false, false)
  AAv

BBv  CC^

  DD^
AA:
   3B^  3G^
 [3B: BEAU; 3G: BELLE]
BB:
   4G^
   
   4B^
 [4G: LEADER; 4B: TRAILER]
CC:
   2G^
   
   2B^
 [2G: LEADER; 2B: TRAILER]
DD:
   1B^  1G^
 [1B: BEAU; 1G: BELLE]

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian