Playing cards: Difference between revisions

(Pari/GP)
Line 1,634:
!Card class methods!
initialize
suits ifNil: [ suits := ('clubs,hearts,spades,diamonds' subStrings: $,) ].
pips ifNil: [ pips := ('2,3,4,5,6,7,8,9,10,jack,queen,king,ace' subStrings: $,) ]
!
new
Line 1,661:
!Card methods!
initWithPip: aPip andSuit: aSuit
( (pips includes: (aPip asLowercase)) &
(suits includes: (aSuit asLowercase)) )
ifTrue: [
thePip := (aPip copy).
theSuit := (aSuit copy)
] ifFalse: [ 'Unknown pip or suit' displayOn: stderr .
Character nl displayOn: stderr ].
Line 1,674:
!
display
(self asString) display
!
displayNl
Line 1,699:
init
deck := OrderedCollection new.
(Card suits) do: [ :suit |
(Card pips) do: [ :pip |
deck add: (Card new: { pip . suit })
]
Line 1,709:
!
shuffle
1 to: (self deck size) do: [ :i |
|r2 o|
r2 := (Random between: 1 and: (self deck size)).
o := (self deck) at: i.
(self deck) at: i put: ((self deck) at: r2).
(self deck) at: r2 put: o
].
^self
Anonymous user