[Gamesnws-commits] r23 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Aug 11 12:36:30 CEST 2009
Author: grafab
Date: 2009-08-11 12:36:29 +0200 (Tue, 11 Aug 2009)
New Revision: 23
Modified:
pkg/R/playUno.R
Log:
getinfo-function: shows information about rules, players, cards
can be run in game with "get-info"-command
Modified: pkg/R/playUno.R
===================================================================
--- pkg/R/playUno.R 2009-08-11 09:51:16 UTC (rev 22)
+++ pkg/R/playUno.R 2009-08-11 10:36:29 UTC (rev 23)
@@ -85,10 +85,12 @@
cat(" Active Player: ",nwsFindTry(ws,'player_in_action'),"\n")
cat(" Status of penalty-var: ",nwsFindTry(ws,'penalty'),"\n")
cat(" Said Uno:",nwsFindTry(ws, 'uno'),"\n")
+ cat(" Rules:",nwsFindTry(ws, 'rules'),"\n")
+ cat(" Rulesbools:",nwsFindTry(ws, 'rulesbools'),"\n")
for(p in players){
points <- nwsFindTry(ws,'points')
uno<-nwsFindTry(ws,'uno')
- cat(" >>",p, " - (",length(nwsFindTry(ws,p))," card(s), ",points[p]," point(s), uno = ",uno[p],"<< ", sep="")
+ cat("(",p, " - (",length(nwsFindTry(ws,p))," card(s), ",points[p]," point(s), uno = ",uno[p],") ", sep="")
}
cat("\n")
}
@@ -261,7 +263,13 @@
card_play<-""
unovec[playerInAction]<-TRUE
nwsStore(ws, 'uno',unovec)
- }else if(!(card_play %in% unlist(cards_hand))){
+ }
+ else if(card_play=="get-info"){
+ # get gameinformation
+ card_play<-""
+ .getInfo(ws)
+ }
+ else if(!(card_play %in% unlist(cards_hand))){
# play a card, that is not in your hand or typing error
cat("\tCard not in your cards!\n\t'NO' for new card.\n")
card_play <- ""
@@ -473,5 +481,35 @@
}
nwsStore(ws, 'player_in_action', playerInAction)
}
-
-
\ No newline at end of file
+##########################################################
+#Function for getting Information about the game
+##########################################################
+.getInfo<-function(ws)
+{
+ require(ws)
+ maxi<- -Inf
+ mini<- Inf
+ sumi<- 0
+ counter<- 0
+ players<-nwsFindTry(ws,'players_logedin')
+ for(p in players){
+ len<-length(nwsFindTry(ws,p))
+ cat("len",len,"\n")
+ if(len > maxi){
+ maxi <- len
+ }
+ if(len < mini){
+ mini <- len
+ }
+ sumi <- sumi + len
+ counter<- counter+1
+ }
+ cat("\nGame Information:")
+ cat("\n Rules",nwsFindTry(ws,'rules'))
+ cat("\n ",nwsFindTry(ws,'rulesbools'))
+ cat("\n Cards in Deck: 102")
+ cat("\n Players in Game: ",counter)
+ cat("\n Max Cards:",maxi)
+ cat("\n Min Cards: ",mini)
+ cat("\n Average Cards: ",sumi/counter,"\n")
+}
\ No newline at end of file
More information about the Gamesnws-commits
mailing list