0

I want this to keep track of each players turn including the AI. Not the numer of rolls but for each turn till the game ends. For example your turn ends when a 1 is rolled on either dice or both.

import sys
from random import randint
def game():
    playercount = 2
    maxscore = 100
    safescore = [0] * playercount
    player = 0
    score=0

    while max(safescore) < maxscore:
        if player == 0:
            rolling = 0
            if score < 17 and score + safescore[player] < maxscore:
                rolling = 1
        else:
            rolling = input("Player %i: (%i, %i) Rolling? (Y) "
                % (player, safescore[player], score)).strip().lower() in {'yes', 'y', ''}
        if rolling:
            rolled = randint(1, 6)
            rolled2 = randint(1, 6)
            print('  Rolled %i' % rolled)
            print('  Rolled %i' % rolled2)
            if rolled ==1 and rolled2 ==1:
                    print('  Snake Eyes!! your score is set to 0')
                    safescore[player] = 0    
                    player = (player + 1) % playercount

            elif rolled == 1:
                print('  Bust! you lose %i but still keep your previous %i'
                      % (score, safescore[player]))
                score, player = 0, (player + 1) % playercount
            elif rolled2 == 1:
                print('  Bust! you lose %i but still keep your previous %i'
                      % (score, safescore[player]))
                score, player = 0, (player + 1) % playercount


            else:
                score += rolled + rolled2
        else:
            safescore[player] += score
            if safescore[player] >= maxscore:
                break
            print('  Sticking with %i' % safescore[player])
            score, player = 0, (player + 1) % playercount




def wannaPlayAgain():
    play_again = input('Play again? y/n: ')
    if play_again == 'y':
        game()
    elif play_again == 'n':
        sys.exit()
    else:
        print("Answer is not valid.")


game()

wannaPlayAgain() 

Edited by itsthewendigo1111

2
Contributors
1
Reply
32
Views
2 Years
Discussion Span
Last Post by davidnelson4911
0

first I would add an object to take care of holding the player's turn counts:

playerTurns = [0 for x in range(playercount)]]

And then, wherever a player's turn ends(Keep track of which player is which as well...) simply increment the proper count:

if turnEnds:
    playerTurns[player] += 1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.