Roulette Game Schedule

Solved
Hello to all the noobs,
here's my issue, a friend and I would like to program the roulette game (the one you find in casinos) in Python. The problem is that we're having a hard time structuring our program because we've added a difficulty which is the choice of the number of players for the game.
Let me explain the program we want to create:

Game flow: "Introduction":

-We choose the number of players

-We assign a name to each player (e.g., the 1st will be player1, the 2nd will be player2,...)

-We then specify their wallet amount (e.g., €1000 each)

-Then the minimum and maximum bets

The game (to be done in a loop):

-We ask the player, each in turn, to choose a number between 0 and 36, and then the amount of their bet

-When the bets are made, the program generates a random number between 0 and 36

-Then we display this winning number, and for each player, we show their winnings or losses.

-Next, we display their updated wallet amount

-If there is a bankruptcy (that is, if one of the players has no money left in their wallet), the game stops

-Finally, we ask if they want to play another round or quit

This is the program we would like to design.

We turned to the use of lists/arrays with the use of the For loop, which I think is the simplest way to make this program. But having some gaps in using these lists/arrays, we decided to ask you for a bit of help.

All ideas are welcome, thank you in advance for the help you will provide on this topic.

3 answers

  1. ```python
    from random import randrange

    class Joueur:
    def __init__(self, nom, argent):
    self.nom = str(nom)
    self.argent = int(argent)
    self.numero = 0
    self.mise = 0

    nbJoueurs = int(input("Nombre de joueurs : "))
    joueurs = []
    sargent = [] # Changer ici pour une liste vide
    argent_initial = int(input("Argent de départ : ")) # Convertir l'argent initial en entier

    # Initialisation de la liste sargent avec l'argent de départ pour chaque joueur
    for _ in range(nbJoueurs):
    sargent.append(argent_initial)

    continuer_partie = True

    while continuer_partie:
    for x in range(0, nbJoueurs):
    joueurs.append(Joueur(input(("Numero choisit du joueur "+str(x+1)+" : ")), sargent[x]))

    for x in range(0, nbJoueurs):
    joueurs[x].mise = int(input("Mise du joueur "+str(x+1)+" : "))

    # Affichage du numero gagnant (aléatoirement)
    numero_gagnant = randrange(1)
    print("La roulette tourne,...... tourne, ...... tourne, ...... tourne, et s'arrete sur le numero", numero_gagnant)

    for x in range(0, nbJoueurs):
    if joueurs[x].numero == numero_gagnant: # Utiliser joueurs[x].numero au lieu de joueurs[x]
    print("Felicitation, votre numero est le bon, vous obtenez ", joueurs[x].mise * 35, "euros!")
    sargent[x] += joueurs[x].mise * 35 # Utiliser l'opérateur +=
    else:
    print("Desoler l'ami, c'est pas pour cette fois. Vous perdez votre mise qui est de", joueurs[x].mise, "euros")
    sargent[x] -= joueurs[x].mise # Utiliser l'opérateur -=

    # On interrompt la partie si le joueur est ruine
    for x in range(0, nbJoueurs):
    if sargent[x] <= 0:
    print("Vous etes ruine! C'est la fin de la partie.")
    continuer_partie = False
    break # Sortir de la boucle si un joueur est ruiné
    else:
    # On affiche l'argent du joueur
    print("Le joueur "+str(x+1)+" a desormais", sargent[x], "euros")

    quitter = input("Souhaitez-vous quitter le casino (o/n) ? ")
    if quitter.lower() == "o": # Utiliser la méthode lower pour simplifier
    print("Vous quittez le casino avec vos gains.")
    continuer_partie = False
    ```
    3
    1. Do you use Python 2 or 3?
      0
    2. You apparently didn't understand
      sargent
      :
      it's the starting money for all players (s for start) which is an int.

      To access the money of one of the players, you shouldn't do
      sargent[x]
      but
      joueurs[x].argent


      Finally, for optimization purposes, instead of
      for x in range(0, nbJoueurs): joueurs.append(Joueur(input(("Numero choisit du joueur "+str(x+1)+" : ")), sargent)) for x in range(0, nbJoueurs): joueurs[x].mise = int(input("Mise du joueur "+str(x+1)+" : "))

      rather do:
      for x in range(0, nbJoueurs): joueurs.append(Joueur(input(("Numero choisit du joueur "+str(x+1)+" : ")), sargent)) joueurs[x].mise = int(input("Mise du joueur "+str(x+1)+" : "))
      0
    3. @ZephirrThank you, you saved me from a sleepless night! lol
      It's true that I didn't quite understand the
      sargent
      , or rather why there was an 's'!

      So I changed everything, but I think there's a problem at line 33 with:
      if joueurs[x] == numero_gagnant:

      because even if I win, it says I lost:
      Number of players: 2
      Starting money: 1000
      Number chosen by player 1: 0
      Bet of player 1: 25
      Number chosen by player 2: 1
      Bet of player 2: 25
      The roulette spins,...... spins, ...... spins, ...... spins, and stops on number 0
      Sorry player 1, it’s not your time. You lose your bet of 25 euros
      Sorry player 2, it’s not your time. You lose your bet of 25 euros
      Player 1 now has 975 euros
      Would you like to leave the casino (y/n)?


      And finally, it only displays the wallet of player 1 but not the others.
      I think it doesn't take the
      if
      function into account.

      Thank you for your help and patience!
      0
    4. To access a player's number:
      player[x].number

      Moreover, there is another nonsense in your script: every time you do
      players.append(Player(input(("Chosen player number "+str(x+1)+" : ")), sargent))

      you are adding a player. It should only be done at the beginning with:
      for x in range(0, numPlayers): players.append(Player(input(("Player name "+str(x+1)+" : ")), sargent))

      The beginning then becomes:
      sargent = input("Starting money: ") continue_game = True for x in range(0, numPlayers): players.append(Player(input(("Player name "+str(x+1)+" : ")), sargent)) while continue_game: for x in range(0, numPlayers): players[x].number = int(input(("Chosen number for player "+str(x+1)+" : "))) players[x].bet = int(input("Bet for player "+str(x+1)+" : "))

      There is also a problem with your
      randrange
      : instead use
      winning_number = random.randint(0,36)


      Finally, to ask once if we want to leave the casino:
       # We interrupt the game if the player is bankrupt for x in range(0, numPlayers): if sargent[x] <= 0: print("You are bankrupt! This is the end of the game.") continue_game = False else: # We display the player's money print("Player "+str(x+1)+" now has", sargent[x], "euros") leave = input("Do you want to leave the casino (y/n)? ") if leave == "y" or leave == "Y": print("You are leaving the casino with your winnings.") continue_game = False
      0
    5. Thank you, otherwise for the
      randrange
      , I set it to 1 to see if the winnings part would work! ;)

      Otherwise now I have another problem (after resolving 2, there are others that appear! ^^'), after having replaced the things that weren't working:
      from random import randrange class Joueur: def __init__(self, nom, argent): self.nom = str(nom) self.argent = int(argent) self.numero = 0 self.mise = 0 nbJoueurs = int(input("Number of players: ")) joueurs = [] sargent = input("Starting money: ") continuer_partie = True for x in range(0, nbJoueurs): joueurs.append(Joueur(input(("Player number: ")), sargent)) while continuer_partie: for x in range(0, nbJoueurs): joueurs[x].numero(Joueur(input(("Player "+str(x+1)+", which number have you chosen? : ")))) joueurs[x].mise = int(input("Player "+str(x+1)+", and your bet: ")) # Display the winning number (randomly) numero_gagnant = random.randint(0,36) print "The roulette spins,...... spins, ...... spins, ...... spins, and stops on the number", numero_gagnant for x in range(0, nbJoueurs): if joueurs[x].numero == numero_gagnant: print "Congratulations player "+str(x+1)+" you have the right number, you receive ", joueurs[x].mise*35, "euros!" joueurs[x].argent = joueurs[x].argent + joueurs[x].mise*35 else: print "Sorry player "+str(x+1)+" , it's not your time. You lose your bet of", joueurs[x].mise, "euros" joueurs[x].argent = joueurs[x].argent - joueurs[x].mise # We stop the game if the player is bankrupt for x in range(0, nbJoueurs): if sargent[x] <= 0: print("You are bankrupt! It's the end of the game.") continuer_partie = False else: # We display the player's money print"Player "+str(x+1)+" now has", sargent[x], "euros" quitter = input("Would you like to leave the casino (y/n)? ") if quitter == "y" or quitter == "Y": print"You're leaving the casino with your winnings." continuer_partie = False


      I get this error message:
       File "C:\Users\victor\Desktop\Test roulette.py", line 25, in <module>
      joueurs[x].numero(Joueur(input(("Player "+str(x+1)+", which number have you chosen? : "))))
      TypeError: __init__() takes exactly 3 arguments (2 given)


      I think of adding in
      def __init__(self, nom, argent):
      "numero" but I tried and it gives me this error message:
       File "C:\Users\victor\Desktop\Test roulette.py", line 20, in <module>
      joueurs.append(Joueur(input(("Player number: ")), sargent))
      TypeError: __init__() takes exactly 4 arguments (3 given)


      I'm a bit stuck :/

      Thank you for your help and patience!
      0