Skip to content

Commit

Permalink
Merge final with martin_genetic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaung Htet Zaw committed Apr 18, 2015
2 parents c5ba023 + 6efb6b1 commit 78bfc96
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
33 changes: 0 additions & 33 deletions Genetic.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,6 @@ private void selectAndProcreateFittest() {
System.out.println();
}

private void selectAndProcreate() {
Individual[] children = new Individual[individuals.length];
Individual p1, p2;

List<Integer> firstRound = new ArrayList<Integer>();
List<Integer> secondRound = new ArrayList<Integer>();

for (int i = 0; i < individuals.length; i++)
firstRound.add(i);

Collections.shuffle(firstRound);
for (int i = 0; i < firstRound.size(); i+=2) {
if (individuals[firstRound.get(i)].fitness >
individuals[firstRound.get(i+1)].fitness)
secondRound.add(firstRound.get(i));
else
secondRound.add(firstRound.get(i+1));
}

Collections.shuffle(secondRound);

for (int i = 0; i < secondRound.size(); i+=2) {
p1 = individuals[secondRound.get(i)];
p2 = individuals[secondRound.get(i+1)];
children[i] = Individual.procreate(p1, p2);
children[i*2] = Individual.procreate(p1, p2);
children[i].mutate();
children[i*2].mutate();
}

individuals = children;
}

private Individual getBest() {
Individual best = individuals[0];
for (int i = 0; i < individuals.length; i++)
Expand Down
15 changes: 1 addition & 14 deletions PlayerSkeleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static int[][] getLegalMoves(int piece) {
class Weights {
public double numHoles;
public double maxHeight;
public double rowsCleared;
public double colHeights;
public double adjColHeightDiffs;
public double rowTrans;
Expand All @@ -26,12 +25,11 @@ class Weights {
public Weights() {}

public double[] toArray() {
double[] arr = new double[9];
double[] arr = new double[8];
int wi = 0;

arr[wi++] = numHoles;
arr[wi++] = maxHeight;
arr[wi++] = rowsCleared;
arr[wi++] = colHeights;
arr[wi++] = adjColHeightDiffs;
arr[wi++] = rowTrans;
Expand All @@ -47,7 +45,6 @@ public static Weights fromArray(double[] arr) {

w.numHoles = arr[wi++];
w.maxHeight = arr[wi++];
w.rowsCleared = arr[wi++];
w.colHeights = arr[wi++];
w.adjColHeightDiffs = arr[wi++];
w.rowTrans = arr[wi++];
Expand All @@ -61,7 +58,6 @@ public static Weights jacobWeights() {
Weights w = new Weights();
w.numHoles = 5;
w.maxHeight = 1.5;
w.rowsCleared = -2;
w.colHeights = 0.5;
w.adjColHeightDiffs = 1.5;
w.maxWellDepth = 1.5;
Expand All @@ -73,7 +69,6 @@ public static Weights martinWeights() {
Weights w = new Weights(); // [233][-44][232][64][68]
w.numHoles = 233;
w.maxHeight = -44;
w.rowsCleared = 232;
w.colHeights = 64;
w.adjColHeightDiffs = 68;
w.maxWellDepth = 72;
Expand All @@ -85,7 +80,6 @@ public static Weights someWeights() {
Weights w = new Weights(); // [239][-2][116][39][53]
w.numHoles = 2.749176;
w.maxHeight = 1.855434;
w.rowsCleared = -0.047475;
w.colHeights = 0.033812;
w.adjColHeightDiffs = -0.088960;
w.rowTrans = 0.775986;
Expand All @@ -99,7 +93,6 @@ public static Weights randomWeights() {
Weights w = new Weights();
w.numHoles = getRandom();
w.maxHeight = getRandom();
w.rowsCleared = getRandom();
w.colHeights = getRandom();
w.adjColHeightDiffs = getRandom();
w.rowTrans = getRandom();
Expand Down Expand Up @@ -358,15 +351,9 @@ private void removeRow(int row) {
}
}

// heuristic += weights.rowsCleared;
// heuristic -= weights.maxHeight;
// maxHeight--;
// heuristic += weights.rowsCleared;
heuristic -= weights.maxHeight * (maxHeight - newMaxHeight);
maxHeight = newMaxHeight;

// computeMaxWellDepth();
// totalWells();
heuristic += weights.maxWellDepth * computeMaxWellDepth();
}

Expand Down

0 comments on commit 78bfc96

Please sign in to comment.