Package Phase3

Class Gbot

java.lang.Object
Phase3.Gbot

public class Gbot
extends java.lang.Object
Genetic algorithm bot (Gbot) similar to the one from Phase2 but adapted to solving 3D problems
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int[][][][][] aShape  
    static int[] aShapeVal  
    static int boardScore  
    static boolean con  
    static int contX  
    static int contY  
    static int contZ  
    static int curHeight  
    static double[] gen1  
    static boolean general  
    static int[] lastCoord  
    static int[][][] lastSolid  
    static int[] leftToPlace  
    static int maxScore  
    static int[][][][][] parcels
    Array storing all parcels alongside all of their rotations
    static int[][][][][] pentominoes
    Array storing all pentominoes alongside all of their rotations
    static int[] placed  
    static boolean slow  
  • Constructor Summary

    Constructors 
    Constructor Description
    Gbot()  
  • Method Summary

    Modifier and Type Method Description
    static void addSolid​(int[][][] solid, int[] coord, int color, int[][][] field)
    Method adding a solid to the container (field) at the specified coordinates
    static double[] arrayCopy​(double[] old)  
    static int[] arrayCopy​(int[] old)  
    static java.lang.Integer[] arrayCopy​(java.lang.Integer[] old)  
    static void assignValue​(int solidIndex, int value)  
    static boolean checkCollision​(int[][][] solid, int[] coord)
    Method checking if a collusion occurs when attempting to add a solid at coordinates
    static int[][][] copyField​(int[][][] f0)  
    static boolean dropPiece​(int[][][] solid, int[] coord, int color, boolean tentative)  
    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 makePlay​(boolean play)
    Makes next move based on the genome
    static void Play()
    Plays the game by making the next move (makePlay)
    static boolean removeLastSolid​(int[][][] field)  
    static void setup()  
    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

    • curHeight

      public static int curHeight
    • contX

      public static int contX
    • contY

      public static int contY
    • contZ

      public static int contZ
    • lastSolid

      public static int[][][] lastSolid
    • lastCoord

      public static int[] lastCoord
    • maxScore

      public static int maxScore
    • boardScore

      public static int boardScore
    • con

      public static boolean con
    • general

      public static boolean general
    • leftToPlace

      public static int[] leftToPlace
    • placed

      public static int[] placed
    • slow

      public static boolean slow
    • gen1

      public static double[] gen1
    • pentominoes

      public static int[][][][][] pentominoes
      Array storing all pentominoes alongside all of their rotations
    • parcels

      public static int[][][][][] parcels
      Array storing all parcels alongside all of their rotations
    • aShapeVal

      public static int[] aShapeVal
    • aShape

      public static int[][][][][] aShape
  • Constructor Details

    • Gbot

      public Gbot()
  • Method Details

    • assignValue

      public static void assignValue​(int solidIndex, int value)
    • removeLastSolid

      public static boolean removeLastSolid​(int[][][] field)
    • addSolid

      public static void addSolid​(int[][][] solid, int[] coord, int color, int[][][] field)
      Method adding a solid to the container (field) at the specified coordinates
      Parameters:
      solid - : solid to be added
      coord - : coordinates to add the solid at
      color - : color of the parcel that is being added
      field - : field (container) that the object is being added to
    • checkCollision

      public static boolean checkCollision​(int[][][] solid, int[] coord)
      Method checking if a collusion occurs when attempting to add a solid at coordinates
      Parameters:
      solid - : Solid to be added
      coord - : coordinates to add the solid at
      Returns:
      true if a collision occurs, false otherwise
    • dropPiece

      public static boolean dropPiece​(int[][][] solid, int[] coord, int color, boolean tentative)
    • 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
    • setup

      public static void setup()
    • 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
    • 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