Card Aliases

By LIQUID_NiTrO on Jun 23, 2005

Couple of aliases dealing with cards. These were made for blackjack.
The first is $addcards(value1,...,valueN) which adds the values of the cards, evaluating any letter other than an A to be a facecard (worth 10) and gives you the best possible hand value.
The second is $cardn(NumSuit) which, I don't know if anyone would consider useful, but takes input such as "2Hearts" or "JSpades" and converts it to "2 of Hearts" or "Jack of Spades". You can specify the .value property to make it evaluate the above two examples to "2" and "10", respectively, which is useful for providing input to $addcards.

alias addcards {
  var %x = 1,%o = $0,%g = 0,%aces = 0
  while ( %x <= %o ) {
    %i = $($+($,%x),2)
    if ( %i isnum ) {
      %g = $calc(%g + %i)
      inc %x 1
      continue
    }
    elseif ( %i != A ) {
      %g = $calc(%g + 10)
      inc %x 1
      continue
    }
    if ( $calc(%g + 11) > 21 ) {
      %g = $calc(%g + 1)
    }
    else {
      %g = $calc(%g + 11)
      inc %aces 1
    }
    inc %x 1
  }
  while ( %g > 21 && %aces ) {
    %g = $calc(%g - 11)
    dec %aces 1
  }
  return %g
}
alias cardn {
  if ( $prop == value ) {
    if ( A* iswm $1 ) {
      return A
    }
    elseif ( $left($1,1) isalpha || $left($1,2) == 10 ) {
      return 10
    }
    else {
      return $left($1,1)
    }
  }
  if ( $left($1,1) isalpha ) {
    if ( A* iswm $1 ) {
      return Ace of $right($1,$calc($len($1) - 1))
    }
    elseif ( K* iswm $1 ) {
      return King of $right($1,$calc($len($1) - 1))
    }
    elseif ( Q* iswm $1 ) [
      return Queen of $right($1,$calc($len($1) - 1))
    }
    elseif ( J* iswm $1 ) {
      return Jack of $right($1,$calc($len($1) - 1))
    }
    else {
      return 0
    }
  }
  else {
    return $iif($left($1,2) isnum,$left($1,2) of $right($1,$calc($len($1) - 2)),$left($1,1) of $right($1,$calc($len($1) - 1)))
  }
}

Comments

Sign in to comment.
aeros   -  Jun 25, 2005

wats the point of this? some irc card game..?

 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.