One recurring complaint is that nobody talks about code on /prog/. So everyone write go and write some code, any code, that does something, anything, and post it. A small explanation wouldn't go amiss either.
Name:
Anonymous2011-03-05 16:57
In this game, two players sit in front of a pile of stones. They take turns, each removing a set amount of stones (up to a specified maximum). The person who removes the last stone(s) wins. Half of the code is redundant as I don’t use a variable to track which player’s move it is. Primarily because I didn’t know how to.
If you are lonely and want to play against the ‘computer’ change the second choice variable to choice=random.randint(1,max)be sure to import random, if you do
def nims(pile, max):
while pile>0:
choice=input("How many Stones do you want to remove, P1?")
while choice not in range(1,max+1):
choice=input("You have made an invalid selection P1.\
Please chose again.")
pile=pile-choice
print pile
if pile<=0:
print 'player 1 wins!'
break
choice=input("Player 2: How many Stones do you want to remove?")
while choice not in range(1,max+1):
choice=input("You have made an invalid selection P2.\
Please chose again.")
pile=pile-choice
print pile
if pile<=0:
print 'game over, player 2 is the winner!'
x=input('How big is the pile?\n')
y=input('How many stones can one person take each time?\n')
print 'Pile set to', x, ', maximum stone number set to', y,'!'