コード例 #1
0
def createAndStartGame(user):
    """ Create a game and start playing """

    game = Game(humanUser=user,
                initialFoodCount=20,
                initialSmartAiCount=1,
                initialRandomAiCount=5)
    game.start()
コード例 #2
0
ファイル: main.py プロジェクト: j-rogers/pbabot
    def __init__(self, game: str, data_file: str = DATA):
        """Init"""
        # Set command prefix
        super().__init__(command_prefix='.')

        # Get all games
        for name, obj in inspect.getmembers(games, inspect.ismodule):
            if name != 'base':
                for n, o in inspect.getmembers(inspect.getmodule(obj),
                                               inspect.isclass):
                    if n not in ('Move', 'Game', 'Playbook'):
                        self.GAMES[n.lower()] = o

        # Bot properties
        self.game = self.GAMES[game](self) if game else Game(self)
        self.private_clocks = False
        self.mc = None

        # Add commands
        self.add_cog(ClockCommands(self))
        self.add_cog(ContactCommands(self))
        self.add_cog(FunctionalCommands(self))
        self.add_cog(MiscCommands(self))
        self.add_cog(HiddenCommands(self))
        self.add_cog(self.game)

        # Extract data from file
        self.memories = []
        self.dead_characters = {}
        self.clocks = []
        self.contacts = []
        self.data_file = data_file
        try:
            with open(f'{self.data_file}/clocks.json', 'rb') as file:
                clocks = jsons.loadb(file.read())
                self.clocks = [
                    Clock(clock['name'], time=clock['time'])
                    for clock in clocks
                ]
            with open(f'{self.data_file}/contacts.json', 'rb') as file:
                contacts = jsons.loadb(file.read())
                self.contacts = [
                    Contact(contact['name'], contact['description'])
                    for contact in contacts
                ]
            with open(f'{self.data_file}/memories.json', 'rb') as file:
                self.memories = jsons.loadb(file.read())
            with open(f'{self.data_file}/dead_characters.json', 'rb') as file:
                self.dead_characters = jsons.loadb(file.read())
            print('Data extracted')
        except EOFError:
            print('No data in file.')
        except FileNotFoundError:
            print('No data file found.')
        except KeyError as ke:
            print(f'KeyError while loading data: {ke}')
コード例 #3
0
def main():

    # Define the envy constants of the utility function in relation to the other players
    envy_constants_player1 = (0, .4, .3)
    envy_constants_player2 = (.4, 0, .2)
    envy_constants_player3 = (.5, .3, 0)

    # Define the guilt constants of the utility function in relation to the other players
    guilt_constants_player1 = (0, .2, .1)
    guilt_constants_player2 = (.3, 0, .1)
    guilt_constants_player3 = (.7, .4, 0)

    # Define the utility functions for each of the players
    utility1 = lambda x, p: envy__guilt_utility_function_player(
        x, p, envy_constants_player1, guilt_constants_player1)
    utility2 = lambda x, p: envy__guilt_utility_function_player(
        x, p, envy_constants_player2, guilt_constants_player2)
    utility3 = lambda x, p: envy__guilt_utility_function_player(
        x, p, envy_constants_player3, guilt_constants_player3)

    # Store these utility functions in a list
    utility_functions = [utility1, utility2, utility3]

    #Create an instance of the bargaining game with the required utility functions
    game = Game(utility_functions)
    game.simulate_game()

    #Exctract the value functions of every time step and the state transition probabilites at every time step
    value_functions = game.value_functions
    probability_matrices = game.probability_matrices

    x_data_v, y_data_v, x_label_v, y_label_v, legend_labels_v, plot_title_v = \
                                                get_value_data(value_functions)
    x_data_p, y_data_p, x_label_p, y_label_p, legend_labels_p, plot_title_p = \
                                     get_probability_data(probability_matrices)

    # Plot value functions of state "(A,A,A)"
    plt.figure(1)
    plt.plot(x_data_v, y_data_v)
    plt.xlabel(x_label_v)
    plt.ylabel(y_label_v)
    plt.legend(legend_labels_v)
    plt.title(plot_title_v)

    # Plot probability of consensus for begin state "(A,A,A)"
    plt.figure(2)
    plt.plot(x_data_p, y_data_p)
    plt.xlabel(x_label_p)
    plt.ylabel(y_label_p)
    plt.legend(legend_labels_p)
    plt.title(plot_title_p)
コード例 #4
0
 def __init__(self, audio_ready, gui_event):
     threading.Thread.__init__(self)
     self.game = Game(audio_ready, gui_event)
     self.audio_ready = audio_ready
     self.gui_event = gui_event
     self.start()
コード例 #5
0
#importation baniere accueil
banner = pygame.image.load('assets/banner.png')
banner = pygame.transform.scale(banner,(500, 500))
banner_rect = banner.get_rect()
banner_rect.x = math.ceil(screen.get_width() / 4)

#import bouton de lancement de jeux
play_button = pygame.image.load('assets/button.png')
play_button = pygame.transform.scale(play_button,(400, 150))
play_button_rect = play_button.get_rect()
play_button_rect.x = math.ceil(screen.get_width() / 3.33 + 10)
play_button_rect.y = math.ceil(screen.get_height() / 2)


#chargement du jeu
game = Game()
running = True

#boucle tant que cette condition est vrai

while running:
    #appliquer la fenetre du jeu
    screen.blit(background, (0,-200))
    
    #verifier si le jeu à commencé ou non
    if game.is_playing:
        #declancher les instructions de la partie
        game.update(screen)
        
    #verifier si le jeu n'a pas commencé
    else:
コード例 #6
0
import datetime as dt
from games import Game
from players import Player

game = Game("NFL", dt.datetime.now())
print(game)

player = Player("Veena", 0)
print(player)
コード例 #7
0
ファイル: driver.py プロジェクト: andystjean1/odds-calculator
    for url in game_urls:

        resp = requests.get(base + url)
        if (resp.status_code != 200):
            print("bad status code bye ", resp.status_code)
            print("url: ", base + url)
            quit()

        soup = BeautifulSoup(resp.content, 'html.parser')
        over_under = GO.get_over_under(soup)
        if (over_under == -1):
            print('skipping this game')
            continue

        spread = GO.get_spread(soup)
        game = Game(over_under, spread)

        #find past 5 games
        past_games = soup.find(
            'div', attrs={'class': 'tab-content sub-module__parallel'})
        teams = past_games.find_all('article')

        for t in teams:
            squad = Team(GO.get_team_name(t), GO.get_last_five_scores(t))
            if (squad.is_favorite(GO.get_favorite(soup))):
                game.favorite = squad
            else:
                game.underdog = squad

        game.display_game()
        game.check_over_under()