Python Forum

Full Version: Horse race game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, I am creating a "horse race" game for a class project. So I have to simulate 16 random numbers, and the player has to guess the 5 firsts. So he can win the "ordre", when he have guessed the 5, the "desordre" when he've guessed the 5 but not in the correct order, and finally the "Bonus 3" and "Bonus 4" when he've guessed the first 3 or 4. So, I have made a few functions, for the "ordre", for the simulation of the random numbers ( simule_arrivee ) and for the "desordre" and the bonus ( comparaison ), but I have to make a function that I'll have too call to simulate the entire game ( joue_quinte(pari) ) in which the parameter will be replaced by the player when calling it in the shell. So I have created this function, but I have no clue on how to do it... Anyone could help pls ? ( sorry for my english and for the french names in the code btw ^^' )
import random
 
def simule_arrivee(tabjeu):
    for i in range (1, 6):
        variable = random.randrange(1, 17)
        while variable in tabjeu:
            variable = random.randrange(1, 17)
        tabjeu.append(variable)
    return tabjeu
 
def joue_quinte(pari):
    tableau_pari=[]
    tableau_jeu=[]
    for i in pari:
        tableau_pari.append(i)
 
def ordre(tabjeu, tabpari):
    compteur = 0
    for i in range(0,5):
        if tabjeu[i] == tabpari[i]:
            compteur += 1
    if compteur == 5:
        return "Ordre"
 
             
         
def comparaison(tabjeu, tabpari) :
    compteur_bis= 0
    for i in range(len(tabjeu)):
        for j in range(len(tabpari)):
            if tabpari[j] == tabjeu[i] :
                compteur_bis +=1
    if compteur_bis == 3:
        return "Bonus 3"
    elif compteur_bis == 4:
        return "Bonus 4"
    elif compteur_bis == 5:
        return "Désordre"
I think you need to describe a complete scenario of interaction between a player and the program, for example
  • The user starts the program
  • The program displays a welcome message and asks for the player's bet for the next race
  • The player types their bet and hit the return key
  • The program "parses" the player's input and interpretes it as a sequence of horses numbers
  • The program fills the list tableau_pari with the player's bet
  • The program simulates the race and stores the result in a list tabjeu
  • The program finds the result of the bet by calling ordre() and comparaison()
  • The program prints the result of the bet and exits

Then you only need to write a function that performs all these steps and call it at the end of the program.