# "Nim" game being created, no GUI used... Need tips...

Jordan Uchima fuzzy.666.chaos at gmail.com
Sat Feb 6 04:54:48 CET 2010

```I am creating a game called Nim, but cannot get a loop going no matter what
I do. What i am trying to do is get it to only accept input from 1 to 4,
and  keep asking for input from the same player if he/she enters in an
invalid number. I also want it to stop when there is 1 or no piece(s) left,
and declare the player who DID NOT take the last piece the winner. Also, how
do I word the coding so that way it will make the players take turns? there
are 2 players. there are 13 pieces to start with. i am using python 2.6.4 .
here is my code:

-----------------------------------------------------------------------------------------------------------------------------------------------

# taking pieces away

player1Choice = raw_input("Well, " + namePlayer1 + " how many"\
" pieces would you like to take?\n" + range(1,
4))
player2Choice = raw_input("Well, " + namePlayer2 + " how many"\
" pieces would you like to take?\n" + range(1,
4))

# setting a variable for the number of pieces

x = 13 - int(player1Choice or player2Choice) and not < 0

# to alternate turns

turn  = \
while player1Choice is False:
print player1Choice and "There is ", x, " pieces remaining."
while player1Choice is True:
print player2Choice and "There is ", x, " pieces remaining."
while player2Choice is False:
print player2Choice and "There is ", x, " pieces remaining."
while player1Choice and player2Choice is True:
print player1Choice and "There is ", x, " pieces remaining."
while x != range(0, 1):
continue turn

# to determine winner/loser

loss = while x = range(0, 4) is True:
print loser " loses!" + loser = \
if player1Choice = loss:
print namePlayer1 + loss
elif player2Choice = loss:
print namePlayer2 + loss
else player1Choice and player2Choice = loss:
print "It's a draw!"
elif player1Choice != loss:
print ""
elif player2Choice != loss:
print ""
else player1Choice and player2Choice != loss:
print "Keep going! Only ", x, " pieces left!"

winner = \
if player1Choice != loss:
print namePlayer1 " wins!"
elif player2Choice != loss:
print namePlayer2 " wins!"
elif player1Choice and player2Choice != loss:
print "Keep going! Only ", x, " pieces left!"
elif player1Choice = loss:
print namePlayer1 + loss
elif player2Choice = loss:
print namePlayer2 + loss
else player1Choice and player2Choice = loss:
print "It's a draw!"

# getting player's names

namePlayer1 = raw_input("Hello Player 1, what is your name?\n")
namePlayer2 = raw_input("Hello Player 2, what is your name?\n")

# greeting players

print "Hello", namePlayer1, "and", namePlayer2, "!"

# instructions

print "Welcome to the game of Nim, where you actually have to think!\n\n"\
"The instructions are simple: you can take 1 to 4 pieces at a time,"\
" but, if you take the last piece, YOU LOSE!\n\n"\
"To take pieces, simply type in the number of pieces you want"\
" to take, and press the ENTER (or in some cases, RETURN) key.\n\n"\
"However, you can NOT take 0 pieces, or more than 4 pieces!\n\n"\
"Well then, let's get started! :-)"

# starting the game

print turn

---------------------------------------------------------------------------------------------------------------------------------------------

All help and insertions would be appreciated. You can reach me at
fuzzy.666.chaos at gmail.com   .

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100205/5c3d0ac0/attachment.html>
```