473,396 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with determining Straight code

8
Hi I have a poker program...

My code for Pair, 2 pair etc work, except when I code for a straight hand

When I separate the sort function like below I can get it...
Expand|Select|Wrap|Line Numbers
  1.  public void straight()
  2.    {
  3.       int locations[] = new int[ 5 ], z = 0;
  4.  
  5.       for ( int y = 0; y < numbers.length; y++ )
  6.  
  7.          if ( numbers[ y ] == 1 )
  8.             locations[ z++ ] = y;
  9.  
  10.       bubbleSort( locations );
  11.  
  12.       int faceValue = locations[ 0 ];
  13.  
  14.       for ( int m = 1; m < locations.length; m++ ) {
  15.  
  16.          if ( faceValue != locations[ m ] - 1 )
  17.             return;   // not a straight
  18.  
  19.          else
  20.             faceValue = locations[ m ];
  21.       }
  22.  
  23.       output += "Straight ";
  24.       status.setText( output );
  25.    }
  26.  
  27.    // sort hand in ascending order
  28.    private void bubbleSort( int values[] )
  29.    {
  30.       for ( int pass = 1; pass < values.length; pass++ )
  31.  
  32.          for ( int comp = 0; comp < values.length - 1; comp++ )
  33.  
  34.             if ( values[ comp ] > values[ comp + 1 ] ) {
  35.                int temp = values[ comp ];
  36.                values[ comp ] = values[ comp + 1 ];
  37.                values[ comp + 1 ] = values[ comp ];
  38.             }
  39.    }
I tried to eliminated the separate call to bubble sort and passed parameters cleverly write the straight code as such:

Expand|Select|Wrap|Line Numbers
  1.  public void straight( Card hand[] )
  2.    {
  3.       int locations[] = new int[ 5 ];
  4.       int z = 0;
  5.       int numbers[] = totalHand( hand );
  6.  
  7.       for ( int y = 0; y < numbers.length; y++ )
  8.       {
  9.          if ( numbers[ y ] == 1 )
  10.             locations[ z++ ] = y;
  11.       } // end for
  12.  
  13.       int faceValue = locations[ 0 ];
  14.  
  15.       if ( faceValue == 0 ) // special case, faceValue is Ace
  16.       {
  17.          faceValue = 13;
  18.  
  19.          for ( int m = locations.length - 1; m >= 1; m-- ) 
  20.          {
  21.             if ( faceValue != locations[ m ] + 1 )
  22.                return; // not a straight
  23.             else
  24.                faceValue = locations[ m ];
  25.          } // end if
  26.       } // end if
  27.       else
  28.       {
  29.          for ( int m = 1; m < locations.length; m++ ) 
  30.          {
  31.             if ( faceValue != locations[ m ] - 1 )
  32.                return; // not a straight
  33.             else
  34.                faceValue = locations[ m ];
  35.          } // end if
  36.       } // end else
  37.  
  38.       System.out.println( "Straight" );
  39.    } // end method straight
This code does not appear to work- do any of you see where the translation went wrong..J
Apr 1 '07 #1
0 1124

Sign in to post your reply or Sign up for a free account.

Similar topics

49
by: Mark Hahn | last post by:
As we are addressing the "warts" in Python to be fixed in Prothon, we have come upon the mutable default parameter problem. For those unfamiliar with the problem, it can be seen in this Prothon...
35
by: Dr.Tube | last post by:
Hi there, I have this web site (www.DrTube.com) which has the following DTD: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> which switches...
7
by: addled | last post by:
Hi there, after reading posts here for a few months, I've built the courage to see if someone can see where I"m going wrong in the webpage I've been working on. In particular the horizontal nav...
1
by: Tim Marshall | last post by:
I hope someone can help me with an extrodinarily vexing problem. I've searched Google high and wide and tried a number of methods for determining if the current user is part of a specified group...
4
by: Gav | last post by:
Hi all, I'm having this strange problem where, in a web app, I have 2 different links to a different form. One is just a straight forward link the other is a bit more complicated because it gets...
11
by: wASP | last post by:
Hi, I've got a pair of int properties in a class. The properties in question are indexing values - but that's not relevant to my problem - or it's just symptomatic ... sort of. They are...
17
by: Gabriel Zachmann | last post by:
Is it correct to say that the typical ownership problem, which frequently arises in C++, does not occur normally in Python? Best regards, Gabriel. --...
73
by: Markus | last post by:
Hi, I can't understand why this code causes a "memory read exception" at int x=**a; void pass(int** a) { int x=**a; } void main()
15
by: sandy123456 | last post by:
At the moment im trying to write a hand class for a game poker patientnce But when i get to the part having to catergorise the difference of full house straight flush flush four of a kind and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.