Alpha Cards Game Script (Updated and fixed bugs)

By manish17 on Feb 08, 2017

Playing cards is always fun , so here comes a new card game made by me : Alpha Cards. The game is played between three players and as of now , it works good. Please comment if you find any bug.

How To Play?

Two cards of each alphabet are taken , so there are 52 cards in total. There are 3 players. Each player is given 5 cards.
You will be having 5 cards in this game. When your turn comes , you can draw a card . After you draw a random card , you have to throw another card of your choice.
Also, you can take the card thrown by the previous player if you wish and the card thrown by you can be taken by the next player.
The objective is to get 5 consecutive letters using one and only one vowel . Eg : M N O P Q
You cannot use two vowels . Otherwise, you can also win by getting a set of 5 vowels : A E I O U
Commands are : !draw to draw a random card , !pick to pick the last thrown card. , !throw to throw a card. and !check to check a hand.

Special thanks to Jamie for helping me with the validation part..

Here goes the snippet :-

############################################################
##          Alpha Cards Game                      ##
##             Version: 1.0                              ##
##             By: manish17                              ##
##             irc.lucidchat.net #LoveLife                 ##
############################################################

ON *:LOAD: {
set %owner $input(Enter name of the bot owner:,e)
var %j = 1
 var %i = 65
while ( %j <= 2  ) {
while (  %i <= 90 ) {
write card.txt $chr( %i )
inc %i
}
inc %j
set %i 65
}

}
alias validateCards {
  var %file = $+(",$1-,"), %x = 1 , %vowel = 0, %vowels = A.E.I.O.U, %chr, %y, %l
  filter -ffct 1 32 %file %file
  while ($read(%file,%x)) {
    %l = $ifmatch
    if ($istok(%vowels,%l,46)) inc %vowel
    if (!%y) || ($calc(%y + 1) == $asc(%l)) %y = $asc(%l)
    else return $false
    inc %x
  }

   if (%vowel == 1) || (%vowel = $calc(%x - 1)) return $true
 return $false
}

on *:text:!cards*:#: {
  if ( %p1 == $null ) && ( %p2 == $null ) && ( %p3 == $null )  {
    set %p1 $nick
    msg $chan 10 $nick has started a game of Alpha Cards! Type !joincard to join . 
    msg $chan 6 Type !cardrules to see the rules of this game before you start playing.
  }
}

on *:text:!joincard*:#: {
  if (%p1 == $null) && (%p2 == $null) && (%p3 == $null)  {
    notice $nick 3 Please start a game first by writing !joincard .
  }
  if (%p1 != $null) && (%p2 == $null) && (%p3 == $null) && ( $nick != %p1) {
    set %p2 $nick
    msg $chan 13 $nick has joined the game! One more player needed.
  }
  if (%p1 != $null) && (%p2 != $null) && (%p3 == $null) && ( $nick != %p2 ) {
    set %p3 $nick
    msg $chan 9 $nick has joined the game. The game may be started now.
    copy
    give

    cardsone
    cardstwo
    cardsthree
    set %turn 1 
    set %checked 0
    set %throw 0
    set %threw 0
    set %check 0
    set %drawn 0

    msg $chan 13 Its %p1 's turn to start the game . they has to !draw a random card from the remaining cards.
  }
}

alias copy {
  var %a = 1 
  while ( %a <= 52) { 
    %b = $read(card.txt, %a )
    write cards.txt %b
    inc %a
  }
} 
alias give { 
  var %i = 1
  var %j = 1
  var %k = 1
  while (%i <= 5) {
    set %x $read(cards.txt,n)
    %y = $readn $+
    write -dl $+ %y cards.txt
    write pl1.txt %x
    inc %i
  }
  while (%j <= 5) {
    set %x $read(cards.txt,n)
    %y = $readn $+
    write -dl $+ %y cards.txt
    write pl2.txt %x
    inc %j
  }
  while (%k <= 5) {
    set %x $read(cards.txt,n)
    %y = $readn $+
    write -dl $+ %y cards.txt
    write pl3.txt %x
    inc %k
  }

}

on *:text:!draw*:#: {
  if ( %turn == 1 ) && ( $nick == %p1 ) && ( %drawn == 0 ) { 
    set %x $read(cards.txt,n)
    %y = $readn $+
    write -dl $+ %y cards.txt 
    write pl1.txt %x  

    notice $nick 3 You picked up 6,15 $upper( %x )  . 

    cardsone
    msg $chan 13 $nick drew a random card. Now they must !throw another card as they has 6 cards atm . 
    set %throw 1 
    notice $nick 10 Please throw a card by typing !throw followed by the letter of the card you want to throw.
    set %drawn 1
  } 

  if ( %turn == 2 ) && ( $nick == %p2 ) && ( %drawn == 0 ) { 
    set %x $read(cards.txt,n)
    %y = $readn $+
    write -dl $+ %y cards.txt 
    write pl2.txt %x 

    notice $nick 3 You picked up 6,15 $upper( %x )  . 

    cardstwo
    msg $chan 13 $nick drew a random card. Now they must throw another card as they has 6 cards atm.
    set %throw 2
    notice $nick 10 Please throw a card by typing !throw followed by the letter of the card you want to throw.
    set %drawn 1
  } 

  if ( %turn == 3 ) && ( $nick == %p3 ) && ( %drawn == 0 ) { 
    set %x $read(cards.txt,n)
    %y = $readn $+
    write -dl $+ %y cards.txt 
    write pl3.txt %x  

    notice $nick 3 You picked up 6,15  $upper( %x )  .

    cardsthree
    msg $chan 13 $nick drew a random card. Now they must throw another card as they has 6 cards atm.
    set %throw 3
    notice $nick 10 Please throw a card by typing !throw followed by the letter of the card you want to throw.
    set %drawn 1
  } 

  set %check 2
}

on *:text:!throw*:#: {
  if ( %turn == 1 ) && ( %throw == 1 ) && ( $nick == %p1) { 
    if ( $read(pl1.txt, w, $2 ) {
      %y = $readn $+ 
      write -dl $+ %y pl1.txt 
      set %throwcard $2
      msg $chan 3  $nick threw the card  6,15 $upper( $2 )  . 

      cardsone
      set %turn 2 
      set %threw 1
      cardstwo
      msg $chan 13 Its %p2   's turn now . they may choose to !draw a random card , !pick a card if one was thrown recently or !check if his hand is complete.
    }
    else {
      notice $nick 14  You do not have that card.
    }
  }

  if ( %turn == 2 ) && ( %throw == 2 )  && ( $nick == %p2) { 
    if ( $read(pl2.txt, w, $2 ) {
      %y = $readn $+ 
      write -dl $+ %y pl2.txt 
      set %throwcard $2
      msg $chan 3 $nick threw the card 6,15 $upper( $2 )  . 

      cardstwo
      set %turn 3
      set %threw 1 
      cardsthree
      msg $chan 13 Its  %p3   's turn now . they may choose to !draw a random card , !pick a card if one was thrown recently or !check if his hand is complete.

    }
    else {
      notice $nick 14 You do not have that card.
    }

  }

  if ( %turn == 3 ) && ( %throw == 3 )  && ( $nick == %p3) { 
    if ( $read(pl3.txt, w, $2 ) {
      %y = $readn $+ 
      write -dl $+ %y pl3.txt 
      set %throwcard $2
      msg $chan 3  $nick threw the card 6,15 $upper( $2 )  . 

      cardsthree
      set %turn 1
      set %threw 1
      cardsone
      msg $chan 13  Its %p1  's turn now . they may choose to !draw a random card , !pick a card if one was thrown recently or !check if his hand is complete.
    }
    else {
      notice $nick 14  You do not have that card.
    }
  }
  set %check 1 
  set %drawn 0
}

on *:text:!pick*:#: {

  if ( %turn == 1 ) && ( $nick == %p1 ) && ( %threw == 1 ) && ( %throwcard != $null) && ( %drawn == 0 ) { 
    msg $chan 3 $nick picked up the card 6,15 $upper( %throwcard )   .10 Now they has 6 cards, so they must be throwing one away. 
    write pl1.txt %throwcard 

    set %throw 1 
    set %threw 0
    set %drawn 1

    cardsone
    notice $nick 3 Please throw a card by typing !throw followed by the letter of the card you want to throw.
  }

  if ( %turn == 2 ) && ( $nick == %p2 ) && ( %threw == 1 ) && ( %drawn == 0 ) { 
    msg $chan 3  $nick picked up the card 6,15 $upper( %throwcard )   .10 Now they has 6 cards, so they must be throwing one away.
    write pl2.txt %throwcard 

    set %throw 2
    set %threw 0
    set %drawn 1

    cardstwo
    notice $nick 3 Please throw a card by typing  !throw  followed by the letter of the card you want to throw.
  }

  if ( %turn == 3 ) && ( $nick == %p3 ) && ( %threw == 1 ) && ( %drawn == 0 ) { 
    msg $chan 3  $nick picked up the card 6,15 $upper( %throwcard )   . 10Now they has 6 cards, so they must be throwing one away.
    write pl3.txt %throwcard 

    set %throw 3
    set %threw 0
    set %drawn 1

    cardsthree
    notice $nick 3 Please throw a card by typing  !throw  followed by the letter of the card you want to throw.
  }
  set %check 2 
}

alias cardsone { 

  if ( $lines(pl1.txt) == 6 ) { 
    notice %p1 Your cards are :- 6,15   $read(pl1.txt, n, 1)    6,15  $read(pl1.txt, n, 2)   6,15  $read(pl1.txt, n, 3)   6,15  $read(pl1.txt, n, 4)   6,15  $read(pl1.txt, n, 5)      6,15  $upper( $read(pl1.txt, n, 6) )  
  }
  else {
    notice %p1 Your cards are :-  6,15  $read(pl1.txt, n, 1)  6,15  $read(pl1.txt, n, 2)  6,15  $read(pl1.txt, n, 3)  6,15  $read(pl1.txt, n, 4)  6,15  $read(pl1.txt, n, 5)  
  }
}

alias cardstwo { 

  if ( $lines(pl2.txt) == 6 ) { 
    notice %p2 Your cards are :- 6,15  $read(pl2.txt, n, 1)  6,15  $read(pl2.txt, n, 2)  6,15  $read(pl2.txt, n, 3)  6,15  $read(pl2.txt, n, 4)  6,15 $read(pl2.txt, n, 5)     6,15  $read(pl2.txt, n, 6)  
  }
  else {
    notice %p2 Your cards are :-  6,15  $read(pl2.txt, n, 1)  6,15  $read(pl2.txt, n, 2)  6,15  $read(pl2.txt, n, 3)  6,15  $read(pl2.txt, n, 4)  6,15  $read(pl2.txt, n, 5)  
  }
}

alias cardsthree { 

  if ( $lines(pl3.txt) == 6 ) { 
    notice %p3 Your cards are :- 6,15  $read(pl3.txt, n, 1)  6,15  $read(pl3.txt, n, 2)  6,15  $read(pl3.txt, n, 3)  6,15  $read(pl3.txt, n, 4)  6,15 $read(pl3.txt, n, 5)     6,15  $read(pl3.txt, n, 6)  
  }
  else {
    notice %p3 Your cards are :-  6,15  $read(pl3.txt, n, 1)  6,15  $read(pl3.txt, n, 2)  6,15  $read(pl3.txt, n, 3)  6,15  $read(pl3.txt, n, 4)  6,15  $read(pl3.txt, n, 5)  
  }
}

on *:text:!check*:#: {

  if ( $nick == %p1) && ( %turn == 1 ) && ( %check == 1 ) {

    checkone
  }

  if ( $nick == %p2) && ( %turn == 2 ) && ( %check == 1 ) {

    checktwo
  }
  if ( $nick == %p3) && ( %turn == 3 ) && ( %check == 1 ) {

    checkthree
  }
}

alias checkone { 
   if ($validateCards(pl1.txt)) { set %checked 1 }
  if ( %checked == 1 ) { 

    msg $chan 6 %p1 has won the game with his cards :- 6,15 $upper( $read(pl1.txt, n, 1) )   6,15 $upper( $read(pl1.txt, n, 2) )   6,15 $upper( $read(pl1.txt, n, 3) )   6,15 $upper( $read(pl1.txt, n, 4) )   6,15 $upper( $read(pl1.txt, n, 5) )
    msg $chan 4 The other hands were : %p2 : 6,15  $upper( $read(pl2.txt, n, 1) )   6,15 $upper( $read(pl2.txt, n, 2) )   6,15 $upper( $read(pl2.txt, n, 3) )   6,15 $upper( $read(pl2.txt, n, 4) )   6,15 $upper( $read(pl2.txt, n, 5) )
   msg $chan 6 %p3 : 6,15 $upper( $read(pl3.txt, n, 1) )   6,15 $upper( $read(pl3.txt, n, 2) )  6,15 $upper( $read(pl3.txt, n, 3) )  6,15 $upper( $read(pl3.txt, n, 4) )  6,15 $upper( $read(pl3.txt, n, 5) )

    gamehalt
  }
  else { 
    msg $chan 4 %p1 checked his cards , but it did not seem to match . Its %p2 's turn to play now. they may choose to !draw a random card , !pick a card if one was thrown recently or !check if his hand is complete.
    set %turn 2
    cardstwo
  }
}

alias checktwo { 
  if ($validateCards(pl2.txt)) { set %checked 1 }

        if ( %checked == 1 ) { 

    msg $chan 6 %p2 has won the game with his cards  :-  6,15  $upper( $read(pl2.txt, n, 1) )   6,15 $upper( $read(pl2.txt, n, 2) )   6,15 $upper( $read(pl2.txt, n, 3) )   6,15 $upper( $read(pl2.txt, n, 4) )   6,15 $upper( $read(pl2.txt, n, 5) )
    msg $chan 4 The other hands were : %p1 :  6,15 $upper( $read(pl1.txt, n, 1) )   6,15 $upper( $read(pl1.txt, n, 2) )   6,15 $upper( $read(pl1.txt, n, 3) )   6,15 $upper( $read(pl1.txt, n, 4) )   6,15 $upper( $read(pl1.txt, n, 5) )
   msg $chan 6 %p3 : 6,15 $upper( $read(pl3.txt, n, 1) )   6,15 $upper( $read(pl3.txt, n, 2) )  6,15 $upper( $read(pl3.txt, n, 3) )  6,15 $upper( $read(pl3.txt, n, 4) )  6,15 $upper( $read(pl3.txt, n, 5) )

     gamehalt
  }
  else { 
    msg $chan 4 %p2 checked his cards, but it did not seem to match . Its %p3 's turn to play now. they may choose to !draw a random card , !pick a card if one was thrown recently or !check if his hand is complete.
    set %turn 3
    cardsthree
  }
}
alias checkthree { 
if ($validateCards(pl3.txt)) { set %checked 1 }

  if ( %checked == 1 ) {

    msg $chan 6 %p3 has won the game with his cards :-  6,15 $upper( $read(pl3.txt, n, 1) )   6,15 $upper( $read(pl3.txt, n, 2) )  6,15 $upper( $read(pl3.txt, n, 3) )  6,15 $upper( $read(pl3.txt, n, 4) )  6,15 $upper( $read(pl3.txt, n, 5) )
    msg $chan 4 The other hands were : %p1 :  6,15 $upper( $read(pl1.txt, n, 1) )   6,15 $upper( $read(pl1.txt, n, 2) )   6,15 $upper( $read(pl1.txt, n, 3) )   6,15 $upper( $read(pl1.txt, n, 4) )   6,15 $upper( $read(pl1.txt, n, 5) )
  msg $chan 6 %p2 :  6,15  $upper( $read(pl2.txt, n, 1) )   6,15 $upper( $read(pl2.txt, n, 2) )   6,15 $upper( $read(pl2.txt, n, 3) )   6,15 $upper( $read(pl2.txt, n, 4) )   6,15 $upper( $read(pl2.txt, n, 5) )

    gamehalt
  }
  else { 
    msg $chan 4 %p3 checked his cards but it did not seem to match. Its %p1 's turn now. they may choose to !draw a random card , !pick a card if one was thrown recently or !check if his hand is complete.
    set %turn 1 
    cardsone
  }
}

alias gamehalt { 
  remove pl1.txt
  remove pl2.txt
  remove pl3.txt 
  unset %p1
  unset %p2
  unset %p3
  remove cards.txt 
  msg $chan 10 Game has been finished. . Well played guys!
  unset %throwcard
}

on *:text:!cardrules*:#: {
  notice $nick Two cards of each alphabet are taken , so there are 52 cards in total. There are 3 players. Each player is given 5 cards.
  notice $nick You will be having 5 cards in this game. When your turn comes , you can draw a card . After you draw a random card , you have to throw another card of your choice.
  notice $nick Also, you can take the card thrown by the previous player if you wish and the card thrown by you can be taken by the next player. 
  notice $nick The objective is to get 5 consecutive letters using one and only one vowel . Eg :  6,15 M  6,15 N  6,15 O  6,15 P  6,15 Q  . 
  notice $nick You cannot use two vowels . Otherwise, you can also win by getting a set of 5 vowels :  6,15 A  6,15 E  6,15 I  6,15 O  6,15 U
  notice $nick Commands are : !draw to draw a random card , !pick to pick the last thrown card. , !throw to throw a card. and !check to check a hand.
}

on *:text:!stopcards*:#: {
  remove pl1.txt
  remove pl2.txt
  remove  pl3.txt 
  unset %p1
  unset %p2
  unset %p3
  remove cards.txt 
  unset %throwcard
  msg $chan 3 Game has been stopped.
}

on *:text:!replace*:#: {
if ( $nick == %owner ) {
if ( $2 == $null ) { notice $nick Please name the player whom you want to swap . } 
elseif ( $3 == $null ) { notice $nick Please name the new player who will be playing. } 

elseif ( $2 == %p1 ) { 
msg $chan 6 $3 will be playing in place of $2 now. 
set %p1 $3
cardsone 
} 

elseif ( $2 == %p2 ) { 
msg $chan 6 $3 will be playing in place of $2 now. 
set %p2 $3 
cardstwo 
} 

elseif ( $2 == %p3 ) { 
msg $chan 6 $3 will be playing in place of $2 now. 
set %p3 $3
cardsthree
} 

else { notice $nick $2 is not playing the game. } 
} 

Comments

Sign in to comment.
rayofsun   -  Oct 29, 2017

hello, because after a while the letters are no longer played?

 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.