Package Phase2
Class Gbot
java.lang.Object
Phase2.Gbot
public class Gbot
extends java.lang.Object
Class containing implementation of the Genetic Algorithm-based bot.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classGbot.State -
Field Summary
Fields Modifier and Type Field Description static int[]bestMoveNextstatic intgames -
Constructor Summary
Constructors Constructor Description Gbot() -
Method Summary
Modifier and Type Method Description static double[]arrayCopy(double[] old)static int[]arrayCopy(int[] old)static java.lang.Integer[]arrayCopy(java.lang.Integer[] old)static int[][]copyField(int[][] f0)static voidgeneSort(double[][] gen)Sorts the array of genesstatic voidinitPopulation()Creates the initial population of genomes, each with random genesstatic voidloadState(Gbot.State s)Loads a statestatic voidmakePlay(boolean play)Makes next move based on the genomestatic voidPlay()Plays the game by making the next move (makePlay)static int[]tournamentSelection(int tSize)Performs the tournament selection for selection of parentsstatic voidtrain()Trains the neural networkstatic voidupdateTop10()Updates the saved top 10 individuals
-
Field Details
-
games
public static int games -
bestMoveNext
public static int[] bestMoveNext
-
-
Constructor Details
-
Gbot
public Gbot()
-
-
Method Details
-
copyField
public static int[][] copyField(int[][] f0) -
arrayCopy
public static java.lang.Integer[] arrayCopy(java.lang.Integer[] old) -
arrayCopy
public static int[] arrayCopy(int[] old) -
arrayCopy
public static double[] arrayCopy(double[] old) -
initPopulation
public static void initPopulation()Creates the initial population of genomes, each with random genes -
Play
public static void Play()Plays the game by making the next move (makePlay) -
train
public static void train()Trains the neural network -
updateTop10
public static void updateTop10()Updates the saved top 10 individuals -
tournamentSelection
public static int[] tournamentSelection(int tSize)Performs the tournament selection for selection of parents- Parameters:
tSize- : size of population to undergo the selection- Returns:
- best parents from the tournament selection
-
loadState
Loads a state- Parameters:
s- : state to be loaded
-
makePlay
public static void makePlay(boolean play)Makes next move based on the genome- Parameters:
play- : true if supposed to make next move, false otherwise
-
geneSort
public static void geneSort(double[][] gen)Sorts the array of genes- Parameters:
gen- : sorted array of genes
-