Jump to content

  • Log In with Google      Sign In   
  • Create Account

Planning Code for Blackjack Game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Chad Smith   Members   -  Reputation: 1137

Like
0Likes
Like

Posted 20 April 2013 - 02:29 PM

QUICK NOTE: The language in C++, though for code design don't think it matters that much.  Just wanted to point that out if someone had a better design or language feature for me.

 

I wanted to see if I could get a review or some advice on my current plan and code design right now. This is my first time to really go and try to design classes, functions, and members that I'll need for a game or a project.  So I wanted to try to start with a "simple" game that I've created before but wanted to try to plan out the code before I actually started working on the code.  Even though I do want a "proper" design and want suggestions for that, my main thing is really is their anything glaring wrong that I will need to look out for?  Anything else you see that I need to add?  Even though I am sure when the coding does actually start I'll see some things that I need to add or change.

 

I didn't create a UML diagram for it, but really made a table for the classes I need and a table for each class listing each member and a brief description why I need it.  I plan to try to create a simple UML diagram for it when I get the time to read up and find a good editor to help create a UML diagram.

 

Anyway here are my tables (just quick screenshots)

Black_Jack_Code_Design1.png
 
Black_Jack_Code_Design2.png
 
 
Quick walk through and thoughts behind some of it.
Hand Class: I tried to represent cards as real-life cards.  A Hand is a collection of cards.  After thinking about how cards are in real life I thought that we don't copy a card when you deal it.  The card is moved.  That for me made me store the collection of Cards as a vector of Card pointers.  When Cards are moved from Hand to another the pointers will be copied and destroyed. I am unsure if this would be abusing the use of Dynamic Memory.  When I Clear I am pretty sure this would ask for me to iterate through all the cards and delete the current iterator.  I feel I could be abusing and not using Dynamic Memory in a proper place.  Maybe some help here or help me visualize it different, as I only see cards moving and not actually be copying in real life?
 
Generic Player: I wanted to create an abstract base class to store the common functionality of a human player and computer player.  Felt like it would be easier to allow multiple types of players this way.  I at first thought a player was really just a hand in the game, but after thinking about it more I wanted it to be that a player and hand is a Has A Relationship, so I every player will store a hand
 
Player: Just the functionality that a human player has
 
ComputerPlayer: Just the functionality that a computer player has.  Their will always be one ComputerPlayer, being the House
 
Deck: Just a standard deck of 52 cards.  The Deck deals the cards to the players.  Because it deals the same way to each player I use GenericPlayer so it works for both human players and computer players.
 
 
That's just some quick thoughts that I had.  What do y'all think?  Some things I should look at?
 
NOTE: This will just be a basic Blackjack game to work on planning out my code.  Players won't be able to bet, raise or anything like that right now.  Just a simple game of Blackjack where the player can play a round or two.
 
 
 
 
 

Edited by Chad Smith, 20 April 2013 - 02:47 PM.


Sponsor:

#2 AllEightUp   Moderators   -  Reputation: 4216

Like
0Likes
Like

Posted 20 April 2013 - 10:02 PM

Nothing looks particularly wrong here.  I'd actually say it is way over thought out at this point simply because the problem is so small in scope.  Practicing planning is one thing, drawing up the above when it basically encompasses the entire game and you could probably have a testbed functional by now, that's another thing.  The rules are down right simple and you've probably written up more planning than there is actual code needed to implement it.  I don't mean to offend, just trying to be practical.  :)



#3 Chad Smith   Members   -  Reputation: 1137

Like
0Likes
Like

Posted 20 April 2013 - 11:50 PM

Nothing looks particularly wrong here.  I'd actually say it is way over thought out at this point simply because the problem is so small in scope.  Practicing planning is one thing, drawing up the above when it basically encompasses the entire game and you could probably have a testbed functional by now, that's another thing.  The rules are down right simple and you've probably written up more planning than there is actual code needed to implement it.  I don't mean to offend, just trying to be practical.  smile.png

No offense taken at all and I'd normally agree.  One reason I wanted to try to do it this way is to try to create something that would allow to expand on it later on.  I always felt my code on my projects has been entirely too hard coded.  So I wanted to try to work on something.

 

Thanks for comment though!  If anyone has any suggestion or comments then I am still all ears.



#4 AllEightUp   Moderators   -  Reputation: 4216

Like
0Likes
Like

Posted 21 April 2013 - 11:40 AM

Nothing looks particularly wrong here.  I'd actually say it is way over thought out at this point simply because the problem is so small in scope.  Practicing planning is one thing, drawing up the above when it basically encompasses the entire game and you could probably have a testbed functional by now, that's another thing.  The rules are down right simple and you've probably written up more planning than there is actual code needed to implement it.  I don't mean to offend, just trying to be practical.  smile.png

No offense taken at all and I'd normally agree.  One reason I wanted to try to do it this way is to try to create something that would allow to expand on it later on.  I always felt my code on my projects has been entirely too hard coded.  So I wanted to try to work on something.

I think the problem is that BlackJack, as a testbed for your experimentation, is a bit too simple.  The only real complexities are doubling down and splitting which I didn't see in the outline.  I would think a more complex card game, perhaps poker, would give you considerably more to work with without being too much.  It is just a thought.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS