top of page

CherryO Game

The Python script counts the average time and iteration for solving CherryO game over different playings. You can play it unlimitedly while the number of cherries is unlimited, too (both are user-defined). Spinner has 7 different options as [-1,-2,-3,-4,2,2,Reset_to_Total_Cherries].

 

# Ehsan Momeni

 

 

# This program counts the average time and iteration for solving CherryO game over different playings.
# You can play it unlimitedly while number of cherries are unlimited, too (both are user-defined)
# Spinner has 7 different options as [-1,-2,-3,-4,2,2,Reset_to_Total_Cherries].

 

from time import *  # To calculate the running time
from random import *  # To generate random numbers for the spinner

 

Times = int(raw_input("\nHow may times do you want to play it?\t"))  # number of total iterations
Total_Cherries = int(raw_input("Enter number of cherries:\t"))  # number of cherries in the tree


list = [-1, -2, -3, -4, 2, 2, Total_Cherries]


Running_count = []
Running_Time = []

 

for i in range(1, Times+1):
    start_time = time()  # Starting time of a game
    Counter = 0  # Counter counts number of iterations in each game

    Cherries = Total_Cherries
    while Cherries > 0:
        Spinner = list[randint(0, len(list)-1)]  # spinner is the action that have to applied on the cherries
        if Spinner == Total_Cherries:  # if game wants to reset to the pre-defined number of cherries
            Cherries = Total_Cherries
        else:  # if game is running without resetting to the pre-defined number of cherries
            Cherries += Spinner
            if Cherries > Total_Cherries:  # condition that limits maximum number of cherries
                Cherries = Total_Cherries
        Counter += 1  # Counting turns in each game
    # print "\nYou won in %d iteratinos!"%(Counter)


    Running_count.append(Counter)  # storing number of counts in each game in a list called Running_count
    Running_Time.append(time() - start_time)  # storing time of solving in each game in a list called Running_Time


print "\nThe average running iteration is %d" % (sum(Running_count)/Times)  # print the average of iteration


print "The average running time is %0.2f" % (sum(Running_Time)/Times)  # print the average of time

 

 

google_scholar1-300x150.png
ResearchGate.png
Ehsan Momeni ORCID GIS Remote Sensing Ur
Ehsan Momeni LinkedIn GIS Remote Sensing
ncbi-300x150.png
academia.png

(Information on this website may not be up to date)

bottom of page