org.vizzini.example.tictactoe
Class TicTacToeGeneticAlgorithmGP

java.lang.Object
  extended by org.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm
      extended by org.vizzini.ai.geneticprogramming.AbstractGeneticAlgorithmGP
          extended by org.vizzini.example.tictactoe.TicTacToeGeneticAlgorithmGP
All Implemented Interfaces:
IGeneticAlgorithm, IGeneticAlgorithmGP

public class TicTacToeGeneticAlgorithmGP
extends AbstractGeneticAlgorithmGP

Provides a genetic programming algorithm to create agents for a tic-tac-toe game.

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Field Summary
 
Fields inherited from class org.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm
_crossoverFraction, _crossoverType, _elapsedTime, _generation
 
Constructor Summary
TicTacToeGeneticAlgorithmGP(boolean isBoardPrinted)
          Construct this object.
 
Method Summary
protected  void configureAgent(IComputerAgent agent, IChromosomeGP chromosome)
          Configure the given agent for play.
protected  IComputerAgent createAgent0()
          Create agent 0.
protected  IComputerAgent createAgent1()
          Create agent 1.
protected  IGame createGame()
          Create the game.
protected  void evaluateFitness()
          Evaluate the fitnesses of the chromosomes in the population.
protected  int evaluateFitness(int index, IChromosomeGP chromosome, boolean isPrinting)
          Evaluate the fitness of the given chromosome for this problem.
protected  int getCoverage(IFunction function)
          Return a count of the number of positions on the grid board which are referenced by the given function.
protected  IGame getGame()
           
protected  String getGamePropertiesPath()
          Return the game properties path.
 int getMinTrialCount()
           
protected  Class getReturnType()
          Return the overall return type for the chromosomes.
 boolean isVerbose()
           
static void main(String[] args)
          Application method.
protected  void rewardAndPunish(IChromosome chromosome0, IChromosome chromosome1)
          Reward and punish the given chromosomes.
protected  void setAgent0(IComputerAgent agent)
          Set the first agent.
protected  void setAgent1(IComputerAgent agent)
          Set the second agent.
protected  void setGame(IGame game)
          Set the game.
 void setMinTrialCount(int minTrialCount)
           
 void setVerbose(boolean isVerbose)
           
 void writeReport()
          Write a report.
protected  void writeStats(Writer writer, int localGens)
          Write statistics using the given parameters.
protected  void writeStatsHeader(Writer writer)
          Write a header for the statistics.
 
Methods inherited from class org.vizzini.ai.geneticprogramming.AbstractGeneticAlgorithmGP
addFunction, addTerminal, createChromosome, getContext, getFunctionCount, getFunctionGenerator, getInitialMaxDepth, getTerminalCount, isSimpleBetter, onePointCrossover, penalizeComplexity, setContext, setInitialMaxDepth, setSimpleBetter
 
Methods inherited from class org.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm
averageCrossover, fillPopulation, generateNewPopulation, getAverageCrossoverFraction, getCrossoverFraction, getCrossoverType, getElapsedTime, getGeneration, getMostFit, getMutationFraction, getMutationMagnitude, getMutationRate, getPerfectFitness, getPopulation, getPopulationSize, getProcessingRate, isDuplicateAllowed, mutation, reproductionAndCrossover, reset, runGenerations, setAverageCrossoverFraction, setCrossoverFraction, setCrossoverType, setDuplicateAllowed, setMutationFraction, setMutationMagnitude, setMutationRate, setPopulation, setPopulationSize, sortPopulation, toString, uniformCrossover
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.vizzini.ai.geneticalgorithm.IGeneticAlgorithm
getCrossoverFraction, getCrossoverType, getElapsedTime, getGeneration, getMostFit, getMutationFraction, getMutationMagnitude, getMutationRate, getPopulationSize, getProcessingRate, reset, runGenerations, setAverageCrossoverFraction, setCrossoverFraction, setCrossoverType, setDuplicateAllowed, setMutationFraction, setMutationMagnitude, setMutationRate, setPopulationSize
 

Constructor Detail

TicTacToeGeneticAlgorithmGP

public TicTacToeGeneticAlgorithmGP(boolean isBoardPrinted)
                            throws IOException,
                                   InstantiationException,
                                   IllegalAccessException
Construct this object.

Throws:
IOException
InstantiationException
IllegalAccessException
Method Detail

main

public static void main(String[] args)
                 throws Exception
Application method.

Parameters:
args - 0-population size (optional)
1-number of generations to run (optional)
2-print frequency (optional)
Throws:
Exception
Since:
v0.3

getMinTrialCount

public int getMinTrialCount()
Returns:
Return minTrialCount.
Since:
v0.3

isVerbose

public boolean isVerbose()
Returns:
Return isVerbose.
Since:
v0.3

setMinTrialCount

public void setMinTrialCount(int minTrialCount)
Parameters:
minTrialCount - the minTrialCount to set
Since:
v0.3

setVerbose

public void setVerbose(boolean isVerbose)
Parameters:
isVerbose - the isVerbose to set
Since:
v0.3

writeReport

public void writeReport()
Write a report.

Specified by:
writeReport in interface IGeneticAlgorithm
Overrides:
writeReport in class AbstractGeneticAlgorithm
Since:
v0.3

configureAgent

protected void configureAgent(IComputerAgent agent,
                              IChromosomeGP chromosome)
Configure the given agent for play.

Since:
v0.3

createAgent0

protected IComputerAgent createAgent0()
Create agent 0.

Since:
v0.3

createAgent1

protected IComputerAgent createAgent1()
Create agent 1.

Since:
v0.3

createGame

protected IGame createGame()
                    throws InstantiationException,
                           IllegalAccessException
Create the game.

Throws:
InstantiationException
IllegalAccessException
Since:
v0.3

evaluateFitness

protected void evaluateFitness()
Evaluate the fitnesses of the chromosomes in the population.

Overrides:
evaluateFitness in class AbstractGeneticAlgorithmGP
Since:
v0.3

evaluateFitness

protected int evaluateFitness(int index,
                              IChromosomeGP chromosome,
                              boolean isPrinting)
Evaluate the fitness of the given chromosome for this problem.

Specified by:
evaluateFitness in class AbstractGeneticAlgorithmGP
Parameters:
index - Index of the chromosome in the population.
chromosome - Chromosome.
isPrinting - Flag indicating if the method should print.
Since:
v0.3

getCoverage

protected int getCoverage(IFunction function)
Return a count of the number of positions on the grid board which are referenced by the given function.

Parameters:
function - Function.
Since:
v0.3

getGame

protected IGame getGame()
Returns:
Return game.
Since:
v0.3

getGamePropertiesPath

protected String getGamePropertiesPath()
Return the game properties path.

Since:
v0.3

getReturnType

protected Class getReturnType()
Return the overall return type for the chromosomes.

Specified by:
getReturnType in class AbstractGeneticAlgorithmGP
Since:
v0.3

rewardAndPunish

protected void rewardAndPunish(IChromosome chromosome0,
                               IChromosome chromosome1)
Reward and punish the given chromosomes.

Since:
v0.3

setAgent0

protected void setAgent0(IComputerAgent agent)
Set the first agent.

Since:
v0.3

setAgent1

protected void setAgent1(IComputerAgent agent)
Set the second agent.

Since:
v0.3

setGame

protected void setGame(IGame game)
Set the game.

Since:
v0.3

writeStats

protected void writeStats(Writer writer,
                          int localGens)
Write statistics using the given parameters.

Overrides:
writeStats in class AbstractGeneticAlgorithm
Parameters:
writer - Writer.
localGens - Current generation.
Since:
v0.3

writeStatsHeader

protected void writeStatsHeader(Writer writer)
Write a header for the statistics.

Overrides:
writeStatsHeader in class AbstractGeneticAlgorithm
Parameters:
writer - Writer.
Since:
v0.3


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02