[Gamesnws-commits] r19 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 10 13:31:27 CEST 2009
Author: grafab
Date: 2009-08-10 13:31:23 +0200 (Mon, 10 Aug 2009)
New Revision: 19
Modified:
pkg/R/playUno.R
Log:
penalty-function instead of many calls
.getpenalty(ws,number of penaltycards, player who should get penalty, reasonnumber)
reasonnumber:
0 = no special reason
1 = player forgot to say uno
2 = player said uno without playing his second-last card
Modified: pkg/R/playUno.R
===================================================================
--- pkg/R/playUno.R 2009-08-10 10:35:10 UTC (rev 18)
+++ pkg/R/playUno.R 2009-08-10 11:31:23 UTC (rev 19)
@@ -103,16 +103,14 @@
# PENALTY
# TODO change for reaction to penalty cards
if( played_number =='2+'&& nwsFind(ws, 'penalty') == FALSE){
- cat("You got 2 penalty cards\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'), nwsFetchTry(ws,'cards'))
+ .getpenalty(ws,2,user,0)
nwsStore(ws, user, cards_hand)
nwsStore(ws, 'penalty', TRUE)
}
if( played_number =='rygb4+' && nwsFindTry(ws, 'penalty') == FALSE){
- cat("You got 4 penalty cards\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'), nwsFetchTry(ws,'cards'),nwsFetchTry(ws,'cards'), nwsFetchTry(ws,'cards'))
- nwsStore(ws, user, cards_hand)
+ .getpenalty(ws,4,user,0)
+ nwsStore(ws, user, cards_hand)
nwsStore(ws, 'penalty', TRUE)
}
cards_hand <- nwsFindTry(ws, user)
@@ -271,15 +269,12 @@
nwsStore(ws, user, cards_hand)
# play card
nwsStore(ws, 'played', card_play_save)
- if(length(cards_hand) == 1 && !unovec[playerInAction]){
- cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ if(length(cards_hand) == 1 && !unovec[playerInAction]){
+ .getpenalty(ws,2,user,1)
nwsStore(ws, user, cards_hand)
}
- else if(length(cards_hand) != 1 && unovec[playerInAction]){
- cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ else if(length(cards_hand) != 1 && unovec[playerInAction]){
+ .getpenalty(ws,2,user,2)
nwsStore(ws, user, cards_hand)
}
unovec[playerInAction]<-FALSE
@@ -299,15 +294,12 @@
nwsStore(ws, user, cards_hand)
# play card
nwsStore(ws, 'played', card_play_save)
- if(length(cards_hand) == 1 && !unovec[playerInAction]){
- cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ if(length(cards_hand) == 1 && !unovec[playerInAction]){
+ .getpenalty(ws,2,user,1)
nwsStore(ws, user, cards_hand)
}
- else if(length(cards_hand) != 1 && unovec[playerInAction]){
- cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ else if(length(cards_hand) != 1 && unovec[playerInAction]){
+ .getpenalty(ws,2,user,2)
nwsStore(ws, user, cards_hand)
}
unovec[playerInAction]<-FALSE
@@ -328,15 +320,12 @@
nwsStore(ws, user, cards_hand)
# play card
nwsStore(ws, 'played', card_play_save)
- if(length(cards_hand) == 1 && !unovec[playerInAction]){
- cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ if(length(cards_hand) == 1 && !unovec[playerInAction]){
+ .getpenalty(ws,2,user,1)
nwsStore(ws, user, cards_hand)
}
- else if(length(cards_hand) != 1 && unovec[playerInAction]){
- cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ else if(length(cards_hand) != 1 && unovec[playerInAction]){
+ .getpenalty(ws,2,user,2)
nwsStore(ws, user, cards_hand)
}
unovec[playerInAction]<-FALSE
@@ -357,15 +346,12 @@
nwsStore(ws, user, cards_hand)
# play card
nwsStore(ws, 'played', card_play_save)
- if(length(cards_hand) == 1 && !unovec[playerInAction]){
- cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ if(length(cards_hand) == 1 && !unovec[playerInAction]){
+ .getpenalty(ws,2,user,1)
nwsStore(ws, user, cards_hand)
}
- else if(length(cards_hand) != 1 && unovec[playerInAction]){
- cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ else if(length(cards_hand) != 1 && unovec[playerInAction]){
+ .getpenalty(ws,2,user,2)
nwsStore(ws, user, cards_hand)
}
unovec[playerInAction]<-FALSE
@@ -397,15 +383,12 @@
nwsStore(ws, user, cards_hand)
# play card
nwsStore(ws, 'played', card_play_save)
- if(length(cards_hand) == 1 && !unovec[playerInAction]){
- cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ if(length(cards_hand) == 1 && !unovec[playerInAction]){
+ .getpenalty(ws,2,user,1)
nwsStore(ws, user, cards_hand)
}
- else if(length(cards_hand) != 1 && unovec[playerInAction]){
- cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ else if(length(cards_hand) != 1 && unovec[playerInAction]){
+ .getpenalty(ws,2,user,2)
nwsStore(ws, user, cards_hand)
}
unovec[playerInAction]<-FALSE
@@ -426,15 +409,12 @@
nwsStore(ws, user, cards_hand)
# play card
nwsStore(ws, 'played', card_play_save)
- if(length(cards_hand) == 1 && !unovec[playerInAction]){
- cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ if(length(cards_hand) == 1 && !unovec[playerInAction]){
+ .getpenalty(ws,2,user,1)
nwsStore(ws, user, cards_hand)
}
- else if(length(cards_hand) != 1 && unovec[playerInAction]){
- cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ else if(length(cards_hand) != 1 && unovec[playerInAction]){
+ .getpenalty(ws,2,user,2)
nwsStore(ws, user, cards_hand)
}
unovec[playerInAction]<-FALSE
@@ -461,15 +441,12 @@
# play card
nwsStore(ws, 'played', card_play_save)
- if(length(cards_hand) == 1 && !unovec[playerInAction]){
- cat("2 penalty-cards, because you forgot to say \"uno\"!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ if(length(cards_hand) == 1 && !unovec[playerInAction]){
+ .getpenalty(ws,2,user,1)
nwsStore(ws, user, cards_hand)
}
- else if(length(cards_hand) != 1 && unovec[playerInAction]){
- cat("1 penalty-card, because you said \"uno\" without having a reason!\n")
- cards_hand <- c(cards_hand, nwsFetchTry(ws,'cards'))
+ else if(length(cards_hand) != 1 && unovec[playerInAction]){
+ .getpenalty(ws,2,user,2)
nwsStore(ws, user, cards_hand)
}
unovec[playerInAction]<-FALSE
@@ -529,4 +506,23 @@
pointsvec[p]<-handsum
}
nwsStore(ws,'points',pointsvec)
+}
+#########################################################
+#Function for giving penalties
+#########################################################
+.getpenalty <- function(ws,number,playerInAction,reasonnumber)
+{
+ require(nws)
+ reason<-""
+ if(reasonnumber==1){
+ reason<-", because you forgot to say \"uno\""
+ }else if(reasonnumber==2){
+ reason<-", because you said \"uno\" without having a reason"
+ }
+ cards_hand<-nwsFindTry(ws, playerInAction)
+ for(i in 1:number){
+ cards_hand<-c(cards_hand, nwsFetchTry(ws,'cards'))
+ }
+ cat("You got ",number," penalty card(s)",reason,"!\n")
+ nwsStore(ws,playerInAction,cards_hand)
}
\ No newline at end of file
More information about the Gamesnws-commits
mailing list