net.sourceforge.cilib.games.random
Class GameSeedingStrategy

java.lang.Object
  extended by net.sourceforge.cilib.games.random.GameSeedingStrategy
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
FixedSeedStrategy, ListSeedingStrategy, UniqueSeedingStrategy

public abstract class GameSeedingStrategy
extends Object
implements Cloneable

This class is used to generate random numbers for Game's. By making sure the seed is only set once, and at the start of the game, it becomes possible to duplicate games played by fixing the seed.

Author:
leo
See Also:
Serialized Form

Field Summary
protected  long currentSeed
           
protected  Random generator
           
 
Constructor Summary
GameSeedingStrategy()
           
GameSeedingStrategy(GameSeedingStrategy other)
          The copy constructor makes a shallow clone.
 
Method Summary
abstract  GameSeedingStrategy getClone()
          Create a cloned copy of the current object and return it.
 long getCurrentSeed()
           
 Random getGenerator()
           
abstract  void seedGenerator()
          Get a seed value and seed the generator.
 void setGenerator(Random generator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

generator

protected Random generator

currentSeed

protected long currentSeed
Constructor Detail

GameSeedingStrategy

public GameSeedingStrategy()

GameSeedingStrategy

public GameSeedingStrategy(GameSeedingStrategy other)
The copy constructor makes a shallow clone. The copy constructor of the Random class re-seeds the generator and that behavior is unwanted. There should only be one instance of this class per game instance. NOTE: I'm not convinced a thread local singleton should be used here, but it is debateable.

Parameters:
other -
Method Detail

getClone

public abstract GameSeedingStrategy getClone()
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface Cloneable
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

seedGenerator

public abstract void seedGenerator()
Get a seed value and seed the generator.


getGenerator

public Random getGenerator()

setGenerator

public void setGenerator(Random generator)

getCurrentSeed

public long getCurrentSeed()


Copyright © 2009 CIRG. All Rights Reserved.