• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Five Card Draw Poker Game Registering 6+ cards

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this wednesday I decided to make a poker game since I thought I knew everything I needed to make to make it. then I ran into the attached error. The first place where it says "your new hand is" should say your cards from 2 to ace. but if you look at the numbers there are two tens. The following code is whats responsible for changing these numbers. Sorry for the messy code. also sorry it is so long, but it is divided into 5 almost identical parts. I just dont understand why this is occuring. it should subtract whatever it adds.

problem.PNG
[Thumbnail for problem.PNG]
error
 
Sheriff
Posts: 7070
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's very hard to read your code, especially when the first thing is an uninitialized variable. Is this all in one method? Break it out into smaller methods. Also, repeated code should be put in a method and called. Just doing this is going to make your code easier to debug.
 
Marshal
Posts: 68966
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And get rid of those switch blocks. They can probably be replaced by the appropriate data structure.
 
joseph Anderson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah really sorry about how hard it is to read. I was just trying to get it done and didn't separate it into different methods, this is approximately lines 500 to 1000 out of 1200 in my program, its technically not repeated each repeat is checking a different variable. but this is the only block where the card counters are decreased and before the program run that I went through with the picture I've never had any added just had problems with keeping cards from previous hand so I figured the problem was probably here. all variables have been initialized. and I realize that the error would be next to impossible to find. but I'm thinking it is almost definitely a logical error. If you want I can upload the whole problem, but I figured even 500 lines of code is stretching what is reasonable.

edit: oh and the reason I am using switch statements is they are easy to use. also why not use them. If they serve the purpose they were meant for and are easy to read it does its job.
 
Campbell Ritchie
Marshal
Posts: 68966
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

joseph Anderson wrote: . . . its technically not repeated each repeat is checking a different variable. . . .

No, that is repeated code which you are pretending is different on each occasion

. . . switch statements . . . are easy to use. . . . they serve the purpose they were meant for and are easy to read it does its job.

Are you trying to tell us those blocks are easy to read? Each consists of 14 13 repeated lines, and squeezing the code together into single lines makes it more difficult to read.
 
lowercase baba
Posts: 12834
52
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is repeated code, even if you do use a different variable:


it should be put into a method where you pass in your four variables one after another (hmmm...maybe that suggests a loop)
 
joseph Anderson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I just went over it with my brother, and when I told him that I only used one method/class he said "how did you even do that", he was kinda surprised at the lack of methods and thought it could be condensed to about a third the total volume. He did however give me an idea for how to solve the issue, though it will take several hundred lines of code which I don't feel like putting in right now. instead of reducing as I am putting the cards into the deck do the card scoring right before the hand scoring.

I appreciate your help. And will put this as solved.
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic