[Gamesnws-commits] r21 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 10 15:56:43 CEST 2009


Author: grafab
Date: 2009-08-10 15:56:43 +0200 (Mon, 10 Aug 2009)
New Revision: 21

Modified:
   pkg/R/adminUno.R
   pkg/R/playUno.R
Log:
Rules could be choosed at the beginning.
WC-rule = wildcard must not be the uno-card
BB-rule = wildcards must not be laid on each other(not implemented)
PC-rule = Penalties can be concatenated(not implemented)

Modified: pkg/R/adminUno.R
===================================================================
--- pkg/R/adminUno.R	2009-08-10 12:43:49 UTC (rev 20)
+++ pkg/R/adminUno.R	2009-08-10 13:56:43 UTC (rev 21)
@@ -18,7 +18,9 @@
 	nwsDeclare(ws, 'penalty', 'single')	#if one player got penalty but can not play a card, next player should not get penalty too
 	nwsDeclare(ws, 'debug' , 'single') 	# boolean for debug-mode
 	nwsDeclare(ws, 'points', 'single') 	# vector of points, in order of players_logedin
-	nwsDeclare(ws, 'uno' , 'single')  #vector of uno-booleans, in order of players_logedin 
+	nwsDeclare(ws, 'uno' , 'single')  #vector of uno-booleans, in order of players_logedin
+	nwsDeclare(ws, 'rules' , 'single') #vector of the rules 
+  nwsDeclare(ws, 'wildcardrule', 'single') #boolean if wildcards can be played as the uno-card 
 	
   # user declares own variable for his hand-cards in .playUnoMaster()
 
@@ -81,12 +83,14 @@
 
 		# Commands for actions depending on master-user Input
 		if(readCommand=="s" && nplayers>=minPlayers && nplayers<=maxPlayers){
-			# Start UNO game	
+		  .askForRules(ws)
+      # Start UNO game	
 			.playUnoMaster(ws, players, cardsStart, log=log, logfile=logfile, debug)
 			cat("For replay you have to reset the Game: createUnoGame()\n")
 			readCommand <- readline("End Game [e]?")
-		} else if(readCommand=="d" && nplayers>=minPlayers && nplayers<=maxPlayers){
-			# Start UNO game	
+		}else if(readCommand=="d" && nplayers>=minPlayers && nplayers<=maxPlayers){
+      .askForRules(ws)
+      # Start UNO game	
 			.playUnoMaster(ws, players, cardsStart, log=log, logfile=logfile, debug=TRUE)
 			cat("For replay you have to reset the Game: createUnoGame()\n")
 			readCommand <- readline("End Game [e]?")
@@ -154,7 +158,13 @@
 		first_card <- paste(first_card, "4+", sep="")
 	nwsStore(ws, 'played', first_card)
 	
-  	#Set startvalue for variable penalty
+  	#set startvalue for vector 'rules'
+  	#wc = wildcard ->Wildcards must not be played as uno-card
+  	#bb = blackblack ->rybg-cards must not lay on each other
+  	#pc = penalty concatenation ->penalties can be concatenated((2+)+(2+)=(4+)...)
+  	rules<-c(wc,bb,pc)
+    
+    #Set startvalue for variable penalty
   	#FALSE = penalty not allready given, TRUE = penalty has been given to a player -> not again!
  	 nwsStore(ws, 'penalty', TRUE)
  	 
@@ -237,3 +247,44 @@
 	#return winner
 	return(winner)
 }
+###############################################
+#Function to ask what rules should be used
+###############################################
+.askForRules<-function(ws)
+{
+  require(nws)
+  rules<-nwsFindTry(ws, 'rules')
+ 	readWCRule<-""
+  while(readWCRule != "y" && readWCRule != "n"){
+    readWCRule <- readline("Wildcards must not be played as uno-card[y],else[n]")
+    if(readWCRule=="y"){
+      wc<-TRUE
+    }
+    else if(readWCRule=="n"){
+      wc<-FALSE
+    }   
+  }
+  readBBRule<-""
+  while(readBBRule != "y" && readBBRule != "n"){
+    readBBRule <- readline("Wildcards must not be laid on other wild cards[y],else[n]")
+    if(readBBRule=="y"){
+      bb<-TRUE
+    }
+    else if(readBBRule=="n"){
+      bb<-FALSE
+    }   
+  }
+  readPCRule<-""
+  while(readPCRule != "y" && readPCRule != "n"){
+    readPCRule <- readline("Penalties could be concatenated[y],else[n]")
+    if(readPCRule=="y"){
+      pc<-TRUE
+    }
+    else if(readPCRule=="n"){
+      pc<-FALSE
+    }   
+  }
+  bools<-c(wc,bb,pc)
+  bools(rules)<-bools
+  nwsStore(ws,'rules',rules)
+}

Modified: pkg/R/playUno.R
===================================================================
--- pkg/R/playUno.R	2009-08-10 12:43:49 UTC (rev 20)
+++ pkg/R/playUno.R	2009-08-10 13:56:43 UTC (rev 21)
@@ -270,33 +270,33 @@
         
     }else if(card_play=="rybg-0"){
 		.removecard(ws,card_play, cards_hand,user)
-    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number)
+    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number,card_play)
     		
 	  }else if(card_play=="rybg-4+" ){
 		.removecard(ws,card_play, cards_hand,user)
 		#penalty has not been given       
 		nwsStore(ws, 'penalty', FALSE)
-    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number)
+    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number,card_play)
 		
 	  }else if(card_play_number == "BREAK" && (played_color == card_play_color || card_play_number == played_number)){
 		.removecard(ws,card_play, cards_hand,user)
-    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number)
+    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number,card_play)
 
 	  }else if(card_play_number=="BACK" && (played_color == card_play_color || card_play_number == played_number)){
 		.removecard(ws,card_play, cards_hand,user)
-		.playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number)		
+		.playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number,card_play)		
 		
  	  }else if(card_play_number=="2+" && card_play_number == played_number){
     .removecard(ws,card_play, cards_hand,user)
     #penalty has not been given                
     nwsStore(ws, 'penalty', FALSE) # play card 
-    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number)
+    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number,card_play)
                                			
 	 }else if(card_play_number=="2+" && played_color == card_play_color){
 		.removecard(ws,card_play, cards_hand,user)
 		#penalty has not been given        
 		nwsStore(ws, 'penalty', FALSE) # play card
-		.playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number)
+		.playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number,card_play)
 
 	 }else if(!(card_play %in% unlist(cards_hand))){
 		cat("\tCard not in your cards!\n\t'NO' for new card.\n")
@@ -305,7 +305,7 @@
 	 }else if( (card_play_color == played_color) || (card_play_number == played_number) ) {
 		# play normal card with color and number
 		.removecard(ws,card_play, cards_hand,user)
-    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number)
+    .playcard(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number,card_play)
 		
 	}else if(played_color != card_play_color && played_number != card_play_number){
 		cat("\tCard does not match!\n")
@@ -368,6 +368,8 @@
      reason<-", because you said \"uno\" without having a reason"
   }else if(reasonnumber==3){
      reason<-", because you played no card"
+  }else if(reasonnumber==4){
+     reason<-", because you played a rybg-card as your last card" 
   }
   cards_hand<-nwsFindTry(ws, playerInAction)
   for(i in 1:number){
@@ -388,7 +390,7 @@
 #######################################################
 #(Play card, check for winner, go to next)-Function
 #######################################################
-.playcard<-function(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number) 
+.playcard<-function(ws, card_play_save, cards_hand, playerInAction,user,unovec,card_play_number,card_play) 
 {
   require(nws)
   # play card
@@ -438,7 +440,9 @@
 			 nwsStore(ws, 'players', playerInAction)
 			 nwsStore(ws, 'player_in_action', playerInAction)
 			}    
-		} else
+		} else if(length(cards_hand) == 0 && (card_play="rybg-0" ||card_play="rybg-4+")&& nwsFindTry(ws, 'wildcardrule')){
+      .getpenalty(ws,1,user,4)
+    }else
 			nwsStore(ws, 'winner', playerInAction)
 }        
 ############################################################



More information about the Gamesnws-commits mailing list