# Jordan Uchima
# 2-4-10
# "Nim" - Game
# Start with thirteen pieces and two players.
# Each player takes 1 - 4 pieces each turn.
# Player who takes the last piece loses.


# Declare constants.
NUMBER_OF_PLAYERS = 2
TOTAL_PIECES_AT_START = 13
namePlayer1 = raw_input("Hello Player 1, what is your name?\n")
namePlayer2 = raw_input("Hello Player 2, what is your name?\n")
# Declare functions.

def rules():
    """Print the rules of the game."""
    print 'The player that takes the last piece loses!'\
          'You can only take 1 - 4 pieces!\n\n'

def get_players():
    """Get the names of the players."""
    # Let's put the player's names in a list.
    players = []
    # Looping like this saves us repeating lines of code for each player.
    for player in range(NUMBER_OF_PLAYERS):
        
        players.append(player)
        break
    return players

def take_turn(player):
    """Handle a player's turn."""
    # Turn logic goes here.
    
player1Choice = int(raw_input(namePlayer1 + " how many pieces would you like to take?\n")),
player2Choice = int(raw_input(namePlayer2 + " how many pieces would you like to take?\n"))
playerChoice = player1Choice and player2Choice
x = 13 - playerChoice
loss = x <=2 and x >= 0,
while player1Choice == loss is True:
    print namePlayer1 + " loses!"
while player2Choice == loss is True:
    print namePlayer2, loss
while player1Choice and player2Choice == loss is True:
    print "It's a draw!"
while player1Choice != loss is True:
    print x
while player2Choice != loss is True:
    print x
while player1Choice and player2Choice != loss is True:
    print ("Keep going! Only ", x, " pieces left!")
validChoice = \
player1Choice == range(1, 4) is True,
print x
player1Choice == range(1, 4) is False,
print validChoice
player2Choice == range(1, 4) is True,
print x
player2Choice == range(1, 4) is False,
print validChoice
           

def main():
    """Run the game."""
    # Display the rules by calling rules function.
    rules()
    # Get the players by calling the get_players function.
    players = get_players()
    # Set up the game.
    remaining_pieces = TOTAL_PIECES_AT_START
    playing = True
    # Main loop - let's play!
    while playing:
        # Take turns.
        for player in players:
            remaining_pieces = take_turn(player)
            # Check if this player has lost.
            if remaining_pieces <= 0:
                # Player has taken last piece.
                print 'Sorry' +  'you have lost.'
                # Break out of the loop
                playing = False
                break


# Automatically run main function if we're run as a script.
if __name__ == '__main__':
    main()

# End.
