Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

petew71 Group Title

Ex 2.6-The game of Nims/Stones. Could someone please show me how they did this one. I just can't figure it all out..

  • one year ago
  • one year ago

  • This Question is Closed
  1. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Hi Peter Check other messages. There was a thread sharing their nims code. At least 3 people did submit working examples. Hope this helps.

    • one year ago
  2. petew71 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Found it, thanks. Typical, i'd not completed the while loops with the if else statements!

    • one year ago
  3. Shadowys Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Clear objectives can aid in programming. The game function objectives are: there are n stones.(variable n is initiated) there are k players, (k>2) (constant k is initiated) players take turns.(there will be function take takes (k) to rotate turns) players take 1/2/3/4/5 stones in one turn.(expect input from player to change n) players play until there is a winner. (while loop until a condition) player to take last stones win.(if-else condition, n==0 to break loop)

    • one year ago
  4. petew71 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I used a while loop for each player, both inside a bigger while loop. But i got mixed up with the logic flow and wasn't getting the ordering quite right! Thanks to looking at others programs i tidied the ends of the loops OK ! I've deliberately held myself back quite a bit, practicing different loops! (I instinctively found 'if, elif, else' , and working with string slices quite easy...But not loops!)

    • one year ago
  5. Shadowys Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    lol yeah, it's tough to understand them, but a general rule is to avoid loops unless you really need to go through the process repetitively. It took me sometime to remember a loop always need a breaking statement. Good luck with your other projects!

    • one year ago
  6. petew71 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Cheers for the tip! :0)

    • one year ago
  7. lh4219 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    def ask(numStones, num, player): ques = False while ques == False: if player == 1: ans = input("Player1 enter number of stones to take from pile. ") if ans >= 1 and ans <= num: ques = True else:continue if ans > numStones: return numStones else: ans = input("Player2 enter number of stones to take from pile. ") if ans >= 1 and ans <= num: ques = True else:continue if ans > numStones: return numStones return numStones - ans def play_nims(pile, max_stones): ''' An interactive two-person game; also known as Stones. @param pile: the number of stones in the pile to start @param max_stones: the maximum number of stones you can take on one turn ''' while pile != 0: while True: pile = ask(pile, max_stones, 1) if pile == 0: print "player1 WINS!" break pile = ask(pile, max_stones, 2) if pile == 0: print "player2 WINS!" break else:continue def play(): print "This is the game of stones. It is a 2 person game." print while True: reply = raw_input("Please enter an N for a new game or a . to exit the game. ") print if reply == 'N' or reply == 'n': reply1 = input("Please enter the number of stones to put in the pile. ") reply2 = input("Please enter the maximum number of stones to remove during a turn. ") print play_nims(reply1, reply2) continue else: break

    • one year ago
  8. petew71 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    A lot more comprehensive than mine!...Well done!

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.