/*----------------------------------------------------------------------+
|      Title:	Range.java                                              |
|                                                                       |
|      Author:	David E. Joyce                                          |
|           Department of Mathematics and Computer Science              |
|           Clark University                                            |
|           Worcester, MA 01610-1477                                    |
|           U.S.A.                                                      |
|                                                                       |
|           http://aleph0.clarku.edu/~djoyce/                           |
|           djoyce@clarku.edu                                           |
|                                                                       |
|      Date:    May, 2002.                                              |
+----------------------------------------------------------------------*/

import java.awt.*;

public class Range {
  private int population;
  private Strategy oldmaxS, maxS;
  private Herd herd;

  public Range (int populationIn) {
    population = populationIn;
    herd = new Herd(population);
    oldmaxS = null;
  }

  public boolean doSimulation(int deaths, int lengthOfMatch, int payoff[][]) {
    herd.runMatch(lengthOfMatch, payoff);
    // First, remove some players due to death, randomly
    herd.death(deaths);
    // Next, select new ones to replace the dead
    herd.birth();
    return oldmaxS.pop == population; // return true if only one strategy
  } // doSimulation


  public void updateData (TimeGraph timeGraph, TextArea reportArea) {
    timeGraph.newData(herd.getStrategyData());
    maxS = herd.getMaxStrategy();
    if (oldmaxS == null || maxS.strategyNumber != oldmaxS.strategyNumber) {
      reportArea.append(maxS+"\n");
      oldmaxS = maxS;
    }
  } // updateData

} // Battle.java

