Commit 9c262019 authored by Fabian Jakob Sauer's avatar Fabian Jakob Sauer

Modified main function. Added first decision method to BasicPlayer.

parent e5d3abce
......@@ -27,7 +27,14 @@
<property name="project.structure.proportion" value="0.0" />
<property name="project.structure.side.proportion" value="0.0" />
</component>
<component name="RunManager" selected="Application.main">
<component name="RunManager" selected="Application.MainClass">
<configuration name="MainClass" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="MainClass" />
<module name="TheGameAI" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TestClass" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="TestClass" />
<module name="TheGameAI" />
......@@ -48,6 +55,7 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.MainClass" />
<item itemvalue="Application.main" />
<item itemvalue="JAR Application.the-game-f2f-engine.jar" />
<item itemvalue="Application.TestClass" />
......@@ -69,37 +77,41 @@
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="322" y="93" key="#Project_Structure/0.0.1920.1040@0.0.1920.1040" timestamp="1588687390551" />
<state width="1877" height="365" key="GridCell.Tab.0.bottom" timestamp="1588706839348">
<state width="468" height="466" key="DebuggerActiveHint" timestamp="1588857735419">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="468" height="466" key="DebuggerActiveHint/0.0.1920.1040@0.0.1920.1040" timestamp="1588857735419" />
<state width="1877" height="344" key="GridCell.Tab.0.bottom" timestamp="1588860569824">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="365" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1588706839348" />
<state width="1877" height="365" key="GridCell.Tab.0.center" timestamp="1588706839348">
<state width="1877" height="344" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1588860569824" />
<state width="1877" height="344" key="GridCell.Tab.0.center" timestamp="1588860569823">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="365" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1588706839348" />
<state width="1877" height="365" key="GridCell.Tab.0.left" timestamp="1588706839348">
<state width="1877" height="344" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1588860569823" />
<state width="1877" height="344" key="GridCell.Tab.0.left" timestamp="1588860569823">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="365" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1588706839348" />
<state width="1877" height="365" key="GridCell.Tab.0.right" timestamp="1588706839348">
<state width="1877" height="344" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1588860569823" />
<state width="1877" height="344" key="GridCell.Tab.0.right" timestamp="1588860569823">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="365" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1588706839348" />
<state width="1877" height="365" key="GridCell.Tab.1.bottom" timestamp="1588706839348">
<state width="1877" height="344" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1588860569823" />
<state width="1877" height="344" key="GridCell.Tab.1.bottom" timestamp="1588860569824">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="365" key="GridCell.Tab.1.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1588706839348" />
<state width="1877" height="365" key="GridCell.Tab.1.center" timestamp="1588706839348">
<state width="1877" height="344" key="GridCell.Tab.1.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1588860569824" />
<state width="1877" height="344" key="GridCell.Tab.1.center" timestamp="1588860569824">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="365" key="GridCell.Tab.1.center/0.0.1920.1040@0.0.1920.1040" timestamp="1588706839348" />
<state width="1877" height="365" key="GridCell.Tab.1.left" timestamp="1588706839348">
<state width="1877" height="344" key="GridCell.Tab.1.center/0.0.1920.1040@0.0.1920.1040" timestamp="1588860569824" />
<state width="1877" height="344" key="GridCell.Tab.1.left" timestamp="1588860569824">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="365" key="GridCell.Tab.1.left/0.0.1920.1040@0.0.1920.1040" timestamp="1588706839348" />
<state width="1877" height="365" key="GridCell.Tab.1.right" timestamp="1588706839348">
<state width="1877" height="344" key="GridCell.Tab.1.left/0.0.1920.1040@0.0.1920.1040" timestamp="1588860569824" />
<state width="1877" height="344" key="GridCell.Tab.1.right" timestamp="1588860569824">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="365" key="GridCell.Tab.1.right/0.0.1920.1040@0.0.1920.1040" timestamp="1588706839348" />
<state width="1877" height="344" key="GridCell.Tab.1.right/0.0.1920.1040@0.0.1920.1040" timestamp="1588860569824" />
</component>
</project>
\ No newline at end of file
......@@ -22,6 +22,19 @@ public class BasicPlayer implements Player {
this.random = new Random(randomSeed);
}
private Placement IsBackwardsTrick(GameState currentGameState, List<Placement> validPlacements)
{
for (Placement placement : validPlacements)
{
if( currentGameState.getTopCardOnOwnAscendingDiscardPile().getNumber() == placement.getCard().getNumber() + 10 ||
currentGameState.getTopCardOnOwnDescendingDiscardPile().getNumber() == placement.getCard().getNumber() - 10 )
{
return placement;
}
}
return null;
}
@Override
public Move computeMove(GameState gameState) {
GameState currentGameState = gameState;
......@@ -49,18 +62,25 @@ public class BasicPlayer implements Player {
return new Move(placementsOfMove);
}
// pick a random placement out of the valid ones
Placement randomPlacement = validPlacements.get(random.nextInt(validPlacements.size()));
if (randomPlacement.getPosition() == CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE
|| randomPlacement.getPosition() == CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE) {
//Pick next placement
Placement nextPlacement = null;
nextPlacement = IsBackwardsTrick(currentGameState, validPlacements); // perform backwards trick if available
if (nextPlacement == null)
{
nextPlacement = validPlacements.get(random.nextInt(validPlacements.size())); // pick random move if no special rule applied
}
if (nextPlacement.getPosition() == CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE
|| nextPlacement.getPosition() == CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE) {
placedOnOpponentsPiles = true;
}
// add this random placement to the placements for our move
placementsOfMove.add(randomPlacement);
placementsOfMove.add(nextPlacement);
// update the view we have on the game to make sure that the next set of valid
// placements is indeed valid
currentGameState = computeNewGameStateAfterPlacement(currentGameState, randomPlacement);
currentGameState = computeNewGameStateAfterPlacement(currentGameState, nextPlacement);
}
return new Move(placementsOfMove);
......
import de.upb.isml.thegamef2f.engine.board.Game;
import de.upb.isml.thegamef2f.engine.player.BasicPlayer;
import de.upb.isml.thegamef2f.engine.player.Player;
import de.upb.isml.thegamef2f.engine.player.RandomPlayer;
import java.util.Random;
public class MainClass {
public static void main(String[] args) {
var numGames = 1000.0;
var RandomPlayerWins = 0.0;
var BasicPlayerWins = 0.0;
Random rand = new Random();
for (int i = 0; i < numGames; i = i + 1) // run specified number of games
{
Game game;
if (i % 2 == 0) // switch starting player after every game
{
game = new Game(new RandomPlayer(), new BasicPlayer(), rand.nextLong());
}
else
{
game = new Game(new BasicPlayer(), new RandomPlayer(), rand.nextLong());
}
Player winner = game.simulate(); // run games simulation
//game.getHistory().printHistory();
// track win statistics
if (winner.getName().equals("RandomPlayer"))
{
RandomPlayerWins += 1;
}
else if (winner.getName().equals("BasicPlayer"))
{
BasicPlayerWins += 1;
}
}
System.out.println("RandomPlayer Wins: " + RandomPlayerWins + " (" + RandomPlayerWins / numGames * 100.0 + " %)");
System.out.println("BasicPlayer Wins: " + BasicPlayerWins + " (" + BasicPlayerWins / numGames * 100.0 + " %)");
}
}
import de.upb.isml.thegamef2f.engine.board.Game;
import de.upb.isml.thegamef2f.engine.player.BasicPlayer;
import de.upb.isml.thegamef2f.engine.player.Player;
import de.upb.isml.thegamef2f.engine.player.RandomPlayer;
public class main {
public static void main(String[] args) {
Game game = new Game(new RandomPlayer(), new BasicPlayer(), 2147953);
Player winner = game.simulate();
game.getHistory().printHistory();
}
}
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