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


Python AI.difficulty方法代码示例

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


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

示例1: game_board

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import difficulty [as 别名]
    def game_board(self, board, player_one, player_two, player_types, ai_difficulty=None):

        from player_data import PlayerData

        pd=PlayerData()

        if 'AI' in player_types:
            from ai import AI
            ai=AI()
            if 'AI: Easy' in [player_one,player_two]:
                ai.difficulty=0
            elif 'AI: Medium' in [player_one,player_two]:
                ai.difficulty=1
            elif 'AI: Hard' in [player_one,player_two]:
                ai.difficulty=2

        sdl2ext.init()

        window = sdl2ext.Window("c4o5x5", size=(320, 420))

        window.show()

        factory = sdl2ext.SpriteFactory(sdl2ext.SOFTWARE)

        spriterenderer = factory.create_sprite_render_system(window)

        moves = 0
        running = True
        updated_p1 = False
        updated_p2 = False

        while running:
            if moves % 2 == 0:
                this_player = player_one
                that_player = player_two
                if player_types[0]=='AI':
                    mode='AI'
                    player_graphic="ai.bmp"
                else:
                    mode='Human'
                    player_graphic = "player_one.bmp"
            if moves % 2 == 1:
                this_player = player_two
                that_player = player_one
                if player_types[1]=='AI':
                    mode='AI'
                    player_graphic="ai.bmp"
                else:
                    mode='Human'
                    player_graphic = "player_two.bmp"
            for x in range(5):
                for y in range(5):
                    if board.marks[x][y] is None:
                        spriterenderer.render(factory.from_image(self.RESOURCES.get_path("tile.bmp")),x*64,y*64)
                    if board.marks[x][y] == player_one:
                        spriterenderer.render(factory.from_image(self.RESOURCES.get_path("tile_o.bmp")),x*64,y*64)
                    if board.marks[x][y] == player_two:
                        spriterenderer.render(factory.from_image(self.RESOURCES.get_path("tile_x.bmp")),x*64,y*64)
            if board.check_winning_positions() != (False,False):
                winning_player = board.check_winning_positions()[0]
                if winning_player == player_one:
                    winning_graphic = 'player_one_wins.bmp'
                    if player_one != 'Guest' and not updated_p1:
                        player=pd.load_player(player_one)
                        pd.update_player(player_one,player.wins+1,player.losses)
                        updated_p1 = True
                    if player_two != 'Guest' and not updated_p2:
                        player=pd.load_player(player_two)
                        pd.update_player(player_two,player.wins,player.losses+1)
                        updated_p2=True
                elif winning_player == player_two:
                    winning_graphic = 'player_two_wins.bmp'
                    if player_one != 'Guest' and not updated_p2:
                        player=pd.load_player(player_two)
                        pd.update_player(player_two,player.wins+1,player.losses)
                        updated_p2=True
                    if player_two != 'Guest' and not updated_p1:
                        player=pd.load_player(player_one)
                        pd.update_player(player_one,player.wins,player.losses+1)
                        updated_p1=True
                spriterenderer.render(factory.from_image(self.RESOURCES.get_path(winning_graphic)),0,(x+1)*64)
                events = sdl2ext.get_events()
                for event in events:
                    if event.type == SDL_MOUSEBUTTONDOWN:
                        running = False
                        SDL_Delay(1000)
                        break
            elif moves == 25:
                winning_graphic = "tie_game.bmp"
                spriterenderer.render(factory.from_image(self.RESOURCES.get_path(winning_graphic)),0,(x+1)*64)
                events = sdl2ext.get_events()
                for event in events:
                    if event.type == SDL_MOUSEBUTTONDOWN:
                        running = False
                        break
            elif mode == 'Human':
                spriterenderer.render(factory.from_image(self.RESOURCES.get_path(player_graphic)),0,(x+1)*64)
                events = sdl2ext.get_events()
                for event in events:
                    if event.type == SDL_QUIT:
#.........这里部分代码省略.........
开发者ID:fooziex,项目名称:cs3420,代码行数:103,代码来源:display_board.py


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