Deck of Cards

By Callison1 on Jul 20, 2007

Shuffles a deck of cards and places them in a random order in a text file. Useful for card game scripts.

Fully tested.

Type /cards and it will write the cards in the correct order into card.txt, type deck1 to shuffle them and write into deck.txt.

;Randomly Places 52 Numbers
alias deck1 {
  if (( $exists(deck.txt) )) write -c deck.txt
  var %b
  :deckstart
  var %a = $rand(1,52)
  if (( $read(deck.txt, wt, %a) != $null )) goto deckstart
  write deck.txt %a
  inc %b
  if (( %b != 52 )) goto deckstart
  deck2
}
;Replaces the 52 Numbers with the correspondent card names (refering to card.txt, see below)
alias deck2 {
  if (( !$exists(deck.txt) )) halt
  var %c = 1
  while (( %c <= 52 )) {
    write -s $+ %c deck.txt $read(card.txt,%c)
    inc %c
  }
}
;Moves the top card to the bottom (Might be useful)
alias cardmove {
if (( !$exists(deck.txt) )) deck1
  var %d = $read(deck.txt,1)
  write -dl1 deck.txt
  write deck.txt %d
}
;This just places the card names in the correct order into a file which 'deck2' refers to in placing the cards. 
alias cards {
  if (( $exists(card.txt) )) write -c card.txt
  write card.txt Ace Of Spades
  write card.txt Two Of Spades
  write card.txt Three Of Spades
  write card.txt Four Of Spades
  write card.txt Five Of Spades
  write card.txt Six Of Spades
  write card.txt Seven Of Spades
  write card.txt Eight Of Spades
  write card.txt Nine Of Spades
  write card.txt Ten Of Spades
  write card.txt Jack Of Spades
  write card.txt Queen Of Spades
  write card.txt King Of Spades
  write card.txt Ace Of Clubs
  write card.txt Two Of Clubs
  write card.txt Three Of Clubs
  write card.txt Four Of Clubs
  write card.txt Five Of Clubs
  write card.txt Six Of Clubs
  write card.txt Seven Of Clubs
  write card.txt Eight Of Clubs
  write card.txt Nine Of Clubs
  write card.txt Ten Of Clubs
  write card.txt Jack Of Clubs
  write card.txt Queen Of Clubs
  write card.txt King Of Clubs
  write card.txt Ace Of Diamonds
  write card.txt Two Of Diamonds
  write card.txt Three Of Diamonds
  write card.txt Four Of Diamonds
  write card.txt Five Of Diamonds
  write card.txt Six Of Diamonds
  write card.txt Seven Of Diamonds
  write card.txt Eight Of Diamonds
  write card.txt Nine Of Diamonds
  write card.txt Ten Of Diamonds
  write card.txt Jack Of Diamonds
  write card.txt Queen Of Diamonds
  write card.txt King Of Diamonds
  write card.txt Ace Of Hearts
  write card.txt Two Of Hearts
  write card.txt Three Of Hearts
  write card.txt Four Of Hearts
  write card.txt Five Of Hearts
  write card.txt Six Of Hearts
  write card.txt Seven Of Hearts
  write card.txt Eight Of Hearts
  write card.txt Nine Of Hearts
  write card.txt Ten Of Hearts
  write card.txt Jack Of Hearts
  write card.txt Queen Of Hearts
  write card.txt King Of Hearts
}

Comments

Sign in to comment.
Olliegod   -  Jul 21, 2007

Perhaps you could include a function to move a card from position X to position Y. Not sure how useful it would be, but I suppose someone could find a use for it.

 Respond  
Anti   -  Jul 21, 2007

Callison where can i find you at are you on right now?

 Respond  
Callison1   -  Jul 21, 2007

Oh sorry, type /cards and it will write the cards in the correct order into card.txt, the deck1 to shuffle them and write into deck.txt.

 Respond  
Anti   -  Jul 20, 2007

One question how do i get it to start XD :D

 Respond  
napa182   -  Jul 20, 2007

i like this idea =)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.