当前位置: 首页>>代码示例>>Python>>正文


Python game.Game方法代码示例

本文整理汇总了Python中game.Game方法的典型用法代码示例。如果您正苦于以下问题:Python game.Game方法的具体用法?Python game.Game怎么用?Python game.Game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在game的用法示例。


在下文中一共展示了game.Game方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_game

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def new_game(self, chat):
        """
        Create a new game in this chat
        """
        chat_id = chat.id

        self.logger.debug("Creating new game in chat " + str(chat_id))
        game = Game(chat)

        if chat_id not in self.chatid_games:
            self.chatid_games[chat_id] = list()

        # remove old games
        for g in list(self.chatid_games[chat_id]):
            if not g.players:
                self.chatid_games[chat_id].remove(g)

        self.chatid_games[chat_id].append(game)
        return game 
开发者ID:jh0ker,项目名称:mau_mau_bot,代码行数:21,代码来源:game_manager.py

示例2: new_atari_game

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def new_atari_game(rom='breakout'):
    
    from game import Game
    game = Game(rom)
    
    if rom == 'space_invaders':
        game.set_params(frame_skip=3, lost_life_as_terminal=False, take_maximum_of_two_frames=True)
    elif game == 'alien':
        game.set_params(frame_skip=4, crop_offset=20, lost_life_as_terminal=False)
    else:
        game.set_params(frame_skip=4, lost_life_as_terminal=False)
    
    parameter = Parameter(lr=7e-4)
    parameter.gamma = 0.99
    parameter.num_history_frames = 4
    
    parameter.async_update_interval = 20
    parameter.max_iter_num = 16 * 10 ** 7
    parameter.update_method = 'rmsprop'
    parameter.rho = 0.99
    parameter.rmsprop_epsilon = 1e-1 # 1e-3 if rom == 'breakout' else 1e-1
    
    time.sleep(1)
    return game, parameter 
开发者ID:PacktPublishing,项目名称:Python-Reinforcement-Learning-Projects,代码行数:26,代码来源:environment.py

示例3: new_minecraft

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def new_minecraft(rom='MinecraftBasic-v0'):
    
    from minecraft.game import Game
    game = Game(rom)
    
    parameter = Parameter(lr=7e-4)
    parameter.gamma = 0.99
    parameter.num_history_frames = 4
    
    parameter.async_update_interval = 20
    parameter.max_iter_num = 16 * 10 ** 7
    parameter.update_method = 'rmsprop'
    parameter.rho = 0.99
    parameter.rmsprop_epsilon = 1e-3
    
    time.sleep(1)
    return game, parameter 
开发者ID:PacktPublishing,项目名称:Python-Reinforcement-Learning-Projects,代码行数:19,代码来源:environment.py

示例4: new_demo

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def new_demo(test=True):
    import pygame
    from demo.game import Game
    
    if test is False:
        game = Game(640, 480, None)
    else:
        def _render(game):
            while True:
                game.draw()
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_9:
                            game.increase_fps()
                        elif event.key == pygame.K_0:
                            game.decrease_fps()    
        pygame.init()
        DISPLAYSURF = pygame.display.set_mode((640, 480), 0, 32)
        pygame.display.set_caption('Demo')
        game = Game(640, 480, DISPLAYSURF)
        t = Thread(target=lambda: _render(game))
        t.start()
    
    return game 
开发者ID:PacktPublishing,项目名称:Python-Reinforcement-Learning-Projects,代码行数:26,代码来源:environment.py

示例5: test_head_to_head

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def test_head_to_head(self):
        # Make the AI play against itself a bunch of times. Randomize which
        # side starts. Every game should take a full 9 moves, and every gamee
        # should end with a draw.
        for i in range(100):
            g = game.Game()
            player = random.choice('XO')
            n = 0
            while True:
                cell = ai.next_move(g, player)
                g[cell] = player
                n += 1
                w = g.winner()
                if w:
                    if w != g.first or n != 9:
                        self.fail('Game won unexpectedly:\n%s.' % str(g))
                    break
                if n == 9:
                    break
                player = game.other_player(player) 
开发者ID:hyperledger,项目名称:aries-rfcs,代码行数:22,代码来源:test_tictactoe.py

示例6: prompt_user

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def prompt_user(self):
        self.computer.print_board()
        while self.game.status < 2:
            user_move = raw_input("Make a move: ")
            while user_move not in self.game.get_moves() and user_move != "ff":
                user_move = raw_input("Please enter a valid move: ")
            if user_move == "ff":
                break;
            self.game.apply_move(user_move)
            start_time = time.time()
            self.computer.print_board()
            print("\nCalculating...\n")
            if self.game.status < 2:
                current_state = str(self.game)
                computer_move = self.computer.ab_make_move(current_state)
                PIECE_NAME = {'p': 'Pawn', 'b': 'Bishop', 'n': 'Knight', 'r': 'Rook', 'q': 'Queen', 'k': 'King'}
                print("Computer moved " + PIECE_NAME[self.game.board.get_piece(self.game.xy2i(computer_move[:2]))] + " at " + computer_move[:2] + " to " + computer_move[2:])
                self.game.apply_move(computer_move)
            self.computer.print_board()
            print("Elapsed time in sec: {time}".format(time=time.time() - start_time))
        user_move = raw_input("Game over. Play again? y/n: ")
        if user_move.lower() == "y":
            self.game = Game()
            self.computer.game = self.game
            self.prompt_user() 
开发者ID:lamesjim,项目名称:Chess-AI,代码行数:27,代码来源:multi_chess_ai.py

示例7: get_heuristic

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def get_heuristic(self, board_state=None):
        cache_parse = board_state.split(" ")[0] + " " + board_state.split(" ")[1]
        if board_state == None:
            board_state = str(self.game)
        if cache_parse in self.cache:
            self.found_in_cache += 1
            return self.cache[cache_parse]
        clone = Game(board_state)
        total_points = 0
        # total piece count
        total_points += heuristics.material(board_state, 100)
        total_points += heuristics.piece_moves(clone, 50)
        total_points += heuristics.in_check(clone, 1)
        total_points += heuristics.pawn_structure(board_state, 1)
        self.cache[cache_parse] = total_points
        return total_points 
开发者ID:lamesjim,项目名称:Chess-AI,代码行数:18,代码来源:chess_ai.py

示例8: __init__

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def __init__(self, output, inputs):
    self._game = Game()
    self._output = output
    self._inputs = inputs 
开发者ID:gynvael,项目名称:stream,代码行数:6,代码来源:harness.py

示例9: main

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def main():
    g = Game()

    while True:
        g.add_move()
        g.show_level()
        if not g.test_player():
            print("Sorry, that was wrong")
            break

    print("Game over") 
开发者ID:mikeckennedy,项目名称:python-for-entrepreneurs-course-demos,代码行数:13,代码来源:program.py

示例10: start_games

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def start_games(amount_of_games):
    player_a_wins = 0
    player_b_wins = 0
    games_played = 0

    logging.info("Starting Open MTG. Playing {0} games".format(amount_of_games))
    for i in range(amount_of_games):
        gold_deck = deck.get_8ed_core_gold_deck()
        silver_deck = deck.get_8ed_core_silver_deck()
        current_game = game.Game([player.Player(gold_deck), player.Player(silver_deck)])
        current_game.start_game()

        if current_game.active_player.index == 0:
            logging.info("Gold player starts game")
        else:
            logging.info("Silver player starts game")
        while not current_game.is_over():
            if current_game.player_with_priority.index is 1:
                move = current_game.player_with_priority.determine_move(method="random", game=current_game)
            else:
                # move = game.player_with_priority.determine_move(method="random", game=game)
                if len(current_game.get_moves()) == 1:
                    move = current_game.get_moves()[0]
                else:
                    move = mcts.uct(current_game, itermax=5)

            current_game.make_move(move, False)

        if current_game.players[1].has_lost:
            player_a_wins += 1
        elif current_game.players[0].has_lost:
            player_b_wins += 1
        games_played += 1
        logging.info("Game {0} is over! current standings: "
                     "{1} - {2}".format(games_played, player_a_wins, player_b_wins))

    logging.info("Player A won {0} out of {1}".format(player_a_wins, games_played))
    logging.info("Player B won {0} out of {1}".format(player_b_wins, games_played))
    logging.info("Quitting Open MTG{0}{0}".format(os.linesep)) 
开发者ID:hlynurd,项目名称:open-mtg,代码行数:41,代码来源:main.py

示例11: setUp

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def setUp(self):
        self.game = Game(None) 
开发者ID:jh0ker,项目名称:mau_mau_bot,代码行数:4,代码来源:test_player.py

示例12: new_demo

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def new_demo(test=False):
    
    import pygame
    from demo.game import Game
    if test is False:
        game = Game(640, 480, None)
    else:
        def _render(game):
            while True:
                game.draw()
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_9:
                            game.increase_fps()
                        elif event.key == pygame.K_0:
                            game.decrease_fps()    
        pygame.init()
        DISPLAYSURF = pygame.display.set_mode((640, 480), 0, 32)
        pygame.display.set_caption('Demo')
        game = Game(640, 480, DISPLAYSURF)
        t = Thread(target=lambda: _render(game))
        t.start()
    
    parameter = Parameter(lr=1e-3)
    parameter.gamma = 0.9
    parameter.iteration_num = 300000
    parameter.num_history_frames = 1
    parameter.network_type = 'mlp'
    
    parameter.update_method = 'rmsprop'
    parameter.rho = 0.95
    parameter.async_update_interval = 5
    parameter.input_scale = 1.0
    
    return game, parameter 
开发者ID:PacktPublishing,项目名称:Python-Reinforcement-Learning-Projects,代码行数:37,代码来源:environment.py

示例13: new_atari_game

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def new_atari_game(rom='breakout'):
    from game import Game
    
    game = Game(rom)
    
    if rom == 'space_invaders':
        game.set_params(frame_skip=3, lost_life_as_terminal=False, take_maximum_of_two_frames=True)
    elif game == 'alien':
        game.set_params(frame_skip=4, crop_offset=20, lost_life_as_terminal=False)
    else:
        game.set_params(frame_skip=4, lost_life_as_terminal=False)
        
    return game 
开发者ID:PacktPublishing,项目名称:Python-Reinforcement-Learning-Projects,代码行数:15,代码来源:environment.py

示例14: setUp

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def setUp(self):
        self.game = game.Game() 
开发者ID:hyperledger,项目名称:aries-rfcs,代码行数:4,代码来源:test_tictactoe.py

示例15: test_set_item_with_bad_value

# 需要导入模块: import game [as 别名]
# 或者: from game import Game [as 别名]
def test_set_item_with_bad_value(self):
        bad_values = ['',None,'*','0',1,0]
        for bad in bad_values:
            self.game = game.Game() # reset state
            with self.assertRaises(ValueError):
                self.game['a1'] = bad 
开发者ID:hyperledger,项目名称:aries-rfcs,代码行数:8,代码来源:test_tictactoe.py


注:本文中的game.Game方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。