Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 16th, 2009, 1:06 AM   #1
bsiguenza
Newbie
 
Join Date: Mar 2009
Posts: 1
Rep Power: 0 bsiguenza is on a distinguished road
Arrow Rock, Paper, Scissor Game Help

This is the template that we are suppose to use while doing the program, I am a beginner to this programming language and really have no clue what I am doing


import random
#table of winning plays
win_play_for = {’r’:’p’, ’p’:’s’, ’s’:’r’}

#scoring results
player_score = 0
mach_score = 0

#keep track of users’last plays
#assume initially an even distribution
hist = [’r’, ’p’, ’s’, ’r’, ’p’, ’s’, ’r’, ’p’, ’s’]
next = 0 #index of where to put next user play

while True:
#guess what user play will be based on past
#behavior. Pick a machine play to win based
#on guess

#get user’s play
user_play = raw_input("what’s your play (r|p|s)? ")
#if the user does not respond with one of those break

#otherwise
#update history of user plays

#determine winner for current play or draw
#print results of current play and scores so far


NOW THIS IS WHAT I HAVE SO FAR, AND THESE ARE ALL JUMBLE AROUND BECAUSE I HAVE NO CLUE WHERE THEY ARE SUPPOSE TO GO, plus i dont know how to add the other requirements PLZ HELP


import random

#table of winning plays
win_play_for = {'r':'p', 'p':'s', 's':'r'}


#scoring results
player_score = 0
mach_score = 0

#kepp track of users' last plays
#assume initially an even distribution
hist = ['r', 'p', 's', 'r', 'p', 's', 'r', 'p', 's']
next = 0 #index of where to put next user play


while True:
hist = ['r', 'p', 's', 'r', 'p', 's', 'r', 'p', 's']
next = 0
guess = random_choice(hist)
len (hist)


#gets user's play
user_play = raw_input("What's your play (r|p|s)?")
hist[next] = user_play
next = next + 1
if next == len(hist):
next = 0

user_play == win_play_for(mach_play)
mach_play == win_play_for(user_play)
bsiguenza is offline   Reply With Quote
Old Mar 25th, 2009, 1:39 PM   #2
woooee
Programmer
 
Join Date: Jun 2008
Posts: 41
Rep Power: 0 woooee is on a distinguished road
Re: Rock, Paper, Scissor Game Help

Break it down into parts, and code and test each one. Let's start with the input loop, asking for a choice until the user enters something that is not "r". "p", or "s".
#gets us into while loop
user_play = raw_input("What's your play (r|p|s)?")
user_play = user_play.lower()
while user_play in ["r", "p", "s"]
   print "user chose", user_play
   user_play = raw_input("What's your play (r|p|s)?")
   user_play = user_play.lower()
Next, send it to a fuction and select the computers choice and find a winner, with print statements so we can see what is going on.
import random

def find_winner(user_play, mach_score, player_score):
   win_play_for = {'r':'p', 'p':'s', 's':'r'}

   computer_play = random.choice(("r", "p", "s"))

   if computer_play != user_play:
      beat_user = win_play_for[user_play]
      print "user chose %s, a %s will beat you" % \
            (user_play, beat_user)

      beat_computer = win_play_for[computer_play]
      print "computer chose %s, a %s will beat you" % \
            (computer_play, beat_computer)
   
      print
      if user_play == beat_computer:
         print "User beats computer"
         player_score += 1
      elif computer_play == beat_user:
         print "Computer beats user"
         mach_score += 1
      else:
         print "We should never get here so there is an error"

   else:
      print "It's a tie.  Both have", user_play

   return mach_score, player_score

##===================================
mach_score=0
player_score=0
user_play = raw_input("What's your play (r|p|s)?")
user_play = user_play.lower()
while user_play in ["r", "p", "s"]:
   mach_score, player_score = find_winner(user_play, mach_score, player_score)
   print "Score is computer=%d,  user=%d" % (mach_score, player_score)
   print "\n-----------------------------------------------------"
   user_play = raw_input("What's your play (r|p|s)?")
   user_play = user_play.lower()
The rest you should try for yourself. This will at least give you a general idea.

Last edited by woooee; Mar 25th, 2009 at 1:56 PM.
woooee is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++/Java Interview for Paper y4g4d4w4 Coder's Corner Lounge 0 Feb 8th, 2009 5:19 PM
Grim's Hex Paper grimpirate Coder's Corner Lounge 9 Jun 21st, 2007 11:05 PM
Why IRC Channel Admins Rock grimpirate Coder's Corner Lounge 8 Dec 10th, 2006 5:51 PM
Research Paper: I think this kid was high... tempest Coder's Corner Lounge 10 Nov 27th, 2005 5:12 PM
Help with rock paper scissor program Batalia2 Visual Basic .NET 14 Mar 21st, 2005 4:11 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:30 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC