Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Baccarat {
- public static void main(String[] args) {
- //We create Player, Banker and the pack
- Pack pack = new Pack();
- BaccaratHand player = new BaccaratHand();
- BaccaratHand banker = new BaccaratHand();
- //First card is dealt to Player and Banker
- player.addCard(pack.dealCard());
- banker.addCard(pack.dealCard());
- //Second card is dealt to Player and Banker
- player.addCard(pack.dealCard());
- banker.addCard(pack.dealCard());
- if(player.isNatural()){
- System.out.println("The Player Wins due to the Natural Hand");
- }else if(banker.isNatural()){
- System.out.println("The Banker Wins due to the Natural Hand");
- }else{
- //Player asks for cards following its strategy
- while(player.totalPoints()<=5){
- System.out.println("Player asks for an extra card");
- player.addCard(pack.dealCard());
- }
- //Banker stays if Player's hand total is greater than 9; otherwise he asks for cards
- if(player.totalPoints()<=9){ //Player does not exceed 9
- while(banker.totalPoints()<9 && banker.totalPoints()<player.totalPoints()){
- System.out.println("Banker asks for an extra card");
- banker.addCard(pack.dealCard());
- }
- }
- //Final score is computed and the winner is announced
- double pointsP = player.totalPoints();
- double pointsB = banker.totalPoints();
- if(pointsP<=9 && (pointsB>9 || pointsP>pointsB)){
- System.out.println("Player wins with "+player+" ("+ pointsP+" points). Banker has "+ banker+" ("+pointsB+" points)");
- }else if (pointsB<=9){
- System.out.println("Banker wins with "+banker+" ("+ pointsB+" points). Player has "+ player+" ("+pointsP+" points)");
- }else{
- System.out.println("Nobody wins: Player "+ player+" ("+pointsP+" points) and Banker "+ banker +" ("+pointsB+" points) exceed 7.5");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment