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

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

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