Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions nim_improved.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Game of Nim

def welcomeMessage():
print\
"""
print(
"""
This is a 2 player game.
The computer-human based game will be made soon.
There are a total of 13 sticks.
Each player choses minimum 1 and maximum 4 sticks in one turn.
The player who picks up the last stick wins.
All the best to both players.
"""
""")

def get_players():
player1 = raw_input("What is player 1's name?")
player2 = raw_input("What is player 2's name?")
player1 = input("What is player 1's name? ")
player2 = input("What is player 2's name? ")
return player1, player2

def gameLogic():
totalSticks = 13
numberOfSticksPicked = 0
turn = 1
while totalSticks:
print"Number of sticks remaining: ", totalSticks
print "Player", turn, "'s turn."
numberOfSticksPicked = int(raw_input("Pick minimum 1 and maximum 4 sticks.\n"))
print ("Number of sticks remaining: ", totalSticks)
print ("Player", turn, "'s turn.")
numberOfSticksPicked = int(input("Pick minimum 1 and maximum 4 sticks.\n"))
if numberOfSticksPicked > totalSticks\
or numberOfSticksPicked > 4\
or numberOfSticksPicked < 1:
print"That is not allowed. Try picking again."
print ("That is not allowed. Try picking again.")
continue
totalSticks = totalSticks - numberOfSticksPicked
if turn == 1:
Expand All @@ -42,9 +42,9 @@ def gameLogic():

def winMessage(turn,player1,player2):
if turn:
print player2 + " won."
print (player2 + " won.")
else:
print player1 + " won."
print (player1 + " won.")



Expand Down