GIDForums  

Go Back   GIDForums > Computer Programming Forums > Miscellaneous Programming Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Jun-2006, 08:29
davis
 
Posts: n/a

Coding Contest #1


The challenge is to produce code that:

1: reads a file of two "poker" hands
2: outputs whether hand 1 or hand 2 is the winner (or if there is a tie)
3: use the best 5 cards of the seven per hand in calculating the value of the hand.
4: output the "string reason" result of the two hands (eg: Straight beats Three of a Kind)


The file will be two hands per line as follows:

kc 5s 6d 4h ks 3h 4s qc ah jh ac 5d 10d 6h
jc 6c qh 4h 3c 9h 10s qs 8d 6s 6h 7s 4d 4c
6d 2c js 3c jd 10s ad 5d 9d 4d jh as 9h 6h
as 5s ks kh 6s 9h 8s js 7h 4d kd 10c 3s qc
10s 9h ks 6c 9c 6d 2s 6h 8h 2d 4d 4c js qd
4d 5c 3c 10h as 3h qs 9c 2c 4c 7d ks kh 6h
jc qd 7s 3d 6c ad qc 8d 4c 9h qh 10h 2c 10s
10d 4c 2h 10s 7d ah 9c 4s 2c 6s 4d 6h ad 10h
..etc..

Where the first hand is the first 7 "cards" and the second hand is the second set of 7 "cards." The card symbols are decoded as follows:

xxy : where x or xx is the face value of the card and the y is the suit of the card.

a,k,q,j,10,9,8,7,6,5,4,3,2 are valid face values
s = spades, d = diamonds, c = clubs, h = hearts are valid suits

as = ace of spades
10d = 10 of diamonds, etc.

No wild cards can be accepted and no illegal hands such as two of the same card can be accepted. Any line read in containing an "illegal hand" should produce an appropriate error message and continue processing subsequent lines, if any exist.

The "ac" (Ace of Clubs) and all others in the file should be processed case-insensitively! That means that:

ac
Ac
aC
AC

...are all treated equally and appropriately!

Standard Poker ranking will be used (order highest to lowest):

Straight Flush
A straight flush is the best natural hand. A straight flush is a straight (5 cards in order, such as 5-6-7-8-9) that are all of the same suit. As in a regular straight, you can have an ace either high (A-K-Q-J-10) or low (5-4-3-2-1). However, a straight may not 'wraparound'. (Such as K-A-2-3-4, which is not a straight). An Ace high straight-flush is called a Royal Flush and is the highest possible hand.

Four of a Kind
Four of a kind is simply four cards of the same rank. If there are two or more hands that qualify, the hand with the higher-rank four of a kind wins.

Full House
A full house is a three of a kind and a pair, such as K-K-K-5-5. Ties are broken by the three of a kind. So K-K-K-2-2 beats Q-Q-Q-A-A, which beats Q-Q-Q-J-J.

Flush
A flush is a hand where all of the cards are the same suit, such as J-8-5-3-2, all of spades.

Straight
A straight is 5 cards in order, such as 4-5-6-7-8. An ace may either be high (A-K-Q-J-10) or low (5-4-3-2-1). However, a straight may not 'wrap around' (such as Q-K-A-2-3, which is not a straight). When straights tie, the highest straight wins. (AKQJ10 beats KQJ109 down to 5432A). If two straights have the same value (AKQJ10 vs AKQJ10) they are a tie.

Three of a Kind
Three cards of any rank, matched with two cards that are not a pair (otherwise it would be a Full House). Highest three of a kind wins.

Two Pairs
This is two distinct pairs of card and a 5th card. The highest pair wins ties. If both hands have the same high pair, the second pair wins. If both hands have the same twp pairs, the highest 5th card wins.

Pair
One pair with three distinct cards. High card breaks ties.

High Card
This is any hand which doesn't qualify as any one of the above hands. If no hand has a pair or better, then the highest card wins. If multiple hands tie for the highest card, they look at the second highest, then the third highest, etc., until the tie is broken or declared a tie by way of all 5 cards. High card is also used to break ties when the high hands both have the same type of hand (pair, flush, straight, etc.).
Note that no suit is superior to any other. All suits are of equal ranking. Therefore a straight in spades and a straight in hearts are equal if the face values of the straights are the same.

as 2s 3s 4s 5s == ah 2h 3h 4h 5h (result is a tie!)

--Challenge entries should use only standard C or standard C++ code/libraries.
Challengers should declare the language used based on the type of file extensions used in their code.

--For example, if ".c" files are used, then it will be assumed that the entry is a C language entry.

--If ".cpp" files are used, then it will be assumed that it is a C++ language entry.

--Entries should provide a README.TXT file that indicates any steps used to build and link the code into an executable.

--Entries should declare the following at the top of the README.TXT

AUTHOR: <your GIDForums username> <your first and last real name>
COPYRIGHT: I hereby place this work that I have authored into the public domain and in the process abandon all copyright protection. <those exact words>
PLATFORM: <operating system/version>
TOOLCHAIN: <preprocessor/compiler/linker version information>
LANGUAGE: <the programming language used for the entry>
LEVEL: <your programming level Beginner/Intermediate/Advanced>
BUILD: <steps required to build/link your code into an executable>
DESIGN: <statements describing your design and your implementation decision making process>

Note that it will be assumed that a file called "hands.txt" will be available in the same path as the executable and that the executable will perform its intended work on that file. The file may contain any number of "hand lines." Your entry should be prepared to deal with hands.txt files of any size including zero lines.

Intermediate and Advanced entries must accept the "hands.txt" by default as well as a command line filename parameter using -f <filename.ext>

All entries should continue processing the file containing hands information until the end of the file. Any errors encountered by Intermediate and Advanced entries should be dealt with accordingly and processing resumed, if possible.

Execution points will be awarded on the overall quality of the application to perform the task(s). HINT: Proper handling of input and output is essential here!

Style points will be awarded on the coding format and consistency of style rather than the preferred coding style of the author. HINT: Be consistent in your style! (Intermediate and Advanced, well-formatted console output will be a big plus!)

Performance points will be awarded and all entries will be judged against the same "hands.txt" file that will be generated at the end of the entry deadline. A sample hands.txt file will be provided. HINT: Linked application file size (10%) and execution speed (90%) will be judged in this category!

Portability points will be awarded and all entries will be (attempted) compiled and executed on a Windows XP system and a Linux 2.6.x kernel-based system. HINT: No platform-specific headers! (such as stdafx.h, dos.h, etc.)

Design points will be awarded based on the general simplicity and straight-forwardness of the design along points given for the judged ease of maintaining the entry code over time. HINT: Appropriate use of comments will definitely be a plus!

Grading Scale Specifics:

For Beginner entries the following grading scale will apply:

Execution: 80% of total
Style: 5% of total
Performance: 5% of total
Portability: 5% of total
Design: 5% of total

For Intermediate entries the following grading scale will apply:

Execution: 50% of total
Style: 15% of total
Performance: 10% of total
Portability: 10% of total
Design: 15% of total

For Advanced entries the following grading scale will apply:

Execution: 20% of total
Style: 20% of total
Performance: 20% of total
Portability: 20% of total
Design: 20% of total

--Your real first and last name won't be published from your README.TXT file unless you ASK for it to be published with it or if you add your first and last name inside of your code files other than README.TXT. The requirement for first/last name is for the authenticity of the public domain statement only.

--Judge(s) will ask (if needed) questions about your entry through the GIDForums private message interface. Please endeavor to respond in a timely manner as without clarification, your entry may be more difficult to judge!

--Only one entry per GIDForums member per programming language. Maximum 2 entries per GIDForums member. No changes may be made after an entry is submitted for judging.

--Entries will be posted for all to see after the end of the entry deadline.

--Points awarded and calculated standings will be posted in highest to lowest order for all entries received in all three categories and for both languages.

--Winners will be announced in each of the three skill levels and for both languages.

--One overall winner will be announced and that person shall be tasked with coming up with the next coding challenge within 2 weeks to keep things rolling.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Contest Paramesh Miscellaneous Programming Forum 76 30-Jun-2006 12:18
Pls help in this coding. harsha C++ Forum 5 08-Apr-2004 20:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:27.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.