sdr 0.7

net.cscott.sdr.calls
Class Evaluator

java.lang.Object
  extended by net.cscott.sdr.calls.Evaluator
Direct Known Subclasses:
A1List.SolidEvaluator, BasicList.LRMEvaluator, C1List.ConcentricEvaluator, Evaluator.EvaluatorChain, Evaluator.Standard

public abstract class Evaluator
extends Object

An Evaluator represents a current dance context. Evaluators are usually stacked: the standard evaluator might call down into a child evaluator for the "tandem" concept, for example, which will then reinvoke the standard evaluator to evaluate "trade". Evaluators keep a continuation context, since each call to evaluate(net.cscott.sdr.calls.DanceState) does only "one part" of a call — the remaining parts go in the continuation.

As the Evaluators operate, they accumulate dancer movements and actions in a DanceState.

Author:
C. Scott Ananian
Tests:
Simplest invocation: "heads start" from squared set.
js> importPackage(net.cscott.sdr.calls.ast);
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> ds.currentFormation().toStringDiagram("|");
|     3Gv  3Bv
|
|4B>            2G<
|
|4G>            2B<
|
|     1B^  1G^
js> comp = AstNode.valueOf("(Seq (Apply (Expr _square start 'HEAD)))");
(Seq (Apply (Expr _square start 'HEAD)))
js> e = new Evaluator.Standard(comp); undefined
js> e.evaluateAll(ds);
js> Breather.breathe(ds.currentFormation()).toStringDiagram("|");
|4B>  3Gv  3Bv  2G<
|
|4G>  1B^  1G^  2B<
"Heads pair off" from squared set.
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.SQUARED_SET); undefined;
js> ds.currentFormation().toStringDiagram("|");
|     3Gv  3Bv
|
|4B>            2G<
|
|4G>            2B<
|
|     1B^  1G^
js> comp = CallDB.INSTANCE.parse(ds.dance.program, "heads pair off");
(Apply (Expr anyone while others 'HEAD 'pair off 'nothing))
js> comp = new net.cscott.sdr.calls.ast.Seq(comp);
(Seq (Apply (Expr anyone while others 'HEAD 'pair off 'nothing)))
js> e = new Evaluator.Standard(comp); undefined
js> e.evaluateAll(ds);
js> Breather.breathe(ds.currentFormation()).toStringDiagram("|");
|4B>  3G<  3B>  2G<
|
|4G>  1B<  1G>  2B<
More complex calls from facing couples.
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.FOUR_SQUARE); undefined;
js> ds.currentFormation().toStringDiagram("|");
|3Gv  3Bv
|
|1B^  1G^
js> Evaluator.parseAndEval(ds, "boys walk girls dodge");
js> ds.currentFormation().toStringDiagram("|");
|1B^  3Gv
|
|1G^  3Bv
js> Evaluator.parseAndEval(ds, "girls walk others dodge");
js> ds.currentFormation().toStringDiagram("|");
|1G^  1B^
|
|3Bv  3Gv
js> Evaluator.parseAndEval(ds, "trade", "roll");
js> ds.currentFormation().toStringDiagram("|");
|1B>  1G<
|
|3G>  3B<
Recursive evaluation with fractionalization, left concept, breathing, etc:
js> ds = new DanceState(new DanceProgram(Program.C4), Formation.FOUR_SQUARE); undefined;
js> ds.currentFormation().toStringDiagram("|");
|3Gv  3Bv
|
|1B^  1G^
js> Evaluator.parseAndEval(ds, "square thru three and a half");
js> ds.currentFormation().toStringDiagram("|");
|3G<
|
|3B>
|
|1B<
|
|1G>
Matching waves; fan the top; even timing:
js> ds = new DanceState(new DanceProgram(Program.A1), Formation.SQUARED_SET); undefined;
js> Evaluator.parseAndEval(ds, "heads pair off; do half of a pass thru");
js> ds = ds.cloneAndClear(); undefined
js> ds.currentFormation().toStringDiagram("|");
|4B>  3B>
|
|3G<  2G<
|
|4G>  1G>
|
|1B<  2B<
js> Evaluator.parseAndEval(ds, "fan the top")
js> ds.currentFormation().toStringDiagram("|");
|1B^  4Gv  3G^  4Bv  2B^  1Gv  2G^  3Bv
js> ds.movements(StandardDancer.COUPLE_1_BOY)
[DancerPath[from=-1,-3,w,to=-6,-4,nw,[ROLL_RIGHT, SWEEP_LEFT],time=2,pointOfRotation=FOUR_DANCERS], DancerPath[from=-6,-4,nw,[ROLL_RIGHT, SWEEP_LEFT],to=-7,0,n,[ROLL_RIGHT, SWEEP_LEFT],time=2,pointOfRotation=FOUR_DANCERS]]
js> ds.movements(StandardDancer.COUPLE_4_GIRL)
[DancerPath[from=-1,-1,e,to=-1,0,n,[ROLL_LEFT, SWEEP_RIGHT],time=1 1/3,pointOfRotation=FOUR_DANCERS], DancerPath[from=-1,0,n,[ROLL_LEFT, SWEEP_RIGHT],to=-2,0,nw,[ROLL_LEFT, SWEEP_RIGHT],time=2/3,pointOfRotation=FOUR_DANCERS], DancerPath[from=-2,0,nw,[ROLL_LEFT, SWEEP_RIGHT],to=-3,1,w,[ROLL_LEFT, SWEEP_RIGHT],time=2/3,pointOfRotation=FOUR_DANCERS], DancerPath[from=-3,1,w,[ROLL_LEFT, SWEEP_RIGHT],to=-5,0,s,[ROLL_LEFT, SWEEP_RIGHT],time=1 1/3,pointOfRotation=FOUR_DANCERS]]
Four-person "pass thru":
js> ds = new DanceState(new DanceProgram(Program.BASIC), Formation.FOUR_SQUARE); undefined;
js> Evaluator.parseAndEval(ds, "pass thru")
js> ds.currentFormation().toStringDiagram("|");
|1B^  1G^
|
|3Gv  3Bv
js> ds.movements(StandardDancer.COUPLE_1_BOY)
[DancerPath[from=-1,-1,n,to=-3,0,n,time=1,pointOfRotation=<null>], DancerPath[from=-3,0,n,to=-1,1,n,time=1,pointOfRotation=<null>]]
js> ds.movements(StandardDancer.COUPLE_3_GIRL)
[DancerPath[from=-1,1,s,to=-1,0,s,time=1,pointOfRotation=<null>], DancerPath[from=-1,0,s,to=-1,-1,s,time=1,pointOfRotation=<null>]]

Nested Class Summary
static class Evaluator.EvaluatorChain
          Chains multiple evaluators together.
static class Evaluator.Standard
          This is the standard top level evaluator.
 
Constructor Summary
Evaluator()
           
 
Method Summary
static Evaluator breathedEval(Formation f, Comp c)
          Create an evaluator which breathes each formation to resolve collisions.
abstract  Evaluator evaluate(DanceState ds)
          Do "one part" of the continuation, and return an Evaluator which will do the remaining parts, or null if there are no additional parts to evaluate.
 void evaluateAll(DanceState ds)
           
 boolean hasSimpleExpansion()
          Return true iff this Evaluator simply evaluates an Ast tree.
static void parseAndEval(DanceState ds, String... calls)
          Convenience method for easy testing.
 Comp simpleExpansion()
          Returns the equivalent simple expansion of the call, if it has one.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Evaluator

public Evaluator()
Method Detail

evaluate

public abstract Evaluator evaluate(DanceState ds)
Do "one part" of the continuation, and return an Evaluator which will do the remaining parts, or null if there are no additional parts to evaluate.

Parameters:
ds - The dynamic dance state. Accumulates dancer actions and movements and tracks static dance information like the level of the dance.
Returns:
An Evaluator for the remaining parts, or null.

hasSimpleExpansion

public boolean hasSimpleExpansion()
Return true iff this Evaluator simply evaluates an Ast tree. That is, if we can "look inside" the definition of this call or concept by treating it as equivalent to its expansion.


simpleExpansion

public Comp simpleExpansion()
Returns the equivalent simple expansion of the call, if it has one.

Throws:
IllegalArgumentException - if hasSimpleExpansion() is false.

toString

public String toString()
Overrides:
toString in class Object

evaluateAll

public final void evaluateAll(DanceState ds)

parseAndEval

public static void parseAndEval(DanceState ds,
                                String... calls)
Convenience method for easy testing.


breathedEval

public static Evaluator breathedEval(Formation f,
                                     Comp c)
Create an evaluator which breathes each formation to resolve collisions. Good to use as a top-level evaluator, but note that phantom concepts will have to return all the phantoms up to this step in order for them not to be breathed away.


sdr 0.7

Copyright © 2006-2009 C. Scott Ananian