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 genes
    static void initPopulation()
    Creates the initial population of genomes, each with random genes
    static void loadState​(Gbot.State s)
    Loads a state
    static void makePlay​(boolean play)
    Makes next move based on the genome
    static void Play()
    Plays the game by making the next move (makePlay)
    static int[] tournamentSelection​(int tSize)
    Performs the tournament selection for selection of parents
    static void train()
    Trains the neural network
    static void updateTop10()
    Updates the saved top 10 individuals

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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

      public static void loadState​(Gbot.State s)
      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