• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

September 2018 Project: BlackJack

 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the first project let's look into the card game
BlackJack
The rules for this game are explained here https://en.wikipedia.org/wiki/Blackjack.

This game could render okay with only using ASCII.
The rules and variations of this game are fairly well explained in the WikiPedia entry.
There could be some classes and methods which we will create which could be used in other card games.
I suspect that much of this code could be reused in for a web site or for Android or a graphical Java application.

Remember to commit your code to your own GitHub repository as needed. If nothing else this can be used as a backup for your code.

You only cheat your self if you cheat with your posts in the Corral. This is supposed to be a fun learning experience for all involved.

Your first steps with this are to think about what you need in terms of objects and how they may interact with each other.
Java is very much object oriented and thinking like this may take some getting used to.
You can choose to draw diagrams, with pen and paper or write a few lines of text.
This is when you try to visualize the system/program and what you create right now may be totally different then what the final program will be.
You can spend as little or as much time you want on this and draw very detailed diagrams or very plain ones. The choice is yours.
However you should still do this step.

I will try to get my own GitHub.com repository started in the next few days but do not expect to see too much code in there regarding this project at the moment.

Reply to this thread with your ideas and maybe your idea will help someone else out.
 
Bartender
Posts: 209
14
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I'm gonna give it a go tomorrow, are we supposed to make the complete game or should we do it step by step, design few classes for a start?

thanks
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do this all alone if you choose to or you can follow along with the Corral postings if you choose to. In the end it's up to you.
I realize that not everyone is at the same skill level and that not everyone will be able to commit the same amount of time to the project.
I will try to make at least some progress each week, and some weeks may haev more progress more then others.

The first challenge that most people have to face is planning of the project, at least in very general terms.
Java likes to use objects and object oriented programming has many different parts.

What object do You suggest be used and what properties and behaviors do you think these objects should have?
This can be small point form listing with only a few objects or this can be an extensive listing, the choice is yours.

You should try to ask yourself some questions like the following when thinking about objects:
  • What is the minimum each object should do?
  • Would/should this be an abstract class?
  • Should I create any interfaces?
  • How would I write a unit test to verify that the methods or objects work as expected?
       Many people use BDD and/or TDD which can be somewhat hard to understand/implement as noted here.

  • These objects will change over the life of the project, but you should not simply write code without doing any planning.

    Please post your listing of objects to the Corral, maybe reply to this post. In a day or two I will post a break down of the objects and their properties as I see them.
    Your objects would be how you see them and that listing could be totally different then my listing and this is 100% okay.
    In a team environment you and your teammates would probably have to at least briefly discuss (maybe in a five minute meeting) what objects you plan on making.
     
    Adrian Grabowski
    Bartender
    Posts: 209
    14
    Mac OS X IntelliJ IDE
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ok, so that's how I see it, I'm a newbie so please don't laugh

    I'm not very familiar with card games but I made following assumptions:

    - every card game will take a place at one table
    - every table will need the ability to create a new deck of cards (which will vary between types of tables, AFAIK Blackjack uses standard 52 card deck)
    - players sit at a table
    - dealer is a player (not sure about this one, might vary between different games)

    When I look at the diagram now it looks like the particular implementation of the Table interface will need to hold most of the game logic, it would need to calculate card values, deal the cards, keep the score... Hmmm I guess it would be a good idea to split it into more classes maybe? Or leave it as it is for now and refactor when it gets too big?

    Cheers



    click here to view the diagram on Lucidchart
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This is a great starting point, keep up the good work.

    Adrian Grabowski wrote:Ok, so that's how I see it, I'm a newbie so please don't laugh.

    The CodeRanch BeNice rule is in effect for all postings on CodeRanch, so no one is going to laugh.
    If or when they do they risk having their post be deleted and their account be closed.

    Adrian Grabowski wrote:AFAIK Blackjack uses standard 52 card deck.

    The rules and setup for the game are explained in the Wiki article in the first post.
    You are correct, that a 52 card deck is used, but more advanced games allow for more then one deck to be used.

    You have some great properties, but objects need to interact with each other some how using actions and behaviors.  
    Here are some possible behaviors and/or actions to think about:
  • Can any player be the dealer and what does the dealer do as they are not a normal player?
  • What does the player do as they are not the dealer?
  • How do you determine the winner of the game?
  • How do you determine the when the game is over?
  • How do you determine if the player can be dealt another card? At some point in time the player will be over 21.

  • How would you implement game rules? The least of which is how much you can bet.
    There are also different game rules and styles as list in the Wikipedia for those who want to go into more advanced programming/options.

    It is also important to not over complicate things. Sometimes you may not need an inner class or inner interface or feature x.
    Some features help with unit testing, but may not help with program design and vice versa.

    Once again, I think you have a great start and this planning phase can last anywhere from five minutes to a few hours for some projects so it is very important that this step not be skipped for any project.
    That said, it is not uncommon for the final objects/coding to not use follow the first plan all the way.
    This plan will be constantly refreshed as the needs on the project/client change and as the understanding of the project increases.

    I will post my objects definitions in a few days, which may not be the same as yours. Yours can be right, and mine can be right both at the same time because we are working on separate projects.  
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Some initial thoughts on what objects we may need and what are some of their properties:
    • Card Object:
      • Each card has a suit
      • Each card has a letter/number value
    • Deck Object:
      • Each deck as a collection of cards
      • The collection of cards could be randomly ordered or order by suit then by letter/number
    • Hand Object:
      • Each hand will have two or more cards.
      • The dealers hand will always be shown face up
    • Player Object:
      • Each player will have money for betting
      • First name
      • Other possible statistical data
      • History, even if it is only session history which is reset after each start of the program
    • Game Rules Object:
      • Each rule will affect who the game is played in some way. This could a be a good use case for interfaces
    • Game Object:
      • One dealer
      • One or more players
      • One or more decks
      • A collection of money bet on the game
      • A collection of game rules
      • History

    This is not a final listing of all the objects and their properties and this could easily change.

    My preference is to start with the smallest unit and go from there.
  • You can't have a game without any rules, players and decks.
  • Players can have names, and a collection of cards (hands).
  • Without any cards you cannot not have any hands/decks.

  • As for behaviors we need to think about things like:
  • What can a player do and what can a dealer do?
  • These are two have some common behaviors, like add card to hand, bet, win game etc.
  • However they also have unique behaviors like deal, split, shuffle, etc.

  • Aside from the dealer and the players we have other classes/objects and things to plan for.
    Also, what behavior belongs to what object? Some times a behavior could be for more then one object.
    Given that we need to make sure that they are named differently if they different behaviors or if they are the same, then maybe we need to create an interface or an abstract class.

    Usually you will discuss some of these details with other members of your team.
    These is only a snapshot into how I think about things and it may not be the same as the way you think about things which is totally fine.
     
    Rancher
    Posts: 5094
    38
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    The dealers hand will always be shown face up


    I think only one card is shown initially.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You are correct Norm, thanks.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Moving on to the next part I've started a new thread where you see some code for a few classes which you can follow along with here.

    I've broken it up to help keep things manageable for both me and anyone else who may be interested in this project.
     
    Greenhorn
    Posts: 14
    Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Pete Letkeman wrote:Moving on to the next part I've started a new thread



    Hi Pete, I'm just joining. The linked page has no content. Also, I've started looking into JavaFX, and already have a working primary scene set up with frames. Does it matter if I attempt this with a GUI? Also, I have my own Git so when I do have something going should I post the link to it here?
     
    Sheriff
    Posts: 7126
    185
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Steven Mcdonald wrote:

    Pete Letkeman wrote:Moving on to the next part I've started a new thread



    Hi Pete, I'm just joining. The linked page has no content.


    Maybe it was under construction, because there is content now.

    Also, I've started looking into JavaFX, and already have a working primary scene set up with frames. Does it matter if I attempt this with a GUI?


    Here's a challenge: if you write the character based game correctly, you should be able to reuse most of it in a JavaFX (or any GUI) program.

    Also, I have my own Git so when I do have something going should I post the link to it here?


    I'm assuming this is GitHub?  I don't see any problem with that; do you Pete?
     
    Steven Mcdonald
    Greenhorn
    Posts: 14
    Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hey all,
    I spent some time writing out much of what I might need to do this project last night, and I spent some time today starting the project. I have posted what I've done so far in My GitHub Projects if anyone is interested. I still don't see any content in the CodeRanch link for this project though, maybe I'm clicking the wrong link?
    codeRanchLinkScreenShotSmallerSize.png
    [Thumbnail for codeRanchLinkScreenShotSmallerSize.png]
    The BlackJack link in the comments.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You are correct Steven Mcdonald, the link does not work for some reason. You are most likely clicking on the correct link.
    I've asked for some help to see why it's not working as expected and hopefully soon it will be fixed.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Steven Mcdonald wrote:I've started looking into JavaFX, and already have a working primary scene set up with frames. Does it matter if I attempt this with a GUI?

    Feel free to use which every display methods/libraries that you want.
    I'm sure that there are some people on this site who are very knowledgeable with JavaFX, Swing etc.
    Personally, due to time constraints, I will not be using JavaFX or any other GUI libraries. I'm more interested in getting the engine working. Plus my JavaFX knowledge is somewhat limited.

    Knute Snortum wrote:Here's a challenge: if you write the character based game correctly, you should be able to reuse most of it in a JavaFX (or any GUI) program.

    This kind of what I had in mind and will try to keep in mind as we go.

    Sure, post you GitHub link the more we share. The more we share the better off we will all be. Your code may provide me with an idea and my code may provide someone else with an idea.
    I would prefer to keep the links to GitHub only as we know that site is a trusted site. Posting multiple files to CodeRanch may work, but I think GitHub links work a bit better in this instance.

    Steve, I briefly looked at your code and I have a few quick comments, if I may:
    - Currently you do not appear to be using any packages to organize your code, and you are using only the default unnamed Java package.
    While this may work, most people would suggest that you setup your project to have/use one or more packages.
    - It looks like you may be use eight spaces or two tabs when formatting your code. Many developers use either four spaces or one tab.
    If you are using the Google Java style standards then you may be using two spaces and no tabs.
    You will probably find that as you get nested structures that eight spaces or two tabs is a bit much.
     
    Knute Snortum
    Sheriff
    Posts: 7126
    185
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Steven Mcdonald wrote:I still don't see any content in the CodeRanch link for this project though, maybe I'm clicking the wrong link?


    Here's the link spelled out:

    https://coderanch.com/t/699340/open-source/BlackJack-Starting-code

    You can also look at the Ranch Corral's front page and find the thread there:

    https://coderanch.com/f/206/ranch-corral

    [Edit: Ah! there was an internal problem that kept non-moderators from seeing the post.  It's fixed now.]
     
    Steven Mcdonald
    Greenhorn
    Posts: 14
    Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Knute Snortum wrote:[Edit: Ah! there was an internal problem that kept non-moderators from seeing the post.  It's fixed now.]



    Thank you Knute!

    Also, I was pretty tired when I made the code in my GitHub. I went through it again and fixed a bunch of the problems I noticed. There are probably many more issues in it, as I am fairly new at this. Also, I'm not sure if all of the interfaces are a good idea, but I wanted to make reusable code so that I could make a GUI with JavaFX later on. I noticed that the code on CodeRanch is implemented differently from mine. I'm still learning best practices and the best ways to structure code. Also, my Deck class constructs cards from the Card class, is this okay? I'm not to sure about structuring it this way, as everyone always says to aim for loose coupling, and I'm not quite sure if this is considered tight in this case?
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Steven Mcdonald wrote:I noticed that the code on CodeRanch is implemented differently from mine.


    Steven, my code, right or wrong is not complete or final code. I will post a link to my github when I get some more code in there which should be better then what I've previously posted.
    I'm only a step or two a head of you Steven with regards to the Ranch Corral. This is something new to me and things could change as the project evolves.
    Currently, I do not get too much time to work on this during the weekdays thanks to work.

    Steven Mcdonald wrote:Also, my Deck class constructs cards from the Card class, is this okay? I'm not to sure about structuring it this way, as everyone always says to aim for loose coupling, and I'm not quite sure if this is considered tight in this case?


    Before you get too concerned about tight and loose coupling, do you know why you would use either of them?

    I took a quick look are your updated code:
  • It's great that you have started using packages, however it may be beneficial to use more then one package.
  • It still looks like you are using two tabs or eight spaces for code indentation. Many Java programmers choose to use four spaces or one tab.
       IDEs can usually help with this. Which IDE/editor are you using?

  • While you are waiting for me, that is if you are waiting for me you can look into unit testing.
    Some companies do not accept code until a separate unit test is created to test the code.
    Many Java developers use JUnit for unit testing, however there are other frameworks which can be as well.
     
    Steven Mcdonald
    Greenhorn
    Posts: 14
    Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Pete Letkeman wrote:
    Steven, my code, right or wrong is not complete or final code.



    I'm sorry, I meant my code. I'm brand new to Java, I took a couple of really basic classes in school a couple of years ago, but I worked 14 hours a day 7 days a week driving a truck up until about a month ago. So this is the first time I'm really able to get into it and learn properly.
    I was asking because I'm basically a clean slate. I didn't really understand even the basics of polymorphism or anything about interfaces until a few days ago when I read about it in the OCA study guide. I've crammed a few lines of code together when I had the chance, but that's
    about it. I went for a Bs in IT, which mainly covered the generals all across the field as UOPX didn't have a computer science or programming degree available online when I started. So to answer the question about coupling and cohesion, no I know of it but I don't truly understand
    when it's okay and when it's not okay. I'm going to check out JUnit 5 tonight, I've never done any unit testing. I normally use Eclipse or NetBeans, but I switched to Notepad++ a couple weeks ago to help practice/learn. Also, I always single tab, GitHub automatically re-formats the code
    to double tabs for some reason.
     
    Bartender
    Posts: 1251
    87
    Hibernate jQuery Spring MySQL Database Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I know I'm bit late to the party. I'm reading the Wiki page Pete furnished. I've no idea about cards and all therefore I played an online BlackJack game for a while just to understand how BlackJack game is played.

    I've got question, what is this hand about?  Is It about a regular player drawing cards? I got that hand's value is the sum of cards a player has drawn.  How many hands does a regular player have?

    I have never used Github and done Junit testing, I've been reading about them (for now only Github) so could be slower on my side. I've downloaded Github tutorial but It's about command line, what do you advice as I'm beginner, should I use Git GUI based Or command line?

    Since this is text based application so this will have menus like hit, stand, double, split etc. for regular player on the console? hope I'm on correct path.
     
    Knute Snortum
    Sheriff
    Posts: 7126
    185
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Ganesh Patekar wrote:I know I'm bit late to the party. I'm reading the Wiki page Pete furnished. I've no idea about cards and all therefore I played an online BlackJack game for a while just to understand how BlackJack game is played.

    I've got question, what is this hand about?  Is It about a regular player drawing cards? I got that hand's value is the sum of cards a player has drawn.  How many hands does a regular player have?


    Normally, a player has one hand -- that is, the cards they're delt.  However, now and then a player can double down and have two hands at once.

    I have never used Github and done Junit testing, I've been reading about them (for now only Github) so could be slower on my side. I've downloaded Github tutorial but It's about command line, what do you advice as I'm beginner, should I use Git GUI based Or command line?


    The way I use GitHub is partly the web-based interface and partly the character interface.  Or more properly, I use Git in character and GitHub on the web.  I don't think this is necessary though.  GitHub has a desktop UI and you could use Git from your IDE if you wanted.

    Since this is text based application so this will have menus like hit, stand, double, split etc. for regular player on the console? hope I'm on correct path.


    Sounds like you are.  I'm learning too!
     
    Ganesh Patekar
    Bartender
    Posts: 1251
    87
    Hibernate jQuery Spring MySQL Database Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Knute Snortum wrote:However, now and then a player can double down and have two hands at once.

    Ahh! ,yes we need two hands for a player when split condition is satisfied.

    I don't think this is necessary though.  GitHub has a desktop UI and you could use Git from your IDE if you wanted.

    Okay will use whichever seems easier at the moment.
     
    Bartender
    Posts: 15737
    368
    • Likes 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Even for intermediate users, I strongly recommend trying out Learn Git Branching, a great way to learn how to use the command line interface with visual aids.

    There will be times where the GUI won't do everything you need to do to get yourself out of a contrived mess, and knowing the CLI is a big help.
     
    Ganesh Patekar
    Bartender
    Posts: 1251
    87
    Hibernate jQuery Spring MySQL Database Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Even for intermediate users, I strongly recommend trying out Learn Git Branching, a great way to learn how to use the command line interface with visual aids.
    There will be times where the GUI won't do everything you need to do to get yourself out of a contrived mess, and knowing the CLI is a big help.

    Thank you  
     
    Ranch Hand
    Posts: 393
    9
    Open BSD BSD Debian
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Even for intermediate users, I strongly recommend trying out Learn Git Branching, a great way to learn how to use the command line interface with visual aids.



    Very very instructional Stephan   I wish so much  had it available when started learn about git.
    Instead for who  is clued on books (in the same vein as the .org site) as a first read i recommend   Ry's Git Tutorial  and/or Git Succinctly by Ryan Hodson  the second one is free (after signup if i remember well)


    There will be times where the GUI won't do everything you need to do to get yourself out of a contrived mess, and knowing the CLI is a big help.


    Who did administration work on machines definitely know what is his(and also git's) UI  ;)
     
    Adrian Grabowski
    Bartender
    Posts: 209
    14
    Mac OS X IntelliJ IDE
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ok, this project disintegrated quicker than Liz Truss's cabinet. Should we maybe resurrect it?
     
    Stephan van Hulst
    Bartender
    Posts: 15737
    368
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If I'm not completely mistaken, one of our members finished a pull request a couple of months ago, and I updated our code analysis tooling.

    So while the project is not very active, I wouldn't call it completely dead yet. But maybe it's time to take stock of where we are and which direction we're heading into.

    I'll take a look at our currently implemented features and our open issues, and post a summary here.
     
    Adrian Grabowski
    Bartender
    Posts: 209
    14
    Mac OS X IntelliJ IDE
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Wow, I didn't know about that at all, I've never received any notifications from github so I wrongly assumed that there was nothing happening there! Looks like I need to catch up, thanks!
     
    Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic