Commit fa23c4ca authored by Fabian Jakob Sauer's avatar Fabian Jakob Sauer

Modifications in optimized player.

parent 9700c026
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ArtifactsWorkspaceSettings">
<artifacts-to-build>
<artifact name="TheGameAI:jar" />
</artifacts-to-build>
</component>
<component name="ChangeListManager">
<list default="true" id="87772642-515a-4b7b-9523-7ca721ec65cc" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
......@@ -24,9 +29,9 @@
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="ignore.virus.scanning.warn.message" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="project.structure.last.edited" value="Modules" />
<property name="project.structure.proportion" value="0.0" />
<property name="project.structure.side.proportion" value="0.0" />
<property name="project.structure.last.edited" value="Artifacts" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2" />
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
......@@ -83,49 +88,69 @@
<servers />
</component>
<component name="WindowStateProjectService">
<state x="322" y="93" key="#Project_Structure" timestamp="1588687390551">
<state x="322" y="93" key="#Project_Structure" timestamp="1589471606793">
<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="1589471606793" />
<state x="992" y="215" key="#com.intellij.ide.util.MemberChooser" timestamp="1590668000458">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="992" y="215" key="#com.intellij.ide.util.MemberChooser/0.0.1920.1040@0.0.1920.1040" timestamp="1590668000458" />
<state x="940" y="314" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1589472909283">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="940" y="314" key="#com.intellij.ide.util.TreeClassChooserDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1589472909283" />
<state x="587" y="0" key="#com.intellij.refactoring.rename.AutomaticRenamingDialog" timestamp="1590663254804">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="587" y="0" key="#com.intellij.refactoring.rename.AutomaticRenamingDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1590663254804" />
<state width="468" height="466" key="DebuggerActiveHint" timestamp="1590674275588">
<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="1590674275588" />
<state x="622" y="273" key="FileChooserDialogImpl" timestamp="1589471605471">
<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="468" height="466" key="DebuggerActiveHint" timestamp="1589460391739">
<state x="622" y="273" key="FileChooserDialogImpl/0.0.1920.1040@0.0.1920.1040" timestamp="1589471605471" />
<state width="1877" height="394" key="GridCell.Tab.0.bottom" timestamp="1590681615975">
<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="1589460391739" />
<state width="1373" height="394" key="GridCell.Tab.0.bottom" timestamp="1589467439116">
<state width="1877" height="394" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1590681615975" />
<state width="1877" height="394" key="GridCell.Tab.0.center" timestamp="1590681615975">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1373" height="394" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1589467439116" />
<state width="1373" height="394" key="GridCell.Tab.0.center" timestamp="1589467439115">
<state width="1877" height="394" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1590681615975" />
<state width="1877" height="394" key="GridCell.Tab.0.left" timestamp="1590681615975">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1373" height="394" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1589467439115" />
<state width="1373" height="394" key="GridCell.Tab.0.left" timestamp="1589467439115">
<state width="1877" height="394" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1590681615975" />
<state width="1877" height="394" key="GridCell.Tab.0.right" timestamp="1590681615975">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1373" height="394" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1589467439115" />
<state width="1373" height="394" key="GridCell.Tab.0.right" timestamp="1589467439116">
<state width="1877" height="394" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1590681615975" />
<state width="1877" height="394" key="GridCell.Tab.1.bottom" timestamp="1590681615975">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1373" height="394" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1589467439116" />
<state width="914" height="351" key="GridCell.Tab.1.bottom" timestamp="1589467439112">
<state width="1877" height="394" key="GridCell.Tab.1.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1590681615975" />
<state width="1877" height="394" key="GridCell.Tab.1.center" timestamp="1590681615975">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="914" height="351" key="GridCell.Tab.1.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1589467439112" />
<state width="914" height="351" key="GridCell.Tab.1.center" timestamp="1589467439112">
<state width="1877" height="394" key="GridCell.Tab.1.center/0.0.1920.1040@0.0.1920.1040" timestamp="1590681615975" />
<state width="1877" height="394" key="GridCell.Tab.1.left" timestamp="1590681615975">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="914" height="351" key="GridCell.Tab.1.center/0.0.1920.1040@0.0.1920.1040" timestamp="1589467439112" />
<state width="914" height="351" key="GridCell.Tab.1.left" timestamp="1589467439112">
<state width="1877" height="394" key="GridCell.Tab.1.left/0.0.1920.1040@0.0.1920.1040" timestamp="1590681615975" />
<state width="1877" height="394" key="GridCell.Tab.1.right" timestamp="1590681615975">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="914" height="351" key="GridCell.Tab.1.left/0.0.1920.1040@0.0.1920.1040" timestamp="1589467439112" />
<state width="914" height="351" key="GridCell.Tab.1.right" timestamp="1589467439112">
<state width="1877" height="394" key="GridCell.Tab.1.right/0.0.1920.1040@0.0.1920.1040" timestamp="1590681615975" />
<state x="690" y="98" key="SettingsEditor" timestamp="1589472912985">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="914" height="351" key="GridCell.Tab.1.right/0.0.1920.1040@0.0.1920.1040" timestamp="1589467439112" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup" timestamp="1589461615549">
<state x="690" y="98" key="SettingsEditor/0.0.1920.1040@0.0.1920.1040" timestamp="1589472912985" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup" timestamp="1590672526563">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup/0.0.1920.1040@0.0.1920.1040" timestamp="1589461615549" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup/0.0.1920.1040@0.0.1920.1040" timestamp="1590672526563" />
</component>
</project>
\ No newline at end of file
Manifest-Version: 1.0
Main-Class: MainClass
......@@ -10,9 +10,9 @@ public class MainClass {
public static void main(String[] args) {
// USER INPUT
var numGames = 100000;
Player p1 = new BasicPlayer();
Player p2 = new RealPlayer();
var numGames = 1;
Player p1 = new OptimizeTurnPlayer();
Player p2 = new BasicPlayer();
Statistics stats = new Statistics(p1, p2);
Random rand = new Random();
......@@ -26,14 +26,17 @@ public class MainClass {
Game game;
if (i % 2 == 0) // switch starting player after every game
{
game = new Game(p1, p2, rand.nextLong());
//game = new Game(p1, p2, rand.nextLong());
game = new Game(p1, p2, 69420);
}
else
{
game = new Game(p2, p1, rand.nextLong());
//game = new Game(p2, p1, rand.nextLong());
game = new Game(p2, p1, 69420);
}
Player winner = game.simulate(); // run games simulation
//game.getHistory().printHistory();
stats.TrackGame(winner, game.getHistory());
}
......
......@@ -6,8 +6,6 @@ import de.upb.isml.thegamef2f.engine.Move;
import de.upb.isml.thegamef2f.engine.Placement;
import de.upb.isml.thegamef2f.engine.board.Card;
import de.upb.isml.thegamef2f.engine.player.Player;
import util.Extensions.ExtendedPlacement;
import util.Extensions.StackValue;
import java.util.ArrayList;
import java.util.List;
......
......@@ -6,8 +6,10 @@ import de.upb.isml.thegamef2f.engine.Move;
import de.upb.isml.thegamef2f.engine.Placement;
import de.upb.isml.thegamef2f.engine.board.Card;
import de.upb.isml.thegamef2f.engine.player.Player;
import util.Extensions.CardTracker;
import util.Extensions.ExtendedPlacement;
import util.Extensions.StackValue;
import util.Extensions.RatedPlacement;
import util.Extensions.GameValue;
import java.util.ArrayList;
import java.util.List;
......@@ -29,13 +31,16 @@ import java.util.Random;
public class OptimizeTurnPlayer implements Player {
private Random random;
private StackValue stackValue = new StackValue();
private double winPercentage = 0.5;
private int badPlacementTheshold = 10;
private float lastGameValue;
private GameValue gameValue = new GameValue();
private CardTracker cardTracker = new CardTracker();
private GameState latestGameState;
@Override
public void initialize(long randomSeed) {
this.random = new Random(randomSeed);
this.cardTracker = new CardTracker();
}
private List<ExtendedPlacement> ComputePlacements(List<Card> pile, Card lastKnownCard, CardPosition pos)
......@@ -69,68 +74,69 @@ public class OptimizeTurnPlayer implements Player {
*/
List<ExtendedPlacement> reconstructedPlacements = new ArrayList<ExtendedPlacement>();
if (newGameState.getTopCardOnOwnDescendingDiscardPile() != latestGameState.getTopCardOnOwnDescendingDiscardPile())
if (latestGameState == null)
{
List<Card> pile = newGameState.getCardsOnOwnDescendingDiscardPile();
Card lastKnownCard = latestGameState.getTopCardOnOwnDescendingDiscardPile();
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OWN_DESCENDING_DISCARD_PILE));
}
if (newGameState.getTopCardOnOwnAscendingDiscardPile() != latestGameState.getTopCardOnOwnAscendingDiscardPile())
{
List<Card> pile = newGameState.getCardsOnOwnAscendingDiscardPile();
Card lastKnownCard = latestGameState.getTopCardOnOwnAscendingDiscardPile();
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OWN_ASCENDING_DISCARD_PILE));
}
if (newGameState.getTopCardOnOpponentsDescendingDiscardPile() != latestGameState.getTopCardOnOpponentsDescendingDiscardPile())
{
List<Card> pile = newGameState.getCardsOnOpponentsDescendingDiscardPile();
Card lastKnownCard = latestGameState.getTopCardOnOpponentsDescendingDiscardPile();
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE));
}
if (newGameState.getTopCardOnOpponentsAscendingDiscardPile() != latestGameState.getTopCardOnOpponentsAscendingDiscardPile())
{
List<Card> pile = newGameState.getCardsOnOpponentsAscendingDiscardPile();
Card lastKnownCard = latestGameState.getTopCardOnOpponentsAscendingDiscardPile();
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE));
if (newGameState.getTopCardOnOwnDescendingDiscardPile().getNumber() != 60)
{
List<Card> pile = newGameState.getCardsOnOwnDescendingDiscardPile();
Card lastKnownCard = newGameState.getCardsOnOwnDescendingDiscardPile().get(0);
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OWN_DESCENDING_DISCARD_PILE));
}
if (newGameState.getTopCardOnOwnAscendingDiscardPile().getNumber() != 1)
{
List<Card> pile = newGameState.getCardsOnOwnAscendingDiscardPile();
Card lastKnownCard = newGameState.getCardsOnOwnAscendingDiscardPile().get(0);
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OWN_ASCENDING_DISCARD_PILE));
}
if (newGameState.getTopCardOnOpponentsDescendingDiscardPile().getNumber() != 60)
{
List<Card> pile = newGameState.getCardsOnOpponentsDescendingDiscardPile();
Card lastKnownCard = newGameState.getCardsOnOpponentsDescendingDiscardPile().get(0);
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE));
}
if (newGameState.getTopCardOnOpponentsAscendingDiscardPile().getNumber() != 1)
{
List<Card> pile = newGameState.getCardsOnOpponentsAscendingDiscardPile();
Card lastKnownCard = newGameState.getCardsOnOpponentsAscendingDiscardPile().get(0);
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE));
}
}
return reconstructedPlacements;
}
private double EvaluateState(List<ExtendedPlacement> reconstructedPlacements)
{
for (ExtendedPlacement placement : reconstructedPlacements)
else
{
if (placement.getPosition() == CardPosition.OWN_ASCENDING_DISCARD_PILE)
if (newGameState.getTopCardOnOwnDescendingDiscardPile() != latestGameState.getTopCardOnOwnDescendingDiscardPile())
{
stackValue.OWN_ASCENDING_DISCARD_PILE += placement.getCard().getNumber() - placement.GetPrevTopCard().getNumber() - 1;
List<Card> pile = newGameState.getCardsOnOwnDescendingDiscardPile();
Card lastKnownCard = latestGameState.getTopCardOnOwnDescendingDiscardPile();
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OWN_DESCENDING_DISCARD_PILE));
}
else if (placement.getPosition() == CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE)
if (newGameState.getTopCardOnOwnAscendingDiscardPile() != latestGameState.getTopCardOnOwnAscendingDiscardPile())
{
stackValue.OPPONENTS_ASCENDING_DISCARD_PILE += placement.getCard().getNumber() - placement.GetPrevTopCard().getNumber() - 1;;
List<Card> pile = newGameState.getCardsOnOwnAscendingDiscardPile();
Card lastKnownCard = latestGameState.getTopCardOnOwnAscendingDiscardPile();
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OWN_ASCENDING_DISCARD_PILE));
}
else if (placement.getPosition() == CardPosition.OWN_DESCENDING_DISCARD_PILE)
if (newGameState.getTopCardOnOpponentsDescendingDiscardPile() != latestGameState.getTopCardOnOpponentsDescendingDiscardPile())
{
stackValue.OWN_DESCENDING_DISCARD_PILE += placement.GetPrevTopCard().getNumber() - placement.getCard().getNumber() + 1;
List<Card> pile = newGameState.getCardsOnOpponentsDescendingDiscardPile();
Card lastKnownCard = latestGameState.getTopCardOnOpponentsDescendingDiscardPile();
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE));
}
else if (placement.getPosition() == CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE)
if (newGameState.getTopCardOnOpponentsAscendingDiscardPile() != latestGameState.getTopCardOnOpponentsAscendingDiscardPile())
{
stackValue.OPPONENTS_DESCENDING_DISCARD_PILE += placement.GetPrevTopCard().getNumber() - placement.getCard().getNumber() + 1;
List<Card> pile = newGameState.getCardsOnOpponentsAscendingDiscardPile();
Card lastKnownCard = latestGameState.getTopCardOnOpponentsAscendingDiscardPile();
reconstructedPlacements.addAll(ComputePlacements(pile, lastKnownCard, CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE));
}
}
return 0.5 +
((stackValue.OPPONENTS_ASCENDING_DISCARD_PILE - stackValue.OWN_ASCENDING_DISCARD_PILE) / 60.0 * 0.25) +
((stackValue.OPPONENTS_DESCENDING_DISCARD_PILE - stackValue.OWN_DESCENDING_DISCARD_PILE) / 60.0 * 0.25);
return reconstructedPlacements;
}
@Override
public Move computeMove(GameState newGameState) {
if (latestGameState == null)
{
latestGameState = newGameState;
}
// Reconstruct enemies last move
List<ExtendedPlacement> reconstructedPlacements = ReconstructPlacements(newGameState);
winPercentage = EvaluateState(reconstructedPlacements);
// System.out.println("Win Percentage: " + winPercentage);
cardTracker.TrackPlacedCardsByOp(reconstructedPlacements);
latestGameState = newGameState;
......@@ -155,12 +161,44 @@ public class OptimizeTurnPlayer implements Player {
// if we cannot find a valid placement anymore, we can stop here and return the
// ones we have so far
if (validPlacements.isEmpty()) {
cardTracker.TrackPlacedCardsByMe(placementsOfMove);
return new Move(placementsOfMove);
}
//Pick next placement
Placement nextPlacement = validPlacements.get(random.nextInt(validPlacements.size())); // pick random move if no special rule applied
// calculate game value before placing a card
lastGameValue = gameValue.calcGameValue(latestGameState, cardTracker);
// rate all possible placements using game value
List<RatedPlacement> ratedPlacements = new ArrayList<RatedPlacement>();
for (Placement potentialPlacement : validPlacements)
{
GameState potentialGameState = computeNewGameStateAfterPlacement(latestGameState, potentialPlacement);
ratedPlacements.add(new RatedPlacement(potentialPlacement, gameValue.calcGameValue(potentialGameState, cardTracker)));
}
// find best rated placement
RatedPlacement bestRatedPlacement = ratedPlacements.get(0);
for (RatedPlacement ratedPlacement : ratedPlacements)
{
if (ratedPlacement.resultingGameValue < bestRatedPlacement.resultingGameValue)
{
bestRatedPlacement = ratedPlacement;
}
}
Placement nextPlacement = bestRatedPlacement.placement;
//Placement nextPlacement = validPlacements.get(random.nextInt(validPlacements.size()); // pick random move if no special rule applied
// return if
//two or more placements are selected
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)
{
cardTracker.TrackPlacedCardsByMe(placementsOfMove);
return new Move(placementsOfMove);
}
}
if (nextPlacement.getPosition() == CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE
|| nextPlacement.getPosition() == CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE) {
......@@ -169,11 +207,23 @@ public class OptimizeTurnPlayer implements Player {
// add this random placement to the placements for our move
placementsOfMove.add(nextPlacement);
/*
// return current move if number of placements >= 2
if (placementsOfMove.size() >= 2)
{
cardTracker.TrackPlacedCardsByMe(placementsOfMove);
return new Move(placementsOfMove);
}
*/
// update the view we have on the game to make sure that the next set of valid
// placements is indeed valid
latestGameState = computeNewGameStateAfterPlacement(latestGameState, nextPlacement);
}
cardTracker.TrackPlacedCardsByMe(placementsOfMove);
return new Move(placementsOfMove);
}
......
......@@ -37,36 +37,55 @@ public class RealPlayer implements Player {
{
while (true)
{
System.out.println("________ Enemy: ________");
System.out.println("ASC [ID:0]: "+ currentGameState.getTopCardOnOpponentsAscendingDiscardPile().getNumber() + " (Number of cards: "+ currentGameState.getCardsOnOpponentsAscendingDiscardPile().size()+")");
System.out.println("DES [ID:1]: "+ currentGameState.getTopCardOnOpponentsDescendingDiscardPile().getNumber() + " (Number of cards: "+ currentGameState.getCardsOnOpponentsDescendingDiscardPile().size()+")");
System.out.println("________ You: ________");
System.out.println("DES [ID:2]: "+ currentGameState.getTopCardOnOwnDescendingDiscardPile().getNumber() + " (Number of cards: "+ currentGameState.getCardsOnOwnDescendingDiscardPile().size()+")");
System.out.println("ASC [ID:3]: "+ currentGameState.getTopCardOnOwnAscendingDiscardPile().getNumber() + " (Number of cards: "+ currentGameState.getCardsOnOwnAscendingDiscardPile().size()+")");
System.out.println("_________ Enemy: ________");
System.out.println("ASC [ID:1]: "+ currentGameState.getTopCardOnOpponentsAscendingDiscardPile().getNumber() + " (Number of cards: "+ currentGameState.getCardsOnOpponentsAscendingDiscardPile().size()+")");
System.out.println("DES [ID:2]: "+ currentGameState.getTopCardOnOpponentsDescendingDiscardPile().getNumber() + " (Number of cards: "+ currentGameState.getCardsOnOpponentsDescendingDiscardPile().size()+")");
System.out.println("_________ You: __________");
System.out.println("DES [ID:3]: "+ currentGameState.getTopCardOnOwnDescendingDiscardPile().getNumber() + " (Number of cards: "+ currentGameState.getCardsOnOwnDescendingDiscardPile().size()+")");
System.out.println("ASC [ID:4]: "+ currentGameState.getTopCardOnOwnAscendingDiscardPile().getNumber() + " (Number of cards: "+ currentGameState.getCardsOnOwnAscendingDiscardPile().size()+")");
System.out.println("Hand cards: " + currentGameState.getHandCards());
System.out.println("______________________\nChoose placement:\n Card:");
int cardNumber = sc.nextInt();
System.out.println("___ Choose placement: ___");
int cardNumber = -1;
do {
System.out.println("Card (0 for 'No more moves'): ");
while (!sc.hasNextInt()) {
System.out.println("That's not an integer. Try again.");
sc.next();
}
cardNumber = sc.nextInt();
} while (cardNumber <= -1);
if (cardNumber == 0)
{
return null;
}
System.out.println("Discard pile ID: ");
int pileID = sc.nextInt();
int pileID = -1;
do {
System.out.println("Discard pile ID: ");
while (!sc.hasNextInt()) {
System.out.println("That's not an integer. Try again.");
sc.next();
}
pileID = sc.nextInt();
} while (pileID <= -1);
CardPosition chosenCardPosition = null;
if (pileID == 0)
if (pileID == 1)
{
chosenCardPosition = CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE;
}
else if (pileID == 1)
else if (pileID == 2)
{
chosenCardPosition = CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE;
}
else if (pileID == 2)
else if (pileID == 3)
{
chosenCardPosition = CardPosition.OWN_DESCENDING_DISCARD_PILE;
}
else if (pileID == 3)
else if (pileID == 4)
{
chosenCardPosition = CardPosition.OWN_ASCENDING_DISCARD_PILE;
}
......
package util.Extensions;
import de.upb.isml.thegamef2f.engine.Placement;
import de.upb.isml.thegamef2f.engine.board.Card;
import java.util.ArrayList;
import java.util.List;
public class CardTracker {
public List<Card> cardsPlacedByMe = new ArrayList<Card>();
public List<Card> cardsPlacedByOp = new ArrayList<Card>();
public void TrackPlacedCardsByMe(List<Placement> placementsOfMove)
{
for (Placement placement : placementsOfMove)
{
cardsPlacedByMe.add(placement.getCard());
}
}
public void TrackPlacedCardsByOp(List<ExtendedPlacement> placementsOfMove)
{
for (ExtendedPlacement placement : placementsOfMove)
{
cardsPlacedByOp.add(placement.getCard());
}
}
public void PrintTrackedCards()
{
System.out.println("Cards played by me: " + cardsPlacedByMe);
System.out.println("Cards played by op: " + cardsPlacedByOp);
}
}
package util.Extensions;
import de.upb.isml.thegamef2f.engine.GameState;
import de.upb.isml.thegamef2f.engine.board.Card;
public class GameValue {
private StackValue ownAsc = new StackValue(true, true);
private StackValue ownDes = new StackValue(true, false);
private StackValue oppAsc = new StackValue(false, true);
private StackValue oppDes = new StackValue(false, false);
private float gameValue = 0.0f;
private float weightOwn = 1.0f;
private float weightOpp = 0.2f;
public float calcGameValue(GameState potentialGameState, CardTracker cardTracker)
{
ownAsc.calcValues(potentialGameState, cardTracker, weightOwn, weightOpp);
ownDes.calcValues(potentialGameState, cardTracker, weightOwn, weightOpp);
oppAsc.calcValues(potentialGameState, cardTracker, weightOwn, weightOpp);
oppDes.calcValues(potentialGameState, cardTracker, weightOwn, weightOpp);
System.out.println("\nOwnAsc: " + potentialGameState.getTopCardOnOwnAscendingDiscardPile());
System.out.println("OwnDes: " + potentialGameState.getTopCardOnOwnDescendingDiscardPile());
System.out.println("OppAsc: " + potentialGameState.getTopCardOnOpponentsAscendingDiscardPile());
System.out.println("OppDes: " + potentialGameState.getTopCardOnOpponentsDescendingDiscardPile());
System.out.println("___________________________________________________");
gameValue = ownAsc.GetValue() + ownDes.GetValue() - oppAsc.GetValue() - oppDes.GetValue();
return gameValue;
}
public void updateStackValue(CardTracker cardTracker, Card topCardOwnAsc, Card topCardOwnDes, Card topCardOppAsc, Card topCardOppDes)
{
}
public void setWeightOwn(float weight)
{
weightOwn = weight;
}
public void setWeightOpp(float weight)
{
weightOpp = weight;
}
}
package util.Extensions;
import de.upb.isml.thegamef2f.engine.Placement;
public class RatedPlacement {
public Placement placement;
public float resultingGameValue;
public RatedPlacement(Placement placement, float gameValue)
{
this.placement = placement;
this.resultingGameValue = gameValue;
}
}
package util.Extensions;
import de.upb.isml.thegamef2f.engine.GameState;
import de.upb.isml.thegamef2f.engine.board.Card;
import java.util.List;
public class StackValue {
public int OWN_ASCENDING_DISCARD_PILE = 0;
public int OWN_DESCENDING_DISCARD_PILE = 0;
public int OPPONENTS_ASCENDING_DISCARD_PILE = 0;
public int OPPONENTS_DESCENDING_DISCARD_PILE = 0;
public float value;
public int GetOwnAscendingDiscardPile()
{
return OWN_ASCENDING_DISCARD_PILE;
}
private boolean isMine;
private boolean isAscending;
public int GetOwnDescendingDiscardPile()
{
return OWN_DESCENDING_DISCARD_PILE;
public int ownTheo;
public int ownPrac;
public int oppTheo;
public int oppPrac;
public StackValue(boolean isMine, boolean isAscending) {
this.isMine = isMine;
this.isAscending = isAscending;
}
public float GetValue() {
return value;
}
private int GetNotSkippedCards(boolean isSmallerThanTopCard, List<Card> playedCards, Card topCard)
{
int notSkippedCards = 0;
for (Card card : playedCards) {
if (isSmallerThanTopCard)
{
if (card.getNumber() <= topCard.getNumber()) {
notSkippedCards++;
}
}
else
{
if (card.getNumber() >= topCard.getNumber()) {
notSkippedCards++;
}
}
}
return notSkippedCards;
}
public void calcValues(GameState potentialGameState, CardTracker cardTracker, float weightOwn, float weightOpp) {