Created
June 8, 2018 21:41
-
-
Save Andrewcpu/73c25d06653cde6010eac5875f692cd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
public class GeneticPlayer { | |
public static Point startPoint = new Point(0,0); | |
private double fitness = 0; | |
//target fitness = 1 | |
/* | |
Naming convention for network: | |
**-**-** | |
LA-NB-OC | |
A = neural level | |
B = neuron number in level | |
C = sub object | |
*/ | |
private double l1n1; // up | |
private double l1n1o1; //left | |
private double l1n1o2; //right | |
private double l1n1o3; //do nothing | |
private double l1n2; // nothing vertically | |
private double l1n2o1; //left | |
private double l1n2o2; //right | |
private double l1n2o3; //do nothing | |
private double l1n3; // down | |
private double l1n3o1; //left | |
private double l1n3o2; //right | |
private double l1n3o3; //do nothing | |
// begin player information | |
private int x, y; | |
private Point target; | |
public GeneticPlayer(Point target) { | |
this.target = target; | |
x = startPoint.x; | |
y = startPoint.y; | |
} | |
public void merge(GeneticPlayer player){ | |
} | |
public int getX() { | |
return x; | |
} | |
public void setX(int x) { | |
this.x = x; | |
} | |
public int getY() { | |
return y; | |
} | |
public void setY(int y) { | |
this.y = y; | |
} | |
public void tick(){ | |
Vector v = ai(); | |
x+=v.getX(); | |
y+=v.getY(); | |
fitness = Maths.calculateFitness(this); | |
} | |
public Vector ai(){ | |
double max = Maths.findMax(l1n1,l1n2,l1n3); | |
Vector aiValue = new Vector(0,0); | |
if(max == l1n1){// UP is decided | |
aiValue.setY(1); | |
double directionalMax = Maths.findMax(l1n1o1,l1n1o2,l1n1o3); | |
if(directionalMax == l1n1o1){ //left | |
aiValue.setX(-1); | |
} | |
else if(directionalMax == l1n1o2){ //right | |
aiValue.setX(1); | |
} | |
else{ // do nothing | |
aiValue.setX(0); | |
} | |
} | |
else if(max == l1n2){// NOTHING is decided | |
aiValue.setY(0); | |
double directionalMax = Maths.findMax(l1n2o1,l1n2o2,l1n2o3); | |
if(directionalMax == l1n2o1){ //left | |
aiValue.setX(-1); | |
} | |
else if(directionalMax == l1n2o2){ //right | |
aiValue.setX(1); | |
} | |
else{ // do nothing | |
aiValue.setX(0); | |
} | |
} | |
else if(max == l1n3){// DOWN is decided | |
aiValue.setY(-1); | |
double directionalMax = Maths.findMax(l1n3o1,l1n3o2,l1n3o3); | |
if(directionalMax == l1n3o1){ //left | |
aiValue.setX(-1); | |
} | |
else if(directionalMax == l1n3o2){ //right | |
aiValue.setX(1); | |
} | |
else{ // do nothing | |
aiValue.setX(0); | |
} | |
} | |
return aiValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment