Esempio n. 1
0
 def change_size(self, parameter):
     """
     changes the size of the current grid world.
     :param parameter:
     :return: None
     """
     if parameter:
         rows, columns = parameter.split('x',2)
         if toolbox.is_integer(rows) and toolbox.is_integer(columns):
             rows = int(rows)
             columns = int(columns)
     else:
         print("You cannot choose 1 for rows or columns.")
         prompt = 'How many rows of cells?'
         rows = toolbox.get_integer_between(2,40,prompt)
         prompt = 'How many cells in each row?'
         columns = toolbox.get_integer_between(2,120,prompt)
     self.__world = World(rows, columns)
     self.random()
     print(self.__world, end='')
     self.__generation = 0
     print()
     print(f'Your world size is now {rows} by {columns}.')
     print()
     print(self.status() + '\n' + self.menu(), end=' ')
Esempio n. 2
0
 def change_size(self, parameter):
     if parameter:
         rows, columns = parameter.split('x', 2)
         if toolbox.is_integer(rows) and toolbox.is_integer(columns):
             rows = int(rows)
             columns = int(columns)
     else:
         prompt = 'How many rows of cells?'
         rows = toolbox.get_integer_between(1, 40, prompt)
         prompt = 'How many cells in each row?'
         columns = toolbox.get_integer_between(1, 120, prompt)
     self.__world = World(rows, columns)
     self.random()
Esempio n. 3
0
 def change_rules(self, whichNumbers):
     """
     Changes the rules of life, from how many neighbors it takes for a cell to remain alive or become alive
     :param whichNumbers:
     :return:
     """
     if whichNumbers:
         if toolbox.is_integer(whichNumbers) and \
                 1 <= int(whichNumbers) <= len(Rules.ruleSets.keys()):
             whichNumbers = int(whichNumbers)
     else:
         print('**************************************')
         for number, set in enumerate(Rules.ruleSets):
             stayAlive = Rules.ruleSets[set]['stayAlive']
             stayAlive1 = stayAlive[0]
             stayAlive2 = stayAlive[1]
             becomeAlive = Rules.ruleSets[set]['becomeAlive']
             string = f'{number + 1}: Neighbors needed for cell to stay alive: {stayAlive1}, {stayAlive2}     '
             string += f'Neighbors needed for cell to become alive: {becomeAlive}'
             print(string)
         print(f'{number + 2}: pick your own characters')
         print('**************************************')
         prompt = 'What character set would you like to use?'
         whichNumbers = toolbox.get_integer_between(1, number + 2, prompt)
         if whichNumbers == number + 2:
             print()
             string = 'You can pick 2 number amounts of neighbors so that an  alive cell stays alive. '
             string += '\nFor example, typing "23" makes it so if a cell has 2 or 3 neighbors, it stays alive. '
             string += '\nHow many neighbors do you want? Please type a 2 digit number: '
             stay = toolbox.get_string(string)
             become = toolbox.get_string('Which number of neighbors would you like to change a cell from dead to alive? (One digit number)  ')
             Rules.set_rules_user_values(stay, become)
     setString = list(Rules.ruleSets.keys())[whichNumbers - 1]
     Rules.set_rules(setString)
     self.display()
Esempio n. 4
0
    def run_simulation(self, parameter):
        """
        Displays the next generation of the world.
        :param parameter:
        :return: None
        """
        if toolbox.is_integer(parameter) and int(parameter) > 0:
            generations = int(parameter)
        else:
            prompt = 'How many generations would you like to simulate?'
            generations = toolbox.get_integer_between(1, 10000, prompt)
        for generation in range(generations):
            self.__world.next_generation()
            if self.__world.is_stable() == True:
                "It is stable now."
                break
            else:
                pass

            #self.__world.__lastWorld = self.__world.__secondWorld
            string = self.__world.__str__()
            string += self.status()
            string += f'left: {generations - generation}'
            print(string)
            time.sleep(self.__delay)

        print()
        print(f'You have now been through {generations} generations. ')
        print()
        print(self.menu(), end=' ')
        self.__generation += generations
Esempio n. 5
0
 def change_rules(self, parameter):
     """
     Print possible display changes for the user.
     :param parameter: which rule display user wants
     :return: none
     """
     if toolbox.is_integer(parameter) and \
             1 <= int(parameter) <= len(Rules.ruleSets.keys()):
         setNumber = int(parameter)
     else:
         print('**************************************')
         for number, ruleSet in enumerate(Rules.ruleSets):
             bornNum = Rules.ruleSets[ruleSet]['bornNum']
             surviveNum = Rules.ruleSets[ruleSet]['surviveNum']
             print(
                 f'{number+1}: Born Number: {bornNum} Survive Number: {surviveNum}'
             )
         print(f'{number+2}: Choose your own characters! ')
         print('**************************************')
         prompt = 'What character set would you like to use?'
         setNumber = toolbox.get_integer_between(1, number + 2, prompt)
         numberOfSets = number + 2
     if setNumber == numberOfSets:
         setString = 'choice'
     else:
         setString = list(Rules.ruleSets.keys())[setNumber - 1]
     Rules.set_rules(setString)
     print(self.__currentWorld, end='')
Esempio n. 6
0
 def change_display(self, parameter):
     """
     Change the live and dead characters for the cells.
     :param parameter:
     :return: None
     """
     if toolbox.is_integer(parameter) and \
             1 <= int(parameter) <= len(Cell.displaySets.keys()):
         setNumber = int(parameter)
     else:
         print('**************************************')
         for number, set in enumerate(Cell.displaySets):
             liveChar = Cell.displaySets[set]['liveChar']
             deadChar = Cell.displaySets[set]['deadChar']
             print(
                 f'{number + 1}: living cells: {liveChar} dead cells: {deadChar}'
             )
         print('**************************************')
         prompt = 'What character set would you like to use?'
         setNumber = toolbox.get_integer_between(1, number + 1, prompt)
     setString = list(Cell.displaySets.keys())[setNumber - 1]
     Cell.set_display(setString)
     print(self.__world, end='')
     print()
     print(
         f'Your living cell is now {liveChar} and a dead cell is {deadChar}.'
     )
     print()
     print(self.status() + '\n' + self.menu(), end=' ')
Esempio n. 7
0
 def skip_generations(self, parameter):
     """
     Displays the next generation of the world.
     :param parameter:
     :return: None
     """
     if toolbox.is_integer(parameter) and int(parameter) > 0:
         generations = int(parameter)
     else:
         prompt = 'How many generations would you like to skip?'
         generations = toolbox.get_integer_between(1, 10000, prompt)
     print(f'Skipping {generations} generations.', end='')
     for generation in range(generations):
         self.__world.next_generation(self.__world)
         if self.__world.is_stable() == True:
             "It is stable now."
             break
         else:
             pass
         if generation % 100 == 0:
             print('.', end='')
     print(' done!')
     self.__generation += generations
     time.sleep(2)
     string = self.__world.__str__()
     string += self.status()
     print(string)
     print()
     print(f'You now have skipped forward {generations} generations.')
     print()
     print(self.menu(), end=' ')
Esempio n. 8
0
    def skip_generations(self, generations):
        """
        Displays the next generation of the world
        :param generations:
        :return: next generation
        """
        if toolbox.is_integer(generations) and int(generations) > 0:
            generations = int(generations)
        else:
            prompt = 'How many generations do you wanna skip?'
            generations = toolbox.get_integer_between(1, 10000, prompt)
        print(f'Skipping {generations} generations.', end='')

        for generation in range(generations):
            self.__world.next_generation()
            if self.__world.is_stable() == True:
                print('It is stable now.')
                break
            else:
                pass
            if generation % 100 == 0:
                print('.', end='')
        print(' done!')
        time.sleep(2)
        self.display()
Esempio n. 9
0
 def change_rule(self, parameter):
     """
     Change the number of neighbors a cell needs to live or die.
     :param parameter:
     :return: None
     """
     if toolbox.is_integer(parameter) and \
             1 <= int(parameter) <= len(Rule.ruleSets.keys()):
         setNumber = int(parameter)
     else:
         print('**************************************')
         for number, set in enumerate(Rule.ruleSets):
             neighbor1 = Rule.ruleSets[set]['neighbor1']
             neighbor2 = Rule.ruleSets[set]['neighbor2']
             neighbor3 = Rule.ruleSets[set]['neighbor3']
             print(
                 f'{number + 1}: neighbor1: {neighbor1} neighbor2: {neighbor2} neighbor3: {neighbor3}'
             )
         print('**************************************')
         prompt = 'What rule set would you like to use?'
         setNumber = toolbox.get_integer_between(1, number + 1, prompt)
     setString = list(Rule.ruleSets.keys())[setNumber - 1]
     Rule.set_rule(setString)
     print(self.__world, end='')
     print()
     print(
         f'Your rule set is now neighbor1:{neighbor1}, neighbor2:{neighbor2}, neighbor3:{neighbor3}.'
     )
     print()
     print(self.status() + '\n' + self.menu(), end=' ')
Esempio n. 10
0
 def get_percentage(self):
     """
     gets a number as a percent from the user
     :return: the percentage inputted
     """
     self.__percentage = toolbox.get_integer_between(1, 100, "What percent of cells do you want alive? (just enter integer) ")
     return self.__percentage
Esempio n. 11
0
 def change_graphics(self, whichCharacters):
     """
     Changes the alive and dead cells to characters of the users choice
     :param whichCharacters: the characters that the user wants to change the alive and dead cells to.
     :return:
     """
     if toolbox.is_integer(whichCharacters) and \
             1 <= int(whichCharacters) <= len(Cell.displaySets.keys()):
         whichCharacters = int(whichCharacters)
     else:
         print('**************************************')
         for number, set in enumerate(Cell.displaySets):
             liveChar = Cell.displaySets[set]['liveChar']
             deadChar = Cell.displaySets[set]['deadChar']
             print(f'{number + 1}: living cells: {liveChar} dead cells: {deadChar}')
         print(f'{number + 2}: pick your own characters')
         print('**************************************')
         prompt = 'What character set would you like to use?'
         whichCharacters = toolbox.get_integer_between(1, number + 2, prompt)
         if whichCharacters == number + 2:
             alive = toolbox.get_string('Which character should represent alive cells?')
             dead = toolbox.get_string('Which character should represent dead cells?')
             Cell.set_display_user_values(alive, dead)
     setString = list(Cell.displaySets.keys())[whichCharacters - 1]
     Cell.set_display(setString)
     self.display()
Esempio n. 12
0
def main():
    print('---Blackjack 0.5---\n')
    table = Table(doubleOn=[9, 10, 11])
    dealer = Dealer('Dealer', 1000000)
    dealer.sit(table)
    #
    # Deck Stacking:
    #
    dealer._shoe.append(Card('ace', 'spades'))
    dealer._shoe.append(Card('ace', 'hearts'))
    #
    #
    #
    numberOfPlayers = get_integer_between(1, 7, 'How many players?')
    for number in range(1, numberOfPlayers + 1):
        name = get_string(f"What is player {number}'s name?")
        player = HumanPlayer(name, 100)
        player.sit(table)
    dealer.take_bets()
    while table.has_players():
        dealer.deal()
        dealer.offer_insurance()
        dealer.play_hands()
        dealer.play_own_hand()
        dealer.payout_hands()
        dealer.take_bets()
    print('\n---There are no more players. Game Over.---')
Esempio n. 13
0
 def change_display(self, parameter):
     """
     Print possible display changes for the user.
     :param parameter:
     :return: none
     """
     if toolbox.is_integer(parameter) and \
             1 <= int(parameter) <= len(Cell.displaySets.keys()):
         setNumber = int(parameter)
     else:
         print('**************************************')
         for number, set in enumerate(Cell.displaySets):
             liveChar = Cell.displaySets[set]['liveChar']
             deadChar = Cell.displaySets[set]['deadChar']
             print(
                 f'{number+1}: living cells: {liveChar} dead cells: {deadChar}'
             )
         print(f'{number+2}: Choose your own characters! ')
         print('**************************************')
         prompt = 'What character set would you like to use?'
         setNumber = toolbox.get_integer_between(1, number + 2, prompt)
         numberOfSets = number + 2
     if setNumber == numberOfSets:
         setString = 'choice'
     else:
         setString = list(Cell.displaySets.keys())[setNumber - 1]
     Cell.set_display(setString)
     print(self.__currentWorld, end='')
Esempio n. 14
0
 def change_size(self, parameter):
     if parameter and ('x' in parameter):
         rows, columns = parameter.split('x', 2)
         if toolbox.is_integer(rows) and toolbox.is_integer(columns):
             rows = int(rows)
             columns = int(columns)
     else:
         #
         # Can not have 1x1, 1x2, etc because it would out of range; at least is 2x2 world.
         #
         prompt = 'How many rows of cells?'
         rows = toolbox.get_integer_between(2, 40, prompt)
         prompt = 'How many cells in each row?'
         columns = toolbox.get_integer_between(2, 120, prompt)
     self.__world = self.__worldType(rows, columns)
     self.random()
Esempio n. 15
0
 def change_speed(self, speed):
     """Change the delay betwen generations of the simulation."""
     if toolbox.is_number(speed):
         speed = int(speed)
     else:
         prompt = 'How fast should the generations update?'
         speed = toolbox.get_integer_between(0, 11, prompt)
     self.__delay = Life.speeds[speed]
Esempio n. 16
0
 def set_geometry(self):
     userGeo = toolbox.get_integer_between(1, 2, """
     Choose 1 or 2:
     1. Basic Geometry 
     2. Donut Geometry""")
     self.__world.set_geometry(userGeo)
     print(self.__world, end='')
     print(self.status() + '\n' + self.menu(), end=' ')
Esempio n. 17
0
 def create_world(self, parameter):
     """Creates a new world"""
     if parameter != None:
         sizes = parameter.split(' ')
         rows = sizes[0]
         columns = sizes[1]
     else:
         rows = get_integer_between("How many rows do you want? ", 1, 250, 0)
         columns = get_integer_between("How many columns do you want? ", 1, 1001, 0)
     self.clear_world()
     self.add_world(int(rows), int(columns))
     self.world.create_cells()
     if self.world.geometry == 'dish':
         self.world.count_neighbors()
     elif self.world.geometry == 'donut':
         self.world.count_neighbors_donut()
     print('')
Esempio n. 18
0
 def get_columns(self):
     """
     gets amount of columns in new world from user
     :return: columns
     """
     # Is is error when you have 1x1 world, so let's have 2x2 instead
     columns = toolbox.get_integer_between(2,120,"How many columns do you want in your world? ")
     return columns
 def get_plot(self):
     counter = 0
     for plots in self.totalPlots:
         if plots.get_owned():
             counter += 1
     whichPlot = toolbox.get_integer_between(1, counter, "Which plot? ", "**ERROR: You must choose an owned plot**")
     whichPlot = whichPlot - 1
     return whichPlot
Esempio n. 20
0
 def get_rows(self):
     """
     Gets amount of rows in new world from user.
     :return: rows
     """
     # Is is error when you have 1x1 world, so let's have 2x2 instead
     rows = toolbox.get_integer_between(2,50,"How many rows do you want in your world? ")
     return rows
Esempio n. 21
0
 def change_fillrate(self, parameter):
     """Change the fillrate for the simulation."""
     if toolbox.is_number(parameter) and 0 <= float(parameter) <= 100:
         fillrate = float(parameter)
     else:
         prompt = 'What percent of cells should be alive?'
         fillrate = toolbox.get_integer_between(0, 100, prompt)
     self.__fillrate = fillrate
     self.random()
Esempio n. 22
0
 def change_geometry(self):
     string = '1. Flat World'
     string += '/n2. Torus World'
     print(string)
     choice = toolbox.get_integer_between(1, 2, 'Which geometry type would you like?: ')
     if choice == 1:
         self.__worldType = World
     else:
         self.__worldType = World_Torus
Esempio n. 23
0
 def change_speed(self, speed=None):
     """
     Create a new world with the given percent of cells alive.
     :param percentAlive: [optiona] Number of living cells out of total cells.
     :return: None
     """
     if (speed is None) or (speed not in [0,1,2,3,4,5,6,7,8,9,10]):
         speed = get_integer_between(0, 10, 'What speed?')
     self.delay = Simulation.delayList[speed]
     self.message = f'speed set to {speed}'
     print(self)
Esempio n. 24
0
 def fill_size(self, parameter):
     """
     Allow user to change the current fill percent of the world
     :param parameter:
     :return: none
     """
     prompt = 'What percent of cells should be alive? '
     percent = toolbox.get_integer_between(1, 100, prompt)
     self.__currentPercent = percent
     w1 = self.__worldType(self.__rows, self.__columns,
                           self.__currentPercent)
     print(w1)
Esempio n. 25
0
 def get_category(self):
     print("\nHere are your categories of words to choose from:")
     print("1. Animals     2. Foods     3. Sports")
     self.__categoryChoice = toolbox.get_integer_between(
         1, 3, 'Which category do you want to use? ')
     if self.__categoryChoice == 1:
         self.__categoryChoice = wordList1
     elif self.__categoryChoice == 2:
         self.__categoryChoice = wordList2
     else:
         self.__categoryChoice = wordList3
     return self.__categoryChoice
Esempio n. 26
0
 def change_fillrate(self, fillrate):
     """
     Change the fillrate for the simulation.
     :param fillrate:
     :return: fillrate
     """
     if toolbox.is_number(fillrate) and 0 <= float(fillrate) <= 100:
         fillrate = float(fillrate)
     else:
         prompt = 'What percent of cells do you want to be alive?'
         fillrate = toolbox.get_integer_between(0, 100, prompt)
     self.__fillrate = fillrate
     self.random()
Esempio n. 27
0
 def populate_world(self, parameter):
     """Populates the world based on the users input"""
     if self.world == None:
         print("You haven't made a world yet")
     else:
         if parameter != None:
             percent = parameter
         else:
             percent = get_integer_between("What percentage do you want to be alive? ", 0, 100, 101)
         for row in self.world.cells:
             for cell in row:
                 cell.die()
         self.world.populate_cells(int(percent))
Esempio n. 28
0
 def change_fillrate(self, parameter):
     """
     Change the fillrate for the simulation.
     :param parameter:
     :return: None
     """
     if toolbox.is_number(parameter) and 0 <= float(parameter) <= 100:
         fillrate = float(parameter)
     else:
         prompt = 'What percent of cells should be alive?'
         fillrate = toolbox.get_integer_between(0, 100, prompt)
     self.__fillrate = fillrate
     self.random()
     print(f'The percent of alive cells is now {fillrate} percent.')
Esempio n. 29
0
 def run_simulation(self, parameter):
     """Displays the next generation of the world"""
     if toolbox.is_integer(parameter) and int(parameter) > 0:
         generations = int(parameter)
     else:
         prompt = 'How many generations would you like to simulate?'
         generations = toolbox.get_integer_between(1, 10000, prompt)
     for generation in range(generations):
         self.__world.next_generation()
         string = self.__world.__str__()
         string += self.status()
         string += f'left: {generations - generation}'
         print(string)
         time.sleep(self.__delay)
     print(self.menu(), end=' ')
Esempio n. 30
0
 def skip_generations(self, generations):
     """Displays the next generation of the world"""
     if toolbox.is_integer(generations) and int(generations) > 0:
         generations = int(generations)
     else:
         prompt = 'How many generations would you like to skip?'
         generations = toolbox.get_integer_between(1, 10000, prompt)
     print(f'Skipping {generations} generations.', end='')
     for generation in range(generations):
         self.__world.next_generation()
         if generation % 100 == 0:
             print('.', end='')
     print(' done!')
     self.__generations = generations
     time.sleep(2)
     self.display()