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


Python AI.play方法代码示例

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


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

示例1: test_ai_play_a_game

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import play [as 别名]
 def test_ai_play_a_game(self):
     ai = AI()
     self.assertEqual(ai.play(1), Game.IN_PROGRESS)
     self.assertEqual(ai.at(4), Game.O)
     self.assertEqual(ai.play(8), Game.IN_PROGRESS)
     self.assertEqual(ai.at(0), Game.O)
     self.assertEqual(ai.play(2), Game.IN_PROGRESS)
     self.assertEqual(ai.at(5), Game.O)
     self.assertEqual(ai.play(6), Game.O_WINS)
开发者ID:alexnad,项目名称:HackBulgaria-Programming-101-2,代码行数:11,代码来源:ai_tests.py

示例2: test_ai_winning

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import play [as 别名]
    def test_ai_winning(self):
        ai = AI(['o', ' ', 'x',
                 ' ', ' ', ' ',
                 ' ', ' ', 'o'])

        self.assertEqual(ai.winning(), 4)
        self.assertEqual(ai.play(1), Game.O_WINS)
开发者ID:alexnad,项目名称:HackBulgaria-Programming-101-2,代码行数:9,代码来源:ai_tests.py

示例3: test_opponent_next_move_is_winning

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import play [as 别名]
    def test_opponent_next_move_is_winning(self):
        ai = AI(['x', ' ', 'o',
                 ' ', ' ', ' ',
                 ' ', ' ', 'x'])

        self.assertEqual(ai.opponent_winning(), 4)
        self.assertEqual(ai.play(4), Game.X_WINS)
开发者ID:alexnad,项目名称:HackBulgaria-Programming-101-2,代码行数:9,代码来源:ai_tests.py

示例4: __init__

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import play [as 别名]
class CLI:
    def __init__(self):
        self._game = AI()

    def play(self):
        outcome = Game.IN_PROGRESS
        while outcome == Game.IN_PROGRESS:
            self._draw_board()
            move = None
            while move is None:
                move = self._get_move()

            outcome = self._game.play(move)
            self._clear()
        self._announce_outcome(outcome)

    def _announce_outcome(self, outcome):
        if outcome == Game.X_WINS:
            print('Congratulations! You won!')
        if outcome == Game.O_WINS:
            print('Sorry, you loose. Better luck next time')
        else:
            print('It\'a a tie')

    def _get_move(self):
        try:
            position = int(input('Enter your move>'))
            if self._game.valid_move(position):
                return position
            print("Wrong input!")
        except ValueError:
            print("Wrong input!")
            return None

    def _clear(self):
        os.system('clear')

    def _draw_board(self):
        state = self._game.current_state()
        symbols = {str(place): symbol for place, symbol in enumerate(state)}
        print(self._fill_board(symbols))

    def _fill_board(self, symbols):
        new_board = []
        for character in BOARD:
            if character in symbols and symbols[character] != Game.EMPTY:
                new_board.append(symbols[character])
            else:
                new_board.append(character)

        return "".join(new_board)
开发者ID:alexnad,项目名称:HackBulgaria-Programming-101-2,代码行数:53,代码来源:cli.py

示例5: Game

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import play [as 别名]
class Game():

    def __init__(self, game_size=4):
        self.game_progress = 0
        self.game_steps = list()
        self.game_size = game_size
        self.player = Player(game_size)
        self.ai = AI(game_size)
        
    def play(self):
        while True:
            self.game_progress += 1
            
            print
            print "Step %d" % self.game_progress
            print
            
            answer = self.player.play()
            if answer['bulls'] == self.game_size:
                print("Congratz! You won!")
                exit()
            else:
                print("%db %dc" % (answer['bulls'], answer['cows']))

            repeat_question = None
            while self.game_progress > len(self.game_steps):
                asked_number, answer = self.ai.play(repeat_question)
                            
                self.game_steps.append((asked_number, answer))
                if answer['bulls'] == self.game_size:
                    print("Hehe, I won!")
                    exit()
                if len(self.ai.possible_numbers) == 0:
                    print("You, liar!")
                    step = raw_input("On which step did you lie: ")
                    while not re.match(r'^\d+$', step) or not (1 <= int(step) <= len(self.game_steps)):
                        print("Invalid step.")
                        step = raw_input("On which step did you lie: ")

                    step = int(step)-1
                    repeat_question = self.game_steps[step][0]
                    self.game_steps = self.game_steps[:step]
                    self.ai.replay(self.game_steps)
                else:
                    repeat_question = None
开发者ID:lachezar,项目名称:cows-and-bulls,代码行数:47,代码来源:cows_and_bulls.py

示例6: assertOposites

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import play [as 别名]
 def assertOposites(self, expected_oposite, given_oposite, board=None):
     ai = AI(board)
     ai.play(given_oposite)
     self.assertEqual(ai.at(expected_oposite), Game.O)
开发者ID:alexnad,项目名称:HackBulgaria-Programming-101-2,代码行数:6,代码来源:ai_tests.py

示例7: BrowserControl

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import play [as 别名]
from browsercontrol import BrowserControl
from ai import AI
	

browserctl = BrowserControl()
AI = AI(browserctl)

AI.play()

print "Total moves: %s" % AI.move_count
	


开发者ID:ishuah,项目名称:2048pybot,代码行数:12,代码来源:2048.py


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