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 class
Gbot.State
-
Field Summary
Fields Modifier and Type Field Description static int[]
bestMoveNext
static int
games
-
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 void
geneSort(double[][] gen)
Sorts the array of genesstatic void
initPopulation()
Creates the initial population of genomes, each with random genesstatic void
loadState(Gbot.State s)
Loads a statestatic void
makePlay(boolean play)
Makes next move based on the genomestatic void
Play()
Plays the game by making the next move (makePlay)static int[]
tournamentSelection(int tSize)
Performs the tournament selection for selection of parentsstatic void
train()
Trains the neural networkstatic void
updateTop10()
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
-