Skip to content
Snippets Groups Projects
Commit 0addc4c8 authored by iliya's avatar iliya
Browse files

feat: added basic strategy to AI

parent 6594a3b0
No related branches found
No related tags found
No related merge requests found
......@@ -125,4 +125,41 @@ public class AIPlayer implements IPlayer {
return str;
}
public void basicStrategy(Deck currentGame) {
while (this.getHand().computeHandValue() < 17) {
this.displayPlayerHand();
for (Card card : this.getHand()) {
if (card.getRankName().equals("As")) {
if (this.getHand().computeHandValue() + 10 <= 21) {
System.out.println("AI assigned the value 11 to the ace");
card.setWeight(11);
if (this.getHand().computeHandValue() == 21) {
break;
}
}
}
}
System.out.println("AI drew a new card");
this.getHand().addToHand(currentGame.removeFromDeck());
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void displayPlayerHand() {
System.out.println();
System.out.println("AI's hand is: " + this.getHand());
System.out.println("Its value is: " + this.getHand().computeHandValue());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment