ftp.nice.ch/pub/next/games/card/NEXTVegas3.0.src.tar.gz#/NEXTVegas/Documentation/CardSet/CardPile.rtf

This is CardPile.rtf in view mode; [Download] [Up]

CardSet Release 2.1






CardPile 






Inherits From:	Object

Declared In:	CardPile.h





Class Description

Instances of this class provide low-level functionality for card games.  CardPiles contain an ordered list of Card objects which can be added to, removed from, or shuffled by clients of the class.

There are a bunch of methods that have been added that give a little detail about the cards contained in the CardPile.   Methods such as isFlush and isStraight give clients the ability to test a "hand" to see if they contain poker style hands like flushes and straights.  lowestCard and lowestValue return the lowest Card object and the lowest Card object's value respectively.   All of these added methods use the Card's value, rather than the Card's userValue, so you should send the pile the setAceHigh: message before using any of them.

To test for a poker hand, you should use the pokerHand method.  It tests the pile from the highest type of win to the lowest, and returns the type of poker hand it finds.  Some methods won't give you the right answer if they are tested in the wrong order.  For example, you may have a pile with a royal flush, but the isStraight and isFlush methods will still return YES, as will the isRoyalFlush method.





Instance Variables

id cardList;



cardList 	A List of Card objects in this CardPile.
cardSize 	The size of cards held by this CardPile.





Method Types

Initializing the class object	+ initialize

Creating and freeing	± free
± init
- initForCardSize:

Card size	± setCardSize:
± returnSize

Manipulating individual cards	- addCard:
- addCopyOfPile:
- addPile:
- cardAt:
- cardIndex:
- insertCard:at:
- insertCopyOfPile:at:
- insertPile:at:
- removeCard:

Manipulating the deck	- addDeck
- cardCount
- empty
- flip
- freeCards
- shuffle



Methods added for NEXTVegas	- addDecks:
- cardList
- highestCard
- highestValue
- isFlush
- isFourOfKind
- isFullHouse
- isJacksOrBetter
- isRoyalFlush
- isStraight
- isStraightFlush
- isThreeOfKind
- isTwoPair
- lowestCard
- lowestValue
- numCardsOfValue
- pokerHand
- setAceHigh:
- sortList:
- sortPile
- total
- userTotal

Archiving	- read: 
- write:





Class Methods

initialize
+ initialize

Initializes the class object.  Seeds the random number generator.  Returns self.

See also:  + initialize (Object)





Instance Methods

addCard:
- addCard:aCard

Adds Card aCard to the top of the pile.  The Card object is not copied; only its id is stored in the pile.  Returns self.

See also:  ± insertCard:at:




addDeck
- addDeck

Adds a deck of 52 cards to the top of the pile, neatly ordered.  Returns self.

See also:  ± shuffle




addDecks:
- addDeck:(int)numDecks

Adds numDecks decks of 52 cards to the top of the pile, neatly ordered.  Returns self.

See also:  ± shuffle




addPile:
- addPile:aCardPile

Adds the cards in the CardPile aCardPile to the top of the receiving pile.  The Card objects are not copied; only their ids are stored in the pile.  Returns self.

See also:  ± insertPile:at:




cardAt:
- cardAt:(int)aPosition

Returns the Card object which is located at aPosition in the CardPile.  Returns nil if there is no Card at the specified index.  The constants CS_TOP and CS_BOTTOM can be used to specify the top and bottom of the pile, respectively.

See also:  ± cardIndex:




cardCount
- (int)cardCount

Returns the number of Card objects in the pile.




cardIndex:
- (int)cardIndex:aCard

Returns the index of aCard in the CardPile.  Returns NX_NOT_IN_LIST if the card isn't in the pile.

See also:  ± cardAt:




cardList
- cardList

Returns the List object that maintains the pointers to the various Cards in the CardPile.

See also:  ± cardAt:




addCopyOfPile:
- addCopyOfPile:aPile

Allocates copies of the cards in the CardPile aPile and adds them to the top of the receiving pile.  The cards in the original pile are not modified.  Returns self.

See also:  ± insertCopyOfPile:at:




empty
- empty

Empties the card list describing the pile.  The Card objects are not freed.  Returns self.

See also:  ± freeCards




flip
- flip

Turns the pile over, reversing the order of the cards and the orientation of each card.  Returns self.




free
- free

Deallocates all the cards in the receiving pile, and the CardPile itself.  Returns nil.

See also:  ± init




freeCards
- freeCards

Empties the pile and frees all the Card objects in the pile.  Returns self.

See also:  ± empty




highestCard
- highestCard

Returns the id of the Card with the highest value in the Pile.

See also:  ± setAceHigh




highestValue
- (int)highestValue

Returns the value of the Card with the highest value in the Pile. 

See also:  ± setAceHigh




init
- init

Initializes a CardPile by calling return [self initForCardSize:CS_SMALL].

See also:  ± free




initForCardSize:
- initForCardSize:(CardSize)aSize

Initializes a CardPile to hold cards of the indicated size.  The pile will contain 0 cards.  Returns self.

Constant	Description
CS_SMALL	Small cards
CS_LARGE	Big cards

See also:  ± free




insertCard:at:
- insertCard:aCard at:(int)aPosition

Adds aCard to the pile at the position specified by aPosition.  The constants CS_TOP and CS_BOTTOM can be used to specify the top and bottom of the pile, respectively.  If you specify a value for aPosition which is greater than the number of cards in the pile, the card will not be inserted.  The Card object is not copied; only its id is stored in the pile.  Returns self.

See also: ± addCard:




insertCopyOfPile:at:
- insertCopyOfPile:aCardPile at:(int)aPosition

Allocates copies of the cards in aCardPile and adds them to the receiving pile at the position specified by aPosition.  The constants CS_TOP and CS_BOTTOM can be used to specify the top and bottom of the pile, respectively.  The cards in aCardPile are not modified.

See also: ± addCard:




insertPile:at:
- insertPile:aCardPile at:(int)aPosition

Inserts the cards in the CardPile aCardPile into the receiving pile at the position aPosition.  The constants CS_TOP and CS_BOTTOM can be used to specify the top and bottom of the pile, respectively.  The Card objects are not copied; only their ids are stored in the pile.  Returns self.

See also:  ± initSuit:value:, ± initSuit:value:faceUp:




isFlush
- (BOOL)isFlush

Returns YES if all cards in the pile are of the same suit, NO if not.

See also:  




isFourOfKind
- (BOOL)isFourOfKind

Returns YES if there are at least four cards in the pile with the same value, NO if not.

See also:  




isFullHouse
- (BOOL)isFullHouse

Returns YES if there is both a three of a kind and a two of a kind with different values, NO if not.

See also:  




isJacksOrBetter
- (BOOL)isJacksOrBetter

Returns YES if there is at least two Cards in the pile whose values are greater than CS_JACK, NO if not.

See also:    ± setAceHigh




isRoyalFlush
- (BOOL)isRoyalFlush

Returns YES if the Cards in the Pile are of the same suit and have consecutive values starting with CS_TEN, NO if not.

See also:  ± setAceHigh




isStraight
- (BOOL)isStraight

Returns YES if the Cards in the Pile have consecutive values, NO if not.

See also:  ± setAceHigh




isStraightFlush
- (BOOL)isStraightFlush

Returns YES if the Cards in the Pile have consecutive values and are of the same suite, NO if not.

See also:  ± setAceHigh




isThreeOfKind
- (BOOL)isThreeOfKind

Returns YES if at least three Cards in the Pile have the same value, NO if not.

See also:  




lowestCard
- lowestCard

Returns the id of the Card in the Pile with the lowest value.

See also:  ± setAceHigh




lowestValue
- (int)lowestValue

Returns the lowest value of the Cards in the Pile.

See also:  ± setAceHigh




numCardsOfValue:
- (int)numCardsOfValue:(int)aValue

Returns the number of Cards in the Pile whose value is aValue.

See also:  




pokerHand
- (PokerHand)pokerHand

Returns one of the following PokerHand constants, depending on the cards in the pile:

Constant	Description
CS_JACKSORBETTER	Pile has only one pair of Cards of equal value (CS_JACK or higher).
CS_TWOPAIR	Pile has two pairs of Cards of equal values.
CS_THREEOFKIND	Pile has three Cards of equal value.
CS_STRAIGHT	The Cards in the Pile have consecutive values.
CS_FLUSH	The Cards in the Pile all have the same suit.
CS_FULLHOUSE	There is one three-of-a-kind and one pair in the Pile.
CS_FOUROFKIND	Pile has four Cards of equal value.
CS_STRAIGHTFLUSH	Pile has both CS_STRAIGHT and CS_FLUSH.
CS_ROYALFLUSH	Pile has both CS_STRAIGHT and CS_FLUSH, and the highest card is a CS_ACE.
CS_NOPOKERHAND	Pile has none of the above.

See also:  ± setAceHigh




read:
- read:(NXTypedStream *)stream

Reads and returns an object of class CardPile from stream.  


 

removeCard:
- removeCard:aCard

Removes the card aCard from the pile.  The Card object is not deallocated.  Note that this is the only way to remove a card from the pile.  Returns nil if the aCard wasn't in the CardPile, otherwise returns aCard.




returnSize
- (CardSize)returnSize

Returns the current card size for this CardPile.

See also:  ± addDeck




setAceHigh
- setAceHigh

Makes all the methods such as isStraight assume that the Ace is the highest card in the deck.

See also: 




setCardSize:
- setCardSize:(CardSize)aSize

Set the size of cards the pile can hold.  If there are cards in the pile, they are set to aSize.  Returns self.

Constant	Description
CS_SMALL	Small cards
CS_LARGE	Big cards

See also:  ± initForCardSize:, - returnSize




shuffle
- shuffle

Randomly re-orders all Card objects contained in the pile.  Returns self.

See also:  ± addDeck




sortList:
- sortList:listObject

Takes the listObject, which is a list of Card objects, and sorts it with respect to the Cards' values.  Returns the sorted listObject.




sortPile
- sortPile

Re-arranges the Cards in the Pile according to their value, from lowest to highest.  Returns self;




total
- (int)total

Returns the sum of the card values in the pile.

See also:  ± userTotal




userTotal
- (int)userTotal

Returns the sum of the card user values in the pile.

See also:  ± total




write:
- write:(NXTypedStream *)stream

Writes the receiver to stream.  Returns self.


These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.