Commit 8cd7c3cf authored by Fabian Jakob Sauer's avatar Fabian Jakob Sauer
Browse files

Fixed bug in logic for potential next move after two already played moves.

parent cc76adc8
...@@ -11,16 +11,17 @@ import java.util.Random; ...@@ -11,16 +11,17 @@ import java.util.Random;
public class MainClass { public class MainClass {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
OptimizeWeights optimizer = new OptimizeWeights(); //OptimizeWeights optimizer = new OptimizeWeights();
optimizer.Compute(); //optimizer.Compute();
RunSimulation();
} }
public void RunSimulation() public static void RunSimulation()
{ {
// USER INPUT // USER INPUT
int numGames = 5000; int numGames = 1;
Player p1 = new BasicPlayer(); Player p1 = new OptimizeTurnPlayerDefault();
Player p2 = new OptimizeTurnPlayer(false); Player p2 = new OptimizeTurnPlayer(false);
Statistics stats = new Statistics(p1, p2); Statistics stats = new Statistics(p1, p2);
...@@ -59,6 +60,7 @@ public class MainClass { ...@@ -59,6 +60,7 @@ public class MainClass {
Player winner = game.simulate(); // run games simulation Player winner = game.simulate(); // run games simulation
//game.getHistory().printHistory(); //game.getHistory().printHistory();
stats.TrackGame(winner, game.getHistory()); stats.TrackGame(winner, game.getHistory());
System.out.println(p1.getName() + ": " + ((OptimizeTurnPlayerDefault)p1).GetCntTurns() + " | " +p2.getName() + ": " +((OptimizeTurnPlayer)p2).GetCntTurns());
} }
stats.PrintStats(); stats.PrintStats();
......
...@@ -31,11 +31,12 @@ public class OptimizeTurnPlayer implements Player { ...@@ -31,11 +31,12 @@ public class OptimizeTurnPlayer implements Player {
private LoggingSystem logger; private LoggingSystem logger;
private int countTurn = 0; private int countTurn = 0;
private Random random; private Random random;
private int badPlacementTheshold = 20; private int badPlacementTheshold = 0;
private float lastGameValue; private float lastGameValue;
private GameValue gameValue; private GameValue gameValue;
private CardTracker cardTracker; private CardTracker cardTracker;
private GameState latestGameState; private GameState latestGameState;
private int numMoves = 0;
public OptimizeTurnPlayer() public OptimizeTurnPlayer()
{ {
...@@ -63,6 +64,7 @@ public class OptimizeTurnPlayer implements Player { ...@@ -63,6 +64,7 @@ public class OptimizeTurnPlayer implements Player {
@Override @Override
public void initialize(long randomSeed) { public void initialize(long randomSeed) {
this.numMoves = 0;
this.countTurn = 0; this.countTurn = 0;
this.gameValue = new GameValue(logger); this.gameValue = new GameValue(logger);
this.random = new Random(randomSeed); this.random = new Random(randomSeed);
...@@ -189,6 +191,7 @@ public class OptimizeTurnPlayer implements Player { ...@@ -189,6 +191,7 @@ public class OptimizeTurnPlayer implements Player {
// ones we have so far // ones we have so far
if (validPlacements.isEmpty()) { if (validPlacements.isEmpty()) {
cardTracker.TrackPlacedCardsByMe(placementsOfMove); cardTracker.TrackPlacedCardsByMe(placementsOfMove);
//System.out.print(placementsOfMove.size() + ", ");
return new Move(placementsOfMove); return new Move(placementsOfMove);
} }
...@@ -224,9 +227,10 @@ public class OptimizeTurnPlayer implements Player { ...@@ -224,9 +227,10 @@ public class OptimizeTurnPlayer implements Player {
if (placementsOfMove.size() >= 2) if (placementsOfMove.size() >= 2)
{ {
// no placement was on opponents pile OR the next best rated placement is too bad) // no placement was on opponents pile OR the next best rated placement is too bad)
if (!placedOnOpponentsPiles || bestRatedPlacement.resultingGameValue - lastGameValue < badPlacementTheshold) if (!placedOnOpponentsPiles || bestRatedPlacement.resultingGameValue - lastGameValue > badPlacementTheshold)
{ {
cardTracker.TrackPlacedCardsByMe(placementsOfMove); cardTracker.TrackPlacedCardsByMe(placementsOfMove);
//System.out.print(placementsOfMove.size() + ", ");
return new Move(placementsOfMove); return new Move(placementsOfMove);
} }
} }
...@@ -244,6 +248,7 @@ public class OptimizeTurnPlayer implements Player { ...@@ -244,6 +248,7 @@ public class OptimizeTurnPlayer implements Player {
} }
cardTracker.TrackPlacedCardsByMe(placementsOfMove); cardTracker.TrackPlacedCardsByMe(placementsOfMove);
//System.out.print(placementsOfMove.size() + ", ");
return new Move(placementsOfMove); return new Move(placementsOfMove);
} }
...@@ -326,4 +331,9 @@ public class OptimizeTurnPlayer implements Player { ...@@ -326,4 +331,9 @@ public class OptimizeTurnPlayer implements Player {
this.badPlacementTheshold = badPlacementTheshold; this.badPlacementTheshold = badPlacementTheshold;
} }
public int GetCntTurns()
{
return countTurn;
}
} }
\ No newline at end of file
...@@ -30,7 +30,7 @@ public class OptimizeTurnPlayerDefault implements Player { ...@@ -30,7 +30,7 @@ public class OptimizeTurnPlayerDefault implements Player {
private LoggingSystem logger; private LoggingSystem logger;
private int countTurn = 0; private int countTurn = 0;
private Random random; private Random random;
private int badPlacementTheshold = 42; private int badPlacementTheshold = 0;
private float lastGameValue; private float lastGameValue;
private GameValue gameValue; private GameValue gameValue;
private CardTracker cardTracker; private CardTracker cardTracker;
...@@ -223,7 +223,7 @@ public class OptimizeTurnPlayerDefault implements Player { ...@@ -223,7 +223,7 @@ public class OptimizeTurnPlayerDefault implements Player {
if (placementsOfMove.size() >= 2) if (placementsOfMove.size() >= 2)
{ {
// no placement was on opponents pile OR the next best rated placement is too bad) // no placement was on opponents pile OR the next best rated placement is too bad)
if (!placedOnOpponentsPiles || bestRatedPlacement.resultingGameValue - lastGameValue < badPlacementTheshold) if (!placedOnOpponentsPiles || bestRatedPlacement.resultingGameValue - lastGameValue > badPlacementTheshold)
{ {
cardTracker.TrackPlacedCardsByMe(placementsOfMove); cardTracker.TrackPlacedCardsByMe(placementsOfMove);
return new Move(placementsOfMove); return new Move(placementsOfMove);
...@@ -324,5 +324,9 @@ public class OptimizeTurnPlayerDefault implements Player { ...@@ -324,5 +324,9 @@ public class OptimizeTurnPlayerDefault implements Player {
gameValue.SetWeights(weightOwn, weightOpp); gameValue.SetWeights(weightOwn, weightOpp);
this.badPlacementTheshold = badPlacementTheshold; this.badPlacementTheshold = badPlacementTheshold;
} }
public int GetCntTurns()
{
return countTurn;
}
} }
\ No newline at end of file
...@@ -14,8 +14,8 @@ import java.util.List; ...@@ -14,8 +14,8 @@ import java.util.List;
import java.util.Random; import java.util.Random;
public class OptimizeWeights { public class OptimizeWeights {
private int sizeThreshold = 1; private int sizeThreshold = 60;
private int startThreshold = 42; private int startThreshold = 0;
private int stepThreshold = 1; private int stepThreshold = 1;
private int sizeWeightOwn = 1; private int sizeWeightOwn = 1;
...@@ -23,7 +23,7 @@ public class OptimizeWeights { ...@@ -23,7 +23,7 @@ public class OptimizeWeights {
private float stepWeightOwn = 1.0f; private float stepWeightOwn = 1.0f;
private int sizeWeightOpp = 1; private int sizeWeightOpp = 1;
private float startWeightOpp = 0.06f; private float startWeightOpp = 0.2f;
private float stepWeightOpp = 0.02f; private float stepWeightOpp = 0.02f;
...@@ -76,7 +76,7 @@ public class OptimizeWeights { ...@@ -76,7 +76,7 @@ public class OptimizeWeights {
private Result Simulate(int badPlacementThreshold, float weightOwn, float weightOpp) private Result Simulate(int badPlacementThreshold, float weightOwn, float weightOpp)
{ {
// USER INPUT // USER INPUT
int numGames = 50000; int numGames = 2500;
Player p1 = new OptimizeTurnPlayerDefault( false); Player p1 = new OptimizeTurnPlayerDefault( false);
Player p2 = new OptimizeTurnPlayer(badPlacementThreshold, weightOwn, weightOpp, false); Player p2 = new OptimizeTurnPlayer(badPlacementThreshold, weightOwn, weightOpp, false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment