Skip to content
Snippets Groups Projects
Commit e851c001 authored by michael.divia's avatar michael.divia
Browse files

Part 2 95%

parent 58751b99
Branches
No related tags found
No related merge requests found
Showing
with 421 additions and 95 deletions
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
\ No newline at end of file
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/padi/Téléchargements",
"program": "/home/padi/Téléchargements/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
\ No newline at end of file
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
\ No newline at end of file
......@@ -4,7 +4,10 @@ import java.util.Scanner;
public class App {
// Scanner will be used all along to take user inputs in the terminal
public static final Scanner in = new Scanner(System.in);
// All Color choices to be used in terminal prints
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
......@@ -25,9 +28,12 @@ public class App {
int numPlayers;
int startMoney;
// Ask the number of players until a valide answer is given
while (true) {
System.out.print("How many players ? ");
// Check that the input is an valid int
while (!App.in.hasNextInt()) {
System.out.println(
App.ANSI_YELLOW + "Please enter a valid number for the number of players." + App.ANSI_RESET);
......@@ -37,6 +43,7 @@ public class App {
numPlayers = App.in.nextInt();
// Player count must be between 1 and 7
if (numPlayers >= 1 && numPlayers <= 7) {
System.out.print("");
break;
......@@ -46,9 +53,12 @@ public class App {
}
}
// Ask the start money count for each players until a valide answer is given
while (true) {
System.out.print("How much money do you start with ? ");
// Check that the input is an valid int
while (!App.in.hasNextInt()) {
System.out.println(App.ANSI_YELLOW + "Please enter a valid number for your Money." + App.ANSI_RESET);
System.out.print("How much money do you start with ? ");
......@@ -57,6 +67,7 @@ public class App {
startMoney = App.in.nextInt();
// Starting money must be more or equal to minimum bid amount
if (startMoney >= 10) {
System.out.print("");
break;
......@@ -65,16 +76,28 @@ public class App {
}
}
// Create a new game
GameManager BlackJack = new GameManager(numPlayers, startMoney);
boolean GameOver = false;
// Game run's in 3 Phases :
// Phase 1 (StartTurn):
// Ask the player how much he wan't to bid
// Phase 2 (PlayTurn):
// Ask the player for all his interactions with this cards
// Phase 3 (ResolveTurn):
// Make the Dealer pick cards
// Do all the math for the player gains and losses
// Check if the player can continue et prepare for the next round
while (!GameOver) {
BlackJack.StartTurn();
BlackJack.PlayTurn();
GameOver = BlackJack.ResolveTurn();
}
// The player has less than the minimum bid amount allowed = Game Over
System.out.print("\033[H\033[2J");
System.out.flush();
......@@ -87,6 +110,7 @@ public class App {
public static void main(String[] args) {
// Play 1 BlackJack Game
BlackJack();
}
......
......@@ -12,12 +12,15 @@ public class GameManager {
public GameManager(int nbPlayer, int startMoney) {
// Create a new BlackJack Deck of card (6 x 52 cards game)
this.Deck = new JeudeCarte(new Paquet(6, 52));
this.Players = new ArrayList<>();
// First Player is always the humain
this.Players.add(new JoueurHumain(Deck, startMoney));
// All other are controlled by the computer
if (nbPlayer > 1) {
for (int x = 1; x < nbPlayer; x++) {
this.Players.add(new JoueurOrdinateur(Deck, startMoney));
......@@ -27,69 +30,122 @@ public class GameManager {
this.Dealer = new JoueurCroupier(Deck);
}
public boolean ResolveTurn() {
// Phase 1 (StartTurn):
// Ask the player how much he wan't to bid
public void StartTurn() {
this.Dealer.DrawCard(0, this.Deck);
this.Step = 0;
// If the player has less than the minimum bid amount allowed
if (this.Players.get(0).GetMoney() <= 10) {
return true;
System.out.print("\033[H\033[2J");
System.out.flush();
System.out.println("*~-~* " + App.ANSI_RED + "BlackJack" + App.ANSI_RESET + " *~-~*\n");
double bet;
System.out.println("Money : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET);
// Ask the bid amount until a valide answer is given
while (true) {
System.out.print("How much do you want to bet (Min. 10) ? ");
// Check that the input is an valid double
while (!App.in.hasNextDouble()) {
System.out.println(App.ANSI_YELLOW + "Please enter a valid number to bet." + App.ANSI_RESET);
System.out.print("How much do you want to bet (Min. 10) ?");
App.in.next();
}
this.Dealer.Reset(this.Deck);
for (Joueur Player : this.Players) {
Player.Reset(this.Deck);
bet = App.in.nextDouble();
// Check if the player has enough money to place the bid
if (bet <= this.Players.get(0).GetMoney()) {
// Check if the minimum bid amount it cleared
if (bet < 10) {
System.out.println(App.ANSI_YELLOW + "Minimum bid amount is 10." + App.ANSI_RESET);
} else {
break;
}
return false;
} else {
System.out.println(App.ANSI_YELLOW + "You don't have enough money." + App.ANSI_RESET);
}
}
// Set the player bid for this turn
Players.get(0).SetBet(bet, 0);
}
// Phase 2 (PlayTurn):
// Ask the player for all his interactions with this cards
public void PlayTurn() {
boolean EndTurn = false;
boolean EndTurn = false, CanSplit = false, CanInsure = false, CanDouble = false, CanDraw = false;
// Continue interacting with the player until all actions have been taken on all
// his hands
while (!EndTurn) {
boolean CanSplit = false, CanInsure = false, CanDouble = false, CanDraw = false;
char choice = 'x';
// Go thew all hands of the player
for (int HandNb = 0; HandNb < this.Players.get(0).NbHands(); HandNb++) {
CanSplit = false;
CanInsure = false;
CanDouble = false;
CanDraw = false;
choice = 'x';
System.out.print("\033[H\033[2J");
System.out.flush();
System.out.println("*~-~* " + App.ANSI_RED + "BlackJack" + App.ANSI_RESET + " *~-~*\n");
System.out.println("Cards in Deck : " + App.ANSI_GREEN + this.Deck.GetNbCards() + App.ANSI_RESET + "\n");
// Show the remaining amount of cards in the deck
System.out.println(
"Cards in Deck : " + App.ANSI_GREEN + this.Deck.GetNbCards() + App.ANSI_RESET + "\n");
System.out.print("Dealer Score : " + App.ANSI_PURPLE);
if (this.Dealer.GetForce(0) == 99) {
System.out.println("BlackJack" + App.ANSI_RESET);
} else {
System.out.println(this.Dealer.GetForce(0) + App.ANSI_RESET);
}
// Dealer has only 1 card in his hand at this point in time
System.out.print("Dealer Strength : " + App.ANSI_PURPLE + this.Dealer.GetForce(0) + App.ANSI_RESET);
// Show the dealer hand
this.Dealer.ShowHands();
// Show the current player balance
System.out.println("\nMoney : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET);
// Check if the player has put down an insurance
if (this.Players.get(0).HasInsured()) {
System.out.println("Insured : " + App.ANSI_BLUE + this.Players.get(0).GetInsured() + App.ANSI_RESET);
System.out.println(
"Insured : " + App.ANSI_BLUE + this.Players.get(0).GetInsured() + App.ANSI_RESET);
}
char choice = 'x';
for (int HandNb = 0; HandNb < this.Players.get(0).NbHands(); HandNb++) {
// Show the hand number of the player
System.out
.println("Bet on Hand " + App.ANSI_GREEN + (HandNb + 1) + App.ANSI_RESET + " : " + App.ANSI_BLUE
+ this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET);
// Show the hand strength of the player
// 99 = BlackJack
// >21 = Busted
// <=21 = show the strength
System.out
.print("Score of Hand " + App.ANSI_GREEN + (HandNb + 1) + App.ANSI_RESET + " : "
.print("Strength of Hand " + App.ANSI_GREEN + (HandNb + 1) + App.ANSI_RESET + " : "
+ App.ANSI_PURPLE);
if (this.Players.get(0).GetForce(HandNb) == 99) {
System.out.println("BlackJack" + App.ANSI_RESET);
} else if (this.Players.get(0).GetForce(HandNb) > 21) {
System.out.println(
this.Players.get(0).GetForce(HandNb) + App.ANSI_RED + " [BUSTED]" + App.ANSI_RESET);
} else {
System.out.println(this.Players.get(0).GetForce(HandNb) + App.ANSI_RESET);
}
this.Players.get(0).ShowHands();
// Show the player hand
this.Players.get(0).ShowHand(HandNb);
// Choices for player
System.out.println("\n--- " + App.ANSI_GREEN + "Choices" + App.ANSI_RESET + " ---\n");
......@@ -109,8 +165,11 @@ public class GameManager {
// the 2 cards have the same strength)
// AND
// if we have less that 3 hands already (Max 2 splits)
// AND
// if the player has enough money
if (this.Players.get(0).CanSplit(HandNb)
&& this.Players.get(0).NbHands() < 3) {
&& this.Players.get(0).NbHands() < 3
&& this.Players.get(0).GetBet(HandNb) <= this.Players.get(0).GetMoney()) {
CanSplit = true;
System.out.println(App.ANSI_BLUE + "[s]" + App.ANSI_RESET + " Split your Hand");
}
......@@ -121,9 +180,12 @@ public class GameManager {
// if the hand has only 2 cards
// AND
// if the hand is not a BlackJack
// AND
// if the player has enough money
if (!this.Players.get(0).HasDoubled(HandNb)
&& this.Players.get(0).NbCards(HandNb) == 2
&& this.Players.get(0).GetForce(HandNb) != 99) {
&& this.Players.get(0).GetForce(HandNb) != 99
&& this.Players.get(0).GetBet(HandNb) <= this.Players.get(0).GetMoney()) {
CanDouble = true;
System.out.println(App.ANSI_BLUE + "[d]" + App.ANSI_RESET + " Double your Hand");
}
......@@ -134,89 +196,188 @@ public class GameManager {
// if the hand has been splitted with a pair of Asses
// AND
// if the player has a BlackJack
// AND
// if the strength of the hand is more than 21
if (!(this.Players.get(0).HasDoubled(HandNb) && this.Players.get(0).NbCards(HandNb) == 3)
&& !(this.Players.get(0).CanSplit(HandNb) && this.Players.get(0).GetCardForce(HandNb, 0) == 1)
&& this.Players.get(0).GetForce(HandNb) != 99) {
&& !(this.Players.get(0).HasSplit(HandNb) && this.Players.get(0).GetCardForce(HandNb, 0) == 1)
&& this.Players.get(0).GetForce(HandNb) < 21) {
CanDraw = true;
System.out.println(App.ANSI_BLUE + "[h]" + App.ANSI_RESET + " Hit");
}
// Stand
System.out.println(App.ANSI_BLUE + "[s]" + App.ANSI_RESET + " Stand");
if (CanInsure || CanSplit || CanDouble || CanDraw || this.Players.get(0).GetForce(HandNb) == 99) {
// Keep (Stand)
System.out.println(App.ANSI_BLUE + "[k]" + App.ANSI_RESET + " Keep current Hand");
// Ask for the player choice until a valide one is given
while (true) {
System.out.print("> ");
choice = App.in.next().charAt(0);
// Choices are checked with available one for confirmation
if ((choice == 'i' && CanInsure) || (choice == 's' && CanSplit) || (choice == 'd' && CanDouble)
|| (choice == 'h' && CanDraw)
|| choice == 's') {
|| choice == 'k') {
break;
} else {
System.out.println(App.ANSI_YELLOW + "Please enter a valid choice." + App.ANSI_RESET);
}
}
}
// Hit
if (choice == 'h') {
this.Players.get(0).DrawCard(HandNb, this.Deck);
// Go back 1 hand to stay on the same hand in the for loop
HandNb--;
}
// Split
else if (choice == 's') {
this.Players.get(0).Split(HandNb, this.Deck);
// Go back 1 hand to stay on the same hand in the for loop
HandNb--;
}
// Double
else if (choice == 'd') {
this.Players.get(0).Double(HandNb, this.Deck);
// Go back 1 hand to stay on the same hand in the for loop
HandNb--;
}
Step++;
}
// Insure
if (choice == 'i') {
this.Players.get(0).Insure();
EndTurn = false;
} else if (choice == 'h') {
EndTurn = false;
} else {
}
// If this point is reached (and not because of the insurance), all hands have
// been played
else {
EndTurn = true;
}
}
}
public void StartTurn() {
// Phase 3 (ResolveTurn):
// Make the Dealer pick cards
// Do all the math for the player gains and losses
// Check if the player can continue et prepare for the next round
public boolean ResolveTurn() {
this.Step = 0;
// Dealer draws card until he hits 17 or more
while (this.Dealer.GetForce(0) <= 17) {
this.Dealer.DrawCard(0, this.Deck);
}
System.out.print("\033[H\033[2J");
System.out.flush();
System.out.println("*~-~* " + App.ANSI_RED + "BlackJack" + App.ANSI_RESET + " *~-~*\n");
double bet;
System.out.println("Money : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET);
// Show the remaining amount of cards in the deck
System.out.println(
"Cards in Deck : " + App.ANSI_GREEN + this.Deck.GetNbCards() + App.ANSI_RESET + "\n");
while (true) {
// Show the hand strength of the dealer
// 99 = BlackJack
// >21 = Busted
// <=21 = show the strength
System.out.print("Dealer Score : " + App.ANSI_PURPLE);
if (this.Dealer.GetForce(0) == 99) {
System.out.println("BlackJack" + App.ANSI_RESET);
} else if (this.Dealer.GetForce(0) > 21) {
System.out.println(this.Dealer.GetForce(0) + App.ANSI_RED + " [BUSTED]" + App.ANSI_RESET);
} else {
System.out.println(this.Dealer.GetForce(0) + App.ANSI_RESET);
}
System.out.print("How much do you want to bet (Min. 10) ? ");
// Show the dealers hand
this.Dealer.ShowHands();
while (!App.in.hasNextDouble()) {
System.out.println(App.ANSI_YELLOW + "Please enter a valid number to bet." + App.ANSI_RESET);
System.out.print("How much do you want to bet ?");
App.in.next();
// Check if the player has put down an insurance
if (this.Players.get(0).HasInsured()) {
System.out.println(
"Insured : " + App.ANSI_BLUE + this.Players.get(0).GetInsured() + App.ANSI_RESET);
}
bet = App.in.nextDouble();
// Go thew all hands of the player
for (int HandNb = 0; HandNb < this.Players.get(0).NbHands(); HandNb++) {
if (bet <= this.Players.get(0).GetMoney()) {
if (bet < 10) {
System.out.println(App.ANSI_YELLOW + "Minimum bid amount is 10." + App.ANSI_RESET);
System.out.println("\nHand " + App.ANSI_GREEN + (HandNb + 1) + App.ANSI_RESET + " :");
System.out.println("\tBet : " + App.ANSI_BLUE + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET);
System.out.print("\tStrength : " + App.ANSI_PURPLE);
if (this.Players.get(0).GetForce(HandNb) == 99) {
System.out.println("BlackJack" + App.ANSI_RESET);
} else if (this.Players.get(0).GetForce(HandNb) > 21) {
System.out.println(
this.Players.get(0).GetForce(HandNb) + App.ANSI_RED + " [BUSTED]" + App.ANSI_RESET);
} else {
break;
System.out.println(this.Players.get(0).GetForce(HandNb) + App.ANSI_RESET);
}
System.out.print("\tResult : ");
if (this.Players.get(0).GetForce(HandNb) > 21 && this.Players.get(0).GetForce(HandNb) != 99) {
System.out.println(App.ANSI_RED + "-" + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET);
} else if (this.Dealer.GetForce(0) == this.Players.get(0).GetForce(HandNb)) {
System.out.println(App.ANSI_BLUE + "±0" + App.ANSI_RESET);
this.Players.get(0).AddMoney(this.Players.get(0).GetBet(HandNb));
} else if (this.Players.get(0).GetForce(HandNb) == 99) {
System.out.println(App.ANSI_GREEN + "+" + (this.Players.get(0).GetBet(HandNb) * 1.5) + App.ANSI_RESET);
this.Players.get(0).AddMoney(this.Players.get(0).GetBet(HandNb) * 2.5);
} else if (this.Dealer.GetForce(0) > 21 && this.Dealer.GetForce(0) != 99) {
System.out.println(App.ANSI_GREEN + "+" + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET);
this.Players.get(0).AddMoney(this.Players.get(0).GetBet(HandNb) * 2);
} else if (this.Players.get(0).GetForce(HandNb) < this.Dealer.GetForce(0)) {
System.out.println(App.ANSI_RED + "-" + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET);
} else if (this.Players.get(0).GetForce(HandNb) > this.Dealer.GetForce(0)) {
System.out.println(App.ANSI_GREEN + "+" + this.Players.get(0).GetBet(HandNb) + App.ANSI_RESET);
this.Players.get(0).AddMoney(this.Players.get(0).GetBet(HandNb) * 2);
}
}
if (this.Players.get(0).HasInsured()) {
System.out.print("Insurance : ");
if (this.Dealer.GetForce(0) == 99) {
System.out.println(App.ANSI_GREEN + "+" + (this.Players.get(0).GetInsured() * 3) + App.ANSI_RESET);
this.Players.get(0).AddMoney(this.Players.get(0).GetInsured() * 3);
} else {
System.out.println(App.ANSI_YELLOW + "You don't have enough money." + App.ANSI_RESET);
System.out.println(App.ANSI_RED + "-" + (this.Players.get(0).GetInsured()) + App.ANSI_RESET);
}
}
Players.get(0).SetBet(bet, 0);
System.out.println("\nMoney : " + App.ANSI_BLUE + this.Players.get(0).GetMoney() + App.ANSI_RESET);
System.out.print("> ");
try {
System.in.read();
} catch (Exception e) {
}
// If the player has less than the minimum bid amount allowed
if (this.Players.get(0).GetMoney() <= 10) {
return true;
}
// If more thn 75% of the Deck has been used, reshuffle all cards. In our case:
// simply recreate a new deck
if (this.Deck.GetNbCards() < 78) {
this.Deck = new JeudeCarte(new Paquet(6, 52));
}
this.Dealer.Reset(this.Deck);
for (Joueur Player : this.Players) {
Player.Reset(this.Deck);
}
return false;
}
}
......@@ -41,6 +41,7 @@ public class Hand implements Comparable<Hand> {
public void Double() {
this.Doubled = true;
this.Bet *= 2;
}
public boolean HasSplit() {
......@@ -182,7 +183,7 @@ public class Hand implements Comparable<Hand> {
public void ShowHand() {
this.SortHand();
// this.SortHand();
for (Carte carte : Hand) {
......
......@@ -22,12 +22,14 @@ interface Joueur {
public void ShowHands();
public void Split(int handNb);
public void Split(int handNb, JeudeCarte Jeu);
public int GetForce(int handNb);
public boolean CanSplit(int handNb);
public boolean HasSplit(int handNb);
public void Reset(JeudeCarte Jeu);
public boolean HasInsured();
......@@ -38,7 +40,7 @@ interface Joueur {
public boolean HasDoubled(int handNb);
public void Double(int handNb);
public void Double(int handNb, JeudeCarte Jeu);
public int NbHands();
......@@ -81,19 +83,26 @@ class JoueurHumain implements Joueur {
return this.Hands.get(handNb).HasDoubled();
}
public void Double(int handNb) {
public void Double(int handNb, JeudeCarte Jeu) {
this.RemoveMoney(this.Hands.get(handNb).GetBet());
this.Hands.get(handNb).Double();
this.Hands.get(handNb).DrawCardFromGame(Jeu);
}
public boolean CanSplit(int handNb) {
if (!this.Hands.get(handNb).HasSplit()
&& this.Hands.get(handNb).GetCarte(0).getForce() == this.Hands.get(handNb).GetCarte(1).getForce()) {
if (!(this.Hands.get(handNb).HasSplit() && this.Hands.get(handNb).GetCarte(0).getForce() == 1)
&& this.Hands.get(handNb).GetCarte(0).getForce() == this.Hands.get(handNb).GetCarte(1).getForce()
&& this.Hands.get(handNb).NbCard() == 2) {
return true;
}
return false;
}
public boolean HasSplit(int handNb) {
return this.Hands.get(handNb).HasSplit();
}
public boolean HasInsured() {
return this.Insured;
}
......@@ -101,6 +110,7 @@ class JoueurHumain implements Joueur {
public void Insure() {
this.Insured = true;
this.Insurance = this.Hands.get(0).GetBet() / 2;
this.RemoveMoney(this.Insurance);
}
public double GetInsured() {
......@@ -137,9 +147,16 @@ class JoueurHumain implements Joueur {
}
public int GetForce(int handNb) {
if ((this.Hands.get(handNb).GetForce() == 99 && this.Hands.get(handNb).HasSplit())
|| (this.Hands.get(handNb).GetForce() == 99 && handNb != 0)
|| (this.Hands.get(handNb).GetForce() == 99 && this.Hands.get(handNb).NbCard() != 2)) {
return 21;
} else {
return this.Hands.get(handNb).GetForce();
}
}
public void SetBet(double amount, int handNb) {
if (amount <= 0) {
throw new RuntimeException("Can't bet a negative or null amount.");
......@@ -188,21 +205,26 @@ class JoueurHumain implements Joueur {
this.Hands.get(handNb).ShowHand();
}
public void Split(int handNb) {
public void Split(int handNb, JeudeCarte Jeu) {
if (this.Hands.size() == 3) {
throw new RuntimeException("Max number of slipts.");
} else if (this.Hands.get(handNb).HasSplit()) {
throw new RuntimeException("Can't split Hand twice.");
}
Carte card = this.Hands.get(handNb).GetCarte(handNb);
Carte card = this.Hands.get(handNb).GetCarte(1);
this.Hands.add(new Hand(card));
this.Hands.get(handNb).RemoveCardFromHand(card);
this.Hands.get(handNb).Splitted();
this.Hands.get(this.Hands.size() - 1).Splitted();
this.Hands.add(new Hand(card));
this.Hands.get(this.Hands.size() - 1).SetBet(this.Hands.get(handNb).GetBet());
this.RemoveMoney(this.Hands.get(handNb).GetBet());
this.Hands.get(handNb).DrawCardFromGame(Jeu);
this.Hands.get(this.Hands.size() - 1).DrawCardFromGame(Jeu);
}
public int NbHands() {
......@@ -246,20 +268,27 @@ class JoueurOrdinateur implements Joueur {
return this.Hands.get(handNb).HasDoubled();
}
public void Double(int handNb) {
public void Double(int handNb, JeudeCarte Jeu) {
this.RemoveMoney(this.Hands.get(handNb).GetBet());
this.Hands.get(handNb).Double();
this.Hands.get(handNb).DrawCardFromGame(Jeu);
}
public boolean CanSplit(int handNb) {
if (this.Hands.get(handNb).HasSplit()
|| this.Hands.get(handNb).GetCarte(0).getForce() != this.Hands.get(handNb).GetCarte(1).getForce()) {
return false;
if (!(this.Hands.get(handNb).HasSplit() && this.Hands.get(handNb).GetCarte(0).getForce() == 1)
&& this.Hands.get(handNb).GetCarte(0).getForce() == this.Hands.get(handNb).GetCarte(1).getForce()
&& this.Hands.get(handNb).NbCard() == 2) {
return true;
}
return true;
}
public boolean HasSplit(int handNb) {
return this.Hands.get(handNb).HasSplit();
}
public boolean HasInsured() {
return this.Insured;
}
......@@ -271,6 +300,7 @@ class JoueurOrdinateur implements Joueur {
public void Insure() {
this.Insured = true;
this.Insurance = this.Hands.get(0).GetBet() / 2;
this.RemoveMoney(this.Insurance);
}
public void Reset(JeudeCarte Jeu) {
......@@ -360,21 +390,26 @@ class JoueurOrdinateur implements Joueur {
this.Hands.get(handNb).ShowHand();
}
public void Split(int handNb) {
public void Split(int handNb, JeudeCarte Jeu) {
if (Hands.size() == 3) {
if (this.Hands.size() == 3) {
throw new RuntimeException("Max number of slipts.");
} else if (this.Hands.get(handNb).HasSplit()) {
throw new RuntimeException("Can't split Hand twice.");
}
Carte card = this.Hands.get(handNb).GetCarte(handNb);
Carte card = this.Hands.get(handNb).GetCarte(1);
this.Hands.add(new Hand(card));
this.Hands.get(handNb).RemoveCardFromHand(card);
this.Hands.get(handNb).Splitted();
this.Hands.get(this.Hands.size() - 1).Splitted();
this.Hands.add(new Hand(card));
this.Hands.get(this.Hands.size() - 1).SetBet(this.Hands.get(handNb).GetBet());
this.RemoveMoney(this.Hands.get(handNb).GetBet());
this.Hands.get(handNb).DrawCardFromGame(Jeu);
this.Hands.get(this.Hands.size() - 1).DrawCardFromGame(Jeu);
}
public int NbHands() {
......@@ -422,13 +457,17 @@ class JoueurCroupier implements Joueur {
throw new RuntimeException("Bank cant Double.");
}
public void Double(int handNb) {
public void Double(int handNb, JeudeCarte Jeu) {
// La Banque ne peut pas doubler
throw new RuntimeException("Bank cant Double.");
}
public boolean CanSplit(int handNb) {
// La Banque ne peut pas split
throw new RuntimeException("Bank cant Split.");
}
public boolean HasSplit(int handNb) {
// La Banque ne peut pas split
throw new RuntimeException("Bank cant Split.");
}
......@@ -504,7 +543,7 @@ class JoueurCroupier implements Joueur {
return this.Hand.GetForce();
}
public void Split(int handNb) {
public void Split(int handNb, JeudeCarte Jeu) {
// La Banque ne peut pas slip
throw new RuntimeException("Bank can't Split.");
}
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment