"Dancer" Program.



Version "Tina10" Jan 9, 2002
Paul Johnson <pauljohn@ku.edu> and Tina Wu <GwoingYu@ChevronTexaco.com>

For: Swarm-2.1.140

This program takes the GraphLib-1.2 and DynamicGraph models as the
starting point. To avoid trouble building GraphLib on various systems,
it has been incorporated into this program, so no separate Graph Lib
is needed.  Some customization of DiGraph and DiGraphNode was needed
to make this work the way we wanted.

This model creates "Dancer" objects and represents them as nodes in a
canvas. In the ModelSwarm's buildObjects method, the starting
positions of the agents are set.  The step method in the Dancer class
controls the movement after the start.

In this exercise, we are considering 10 possible dance moves.  Some
take longer than others, and the model is designed to make this an
explicit part of the simulation.  

Possible Dance Steps:

Number	StepName		TimeStepsRequired	
0. 	Stand 			1
1.	Run 			3
2. 	Roll forward		12
3. 	Pas de Bourree 		3
4. 	Soutenu Turn		6	
5. 	Balance			6
6. 	Grand Jete 		3	
7. 	Par de chat 		3	
8. 	Swing leg side 		1
9. 	Roll side way 		3

For each dance step, there can be movement of a certain distance and
direction.  Furthermore, when each dance step, is completed, then the
dancer can make a transition into another dance step.  For the steps
listed above, we have movements of various types.  For example, for
dance step 0, the distance moved is 0 and there is only one possible
direction. However, from a standing position, the dancer can go into
many other dance steps. Here is a table that describes the logic completely:


Step	Dist	NumberOfDirections	NextStepMayBe	
0.	0		1		0,1,2,3,4,5,6,7
1.	1		8		0,1,2,3,4,5,6,7
2.	1		1		0,8,9
3.	0		8		0,1,2,3,4,6
4.	1		2		0,1,2,3,4,5,7
5.	0		1		0,1,2,3,4,5,7
6.	1		8		0,1,2,3,4,5,6,7
7.	1		2		0,1,2,3,4,5,7
8.	0		2		0,1,2,3,4,5,6,7,8,9
9.	1		2		0,1,2,3,4,5,6,7,8,9

Furthermore, we allow the possibility that a particular step can be
repeated.  That means when a dancer embarks on a "run" of 5 units 
duration, she does not stop until the 5 units of time have passed.
In essence, that means that the time steps required to complete a 
sequence of moves is the time required for one completion times 
the number of repetitions.  Until the dancer completes that sequence,
she cannot decide to make a different step.

Now, directions!  0 is facing front, "down", 4 is backwards.


                   4

           5              3
                   ^
                   |
      6      <- Current ->       2
                   |
                   v
           7             1

                  0


The dance floor is supposed to allow dancers to move 10 spaces
sideways and 8 spaces front and back. They can exit the stage only on
left or right.  The coordinates are set so that "on stage" coordinates
range from [1,1] (top left) to [10,8] (bottom right). The dancers,
when they are "off", sit on the left and right edges of the stage. The
display is scaled so that the dancers that are "off" are half-way
visible. It takes only one step to bring them fully on stage.
Offstage os left is position 0, and Offstage on right is at position
11.

As shown on the Canvas on the Screen, the coordinates lay out
like so:

|----------------------------------------------------------|
|0,1      | 1 ,1                                 1,8|  11,1|
|         |	                                    |      |
|off      |	                                    | off  |
|stage    |	                                    | stage|
|         |	              On Stage              |      |
|         |	                                    |      |
|         |	                                    |      |
|         |	                                    |      |
|0,8      |     1,8		                10,8|  11,8|
|----------------------------------------------------------


The initial positions of the dancers are designated as:

4, 5
5, 4
6, 3
7, 2
2, 2

The step method is called whenever it is time for a dancer to choose
the next step.  First, the dancer runs the "chooseNextStep" method to
decide on a step between 0 and 9. Then the dancer chooses a direction
with the "chooseNextDirection" method (from the appropriate range, of
course) and a number of times the step is to be repeated with the
chooseNextReps method. Those decisions are fed into other methods that
calculate the intended location where the dancer will go and make sure
that the dancer does not try to land on a space than another dancer
has "claimed" it is going to.

The details of how dancers move are written down in the method
planStep: Dir: Rep: that gives calculations that
figure out the dancer's intended position. The arguments are 3
integers, such as (1,1,4).  The action specifies a step number (1),
and inside the method the precise meaning of that dance step is
defined. It specifies how many squares to move and how long it takes
to get there. Until that dance move is finished, the dancer is not
called on to do anything else.  The second argument gives direction,
which so far is just left or right, but it could be 8 directional if
you want. The final argument is for the number of repetitions.
Suppose you want to tell a dancer to do 4 pirouettes in a particular
direction. The last argument to step:Dir:Rep tells how many
repetitions to do.  This allows us to tell a dancer to run for 10
timesteps in a particular direction, for example.

As it stands now, the agents decide how to move according to given
rules.  However, this program may also be used as a choreography tool.
As the model runs, the GUI shows agents.  When the model is paused, a
right click on an agent will expose a panel where the choreographyer
can tell the dancer to make an indicated step.  After that, when the
model is resumed, the other dancers that have not stepped yet will
move and the simulation can continue.

I don't yet have the ability to load a dance "back in" to the
simulation, but I have done work like that on other projects and it
would not be too terribly hard.  The "vision" is that the choreography
can be specified as a vector of positions and steps, one set for each
time step.

