Commit 0f8922e2 authored by Fabian Jakob Sauer's avatar Fabian Jakob Sauer

Added HelpEnemyWithoutConsequences check.

parent 1d0514e1
......@@ -86,22 +86,22 @@
<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="1588936167247" />
<state width="1877" height="310" key="GridCell.Tab.0.bottom" timestamp="1588936544380">
<state width="1877" height="227" key="GridCell.Tab.0.bottom" timestamp="1588938545886">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="310" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1588936544380" />
<state width="1877" height="310" key="GridCell.Tab.0.center" timestamp="1588936544380">
<state width="1877" height="227" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1588938545886" />
<state width="1877" height="227" key="GridCell.Tab.0.center" timestamp="1588938545886">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="310" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1588936544380" />
<state width="1877" height="310" key="GridCell.Tab.0.left" timestamp="1588936544380">
<state width="1877" height="227" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1588938545886" />
<state width="1877" height="227" key="GridCell.Tab.0.left" timestamp="1588938545886">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="310" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1588936544380" />
<state width="1877" height="310" key="GridCell.Tab.0.right" timestamp="1588936544380">
<state width="1877" height="227" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1588938545886" />
<state width="1877" height="227" key="GridCell.Tab.0.right" timestamp="1588938545886">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="310" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1588936544380" />
<state width="1877" height="227" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1588938545886" />
<state width="1073" height="173" key="GridCell.Tab.1.bottom" timestamp="1588936180713">
<screen x="0" y="0" width="1920" height="1040" />
</state>
......
......@@ -115,6 +115,9 @@ public class BasicPlayer implements Player {
private Placement IsBackwardsTrick(GameState currentGameState, List<Placement> validPlacements)
{
/* checks if one of the valid placements is a BackwardsTrick placement.
* If true, placement is returned
* If false, null is returned */
for (Placement placement : validPlacements)
{
if( (currentGameState.getTopCardOnOwnAscendingDiscardPile().getNumber() == placement.getCard().getNumber() + 10 && placement.getPosition() == CardPosition.OWN_ASCENDING_DISCARD_PILE) ||
......@@ -126,6 +129,22 @@ public class BasicPlayer implements Player {
return null;
}
private Placement IsHelpEnemyWithoutConsequences(GameState currentGameState, List<Placement> validPlacements)
{
/* checks if one of the valid placements is a HelpEnemyWithoutConsequences placement.
* If true, placement is returned
* If false, null is returned */
for (Placement placement : validPlacements)
{
if( (currentGameState.getTopCardOnOpponentsAscendingDiscardPile().getNumber() == placement.getCard().getNumber() + 1 && placement.getPosition() == CardPosition.OPPONENTS_ASCENDING_DISCARD_PILE) ||
(currentGameState.getTopCardOnOpponentsDescendingDiscardPile().getNumber() == placement.getCard().getNumber() - 1 && placement.getPosition() == CardPosition.OPPONENTS_DESCENDING_DISCARD_PILE) )
{
return placement;
}
}
return null;
}
@Override
public Move computeMove(GameState newGameState) {
if (latestGameState == null)
......@@ -166,9 +185,9 @@ public class BasicPlayer implements Player {
Placement nextPlacement = null;
nextPlacement = IsBackwardsTrick(latestGameState, validPlacements); // perform backwards trick if available
if (nextPlacement == null)
{
nextPlacement = IsHelpEnemyWithoutConsequences(latestGameState, validPlacements); // perform help enemy 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
......
......@@ -8,7 +8,7 @@ import java.util.Random;
public class MainClass {
public static void main(String[] args) {
var numGames = 1000.0;
var numGames = 100000.0;
var RandomPlayerWins = 0.0;
var BasicPlayerWins = 0.0;
......@@ -16,6 +16,10 @@ public class MainClass {
for (int i = 0; i < numGames; i = i + 1) // run specified number of games
{
if (i % 1000 == 0)
{
System.out.println(i);
}
Game game;
if (i % 2 == 0) // switch starting player after every game
{
......
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