I am a little confused with how to get this method to determine what the best choice is for the number of aces that should be counted as 1 or 11. I will post the method and the code so you can run it. Any help is greatly appreciated - public static int weHaveAces(int player[], int deal[])
-
{
-
int plyttl = 0;
-
-
for(int x = 0; x < player.length - 1;x++)
-
-
{
-
plyttl += player[x];
-
System.out.println(plyttl);
-
}
-
int bestttl = plyttl;
-
for(int z = 0; z <= player[2];z++)
-
{
-
//System.out.println(( plyttl - (10*z)));
-
//System.out.println(21 - plyttl);
-
while((21 - ( plyttl - 10*z)) < 21 - plyttl)
-
{
-
-
bestttl = (plyttl - 10*z);
-
//System.out.println(bestttl);
-
//System.out.println("test"+ z);
-
}
-
}
-
-
-
Whole Code:
-
-
/*Jordan Feldman
-
Pitt BlackJack
-
4/5/2010*/
-
-
import javax.swing.JOptionPane;
-
-
class BlackJack
-
{
-
public static void main(String args[])
-
{
-
int playerCard1 = 0, playerCard2 = 0, dealerCard1 = 0, dealerCard2 = 0, playerAces = 0, dealerAces = 0;
-
-
int[] playerCards = new int [3];// Creates an int array with 3 positions
-
-
makeDeck(playerCards);
-
-
playerCard1 = playerCards[0];
-
playerCard2 = playerCards[1];
-
playerAces = playerCards[2];
-
-
int[] dealerCards = new int [3];// Creates an int array with 3 positions
-
-
makeDeck(dealerCards);
-
-
dealerCard1 = dealerCards[0];
-
dealerCard2 = dealerCards[1];
-
dealerAces = dealerCards[2];
-
-
-
printMethod(playerCards,dealerCards);
-
firstLogic(playerCards,dealerCards);
-
-
}
-
-
public static void makeDeck(int cards[])
-
{
-
int y = 0;
-
-
for(int x = 0;x < 2; x++)
-
{
-
cards[x] = 1;//(int)(Math.random()* 13 +1); //Generates a random value between 1-13
-
if (cards[x] == 11 || cards[x] == 12 || cards[x] == 13)
-
{
-
cards[x] = 10;
-
}
-
else if (cards[x] == 1)
-
{
-
cards[x] = 11;
-
++y;
-
-
}
-
}
-
cards[2] = y;
-
//System.out.println(cards[2]);
-
}
-
public static void printMethod(int playerCards[], int dealerCards[])
-
{
-
String name;
-
-
int x = playerCards[0];
-
int y = playerCards[1];
-
int playerTotal = x + y;
-
-
System.out.println("Welcome to the River's Casino!");
-
name = JOptionPane.showInputDialog("What is your name?");
-
System.out.println("Let's play BlackJack " + name + ".\n");
-
-
System.out.println("The dealer:\n? + "+ dealerCards[1] + "\n");
-
-
System.out.println("You:\n" + playerCards[0] + " + " + playerCards[1] + " = " + playerTotal);
-
int plyttl = weHaveAces(playerCards,dealerCards);
-
System.out.println("Your best choice is " + plyttl);
-
-
}
-
public static void firstLogic(int player[], int dealer[])
-
{
-
int acecnt;
-
if(dealer[2] >= 1 || player[2] >= 1)
-
{
-
// weHaveAces(player,dealer);
-
}
-
else
-
{
-
noAces(player,dealer);
-
}
-
}
-
public static int weHaveAces(int player[], int deal[])
-
{
-
int plyttl = 0;
-
-
for(int x = 0; x < player.length - 1;x++)
-
-
{
-
plyttl += player[x];
-
System.out.println(plyttl);
-
}
-
int bestttl = plyttl;
-
for(int z = 0; z <= player[2];z++)
-
{
-
//System.out.println(( plyttl - (10*z)));
-
//System.out.println(21 - plyttl);
-
while((21 - ( plyttl - 10*z)) < 21 - plyttl)
-
{
-
-
bestttl = (plyttl - 10*z);
-
//System.out.println(bestttl);
-
//System.out.println("test"+ z);
-
}
-
}
-
-
return bestttl;
-
-
}
-
-
-
-
public static void noAces(int ply[], int deal[])
-
{
-
-
}
-
-
-
}
1 1905
I would:
1. Have a flag that says whether you have an ace or not.
2. Count the aces as 1 to the total.
3. When you display the total,
- Check if you have an ace
- Check if the total is < 11.
If so, add 10 to the 'displayed' total.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Good Time Tribe |
last post by:
I'm an aspiring game programmer. I'm more experienced with pascal, c++,
and Java so I naturally love what c# offers and want to learn it. I
also wanted to start with something simple, to kind of...
|
by: f pemberton |
last post by:
I have a string (xdata) and theres a newline after every 17 characters
of the string. I was wondering how I can replace multiple substrings
multiple times within a string? To put it another way,...
|
by: mturner64 |
last post by:
Trying to link my Samsung BlackJack phone to my laptop to achieve internet access. When I plug the phone into the laptop the computer recognizes the BlackJack but I do not know how to configure one...
|
by: Gaijinco |
last post by:
Hi my name is Carlos Obregón and I'm currently a profesor of C/C++
programming at the CUMD in Bogotá Colombia.
This last term I ask my students to develop an implementation of the
minesweeper...
|
by: EXotiX |
last post by:
hey im new to vb6 and I am making a blackjack game but can not randomize the array correctly. Could you help please
Option Explicit
Const NumItems As Integer = 53
Public Sub RandomizeCards()...
|
by: Martin Marcher |
last post by:
Hello,
having worked quite a bit with python in the last months (some Java
before, and some C++ before that) I was very impressed by an idea the
Java people had.
Explanation: the JSRs define...
|
by: Marc 'BlackJack' Rintsch |
last post by:
On Thu, 28 Aug 2008 09:13:00 -0700, SUBHABRATA wrote:
a1, a2, a2, …, a20? You must be kidding. Please stop numbering names
and use *meaningful* names instead!
Could you describe them...
|
by: AEB |
last post by:
Hello, my supervisor has requested that I write a program to display
2D waves in 3D using Python. Basically I have a time series file that
has the heights of the wave over time steps, and I want...
|
by: imran akhtar |
last post by:
i have a balckjack code, which does not seem to run, in python, it comes up with syntax error, i have try sortng it out. does not seem to work. below is my code, if anyone can work out wht wrong...
|
by: imran akhtar |
last post by:
hi, i am making black jack code, but i am stuck, i have made start, but for reason gettin errors, which i dont seem be able to fix, below is my code wht i started.
import random
deck = *4...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |