blackjack

initializer-string for array of chars is too long error

喜夏-厌秋 提交于 2020-05-25 07:26:25
问题 I am working on a BlackJack Game using C++, and I have the following piece of code within it where I am getting an error typedef struct { int value; char suit[8]; char name[8]; }Deck; Deck Cards[52] = {{ 1,"Ace","Hearts"},{ 2, "Two","Hearts"}, { 3, "Three", "Hearts"}, { 4, "Four","Hearts"}, { 5,"Five","Hearts"},{ 6,"Six", "Hearts06"}, { 7,"Seven","Hearts"},{ 8,"Eight","Hearts"},{ 9,"Nine","Hearts"},{ 10,"Ten","Hearts"},{10,"Jack","Hearts"},{10,"Queen","Hearts"},{10,"King","Hearts"}, { 1,"Ace"

Array for Blackjack cards, strings or integers?

无人久伴 提交于 2019-12-30 07:33:05
问题 Having a look at related BlackJack questions, there is a confusion on what is better to use for the cards, either making an array of strings/items or integers. With my BlackJack game Aces are 11 only and 10, J, Q and K are all value 10, doesn't matter of the suit. What would make it easier for me to code the cards with, strings or integers? Visual Studio C# 2010, Windows form application 回答1: A Card is an object, so make it its own class. An enum of Suit (Heart, Diamond, Club, Spade) and an

Is there an elegant way to deal with the Ace in Blackjack?

对着背影说爱祢 提交于 2019-12-17 16:34:05
问题 My kiddo had a homework assignment to write Blackjack in Java. I helped him a little but for the most part he did it all himself and it actually plays pretty well. He even caught an error I didn't see in how it was calculating hand values. However, there is a snag that he hasn't dealt with and every solution I can think of is really complicated and way beyond what he's going to be able to easily code up with his still rudimentary Java skills. The Ace. In fact, not just one Ace, there's four

Rework blackjack game

依然范特西╮ 提交于 2019-12-13 06:54:37
问题 I'm trying to create a blackjack game, where the player starts off with 2 cards, and then asked if he/she would like to have another card (user input: yes or no), if yes, another card is added to the total. if no, the game just terminates. Here is a sample output I'm trying to get: And this is what I have so far (It's probably wrong in terms of the placement): import java.util.Scanner; public class BlackJackGame { public static void main(String[] args) { int randomnum1 = (int) (1 + Math

BlackJack Program, string value issue

此生再无相见时 提交于 2019-12-13 03:43:29
问题 I'm in the midst of creating a BlackJack program. I'm currently in the "number checking" process. So once the cards have been dealt and the player asks for a "Hit" I need to check if the cards they have exceed, 21. I tried this : if(pCard1+pCard2+pCard3 > 21) System.out.println("Bust!"); But it soon came to my realization that because my card array is an array of strings, I cannot use mathematical operators to check wether or not the cards exceed 21. I was wondering if there was anyway to

Assigning int value to string

前提是你 提交于 2019-12-12 18:25:08
问题 I'm designing a Black Jack program. My issue is that, I use a switch case to generate a random card. But when it comes time to compare the value of the cards....lets say if(pCard1 + pCard2 > 21) it's not allowing me to compare them because they are strings. However, they need to be strings because I have to be able to assign String "Queen" but I also need "Queen" to have an int value of 10. I'm not sure how to go about this. Here's what I have so far. I'm not including my entire code because

I (think) I'm getting objects returned when I expect my array to have just 2 properties available

微笑、不失礼 提交于 2019-12-11 13:17:20
问题 Probably the worst way to ask a question, but I'm new and trying my best to explain my problem. I'm implementing a Ruby Blackjack game. You can see the repo / source for what I have here: https://bitbucket.org/subem81/blackjack This is the particular section of concern (kept in the "Hand" module which is included in the Dealer and Player classes using what I think are mixins): def show_hand if self.class.to_s == 'Dealer' self.hand.each do |card| card.show_card end elsif self.class.to_s ==

python only show tuple items in loop x amount of times

青春壹個敷衍的年華 提交于 2019-12-11 11:51:25
问题 I need help finding a python function that will only show the value in the tuple, (x) amount of times. from random import * rankName = ("Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King") suit = ("hearts", "diamonds", "spades" , "clubs") users = ("I", "computer", "deck") NUMCARDS = 52 DECK = 0 PLAYER = 1 COMP = 2 count = 0 while (count < 52): for u in rankName: for i in suit: count = count + 1 w = choice(users) ''' 'computer' and 'I' should

Convert an array into an ArrayList [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-03 18:28:14
问题 This question already has answers here : Create ArrayList from array (33 answers) Closed 6 years ago . I'm having a lot of trouble turning an array into an ArrayList in Java. This is my array right now: Card[] hand = new Card[2]; "hand" holds an array of "Cards". How this would look like as an ArrayList ? 回答1: As an ArrayList that line would be import java.util.ArrayList; ... ArrayList<Card> hand = new ArrayList<Card>(); To use the ArrayList you have do hand.get(i); //gets the element at

How to add the values of two “Cards” in Java?

泪湿孤枕 提交于 2019-12-02 16:48:33
问题 I am working on a project to simulate the first deal in a game of blackjack. So far, the program creates two cards of random rank (ACE to KING) and random suit. I am struggling with created a switch table or if-else ladder assign the added value of the two cards as a variable score. The code below represents conceptually what I am trying to do, I just want to know how to make it simpler. Thanks! public int Score() { int score = 0; if (card1.rank() == TWO && card2.rank() == TWO){ score = 4; }