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


Python Board.play方法代码示例

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


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

示例1: play_against_human

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import play [as 别名]
def play_against_human():
    agent1 = Agent(Board.PLAYER_X)
    agent2 = Agent(Board.PLAYER_O)
    run_games(agent1, agent2, 100, None, False)

    human = Human(Board.PLAYER_O)
    Board.play(agent1, human, None, [False, True])
开发者ID:acidghost,项目名称:RL-tictactoe,代码行数:9,代码来源:tictactoe.py

示例2: Cotigo

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import play [as 别名]
class Cotigo(object):
    def __init__(self, size=19):
        self.canned_answers = {
            'name': "cotigo",
            'protocol_version': 2,
            'version': VERSION,
        }
        self.size = size
        self.clear()

    def clear(self):
        self.board = Board(self.size)

    def _cmd_list_commands(self, args):
        cmdlist = self.canned_answers.keys()
        for obj in dir(self):
            if obj.startswith("_cmd_"):
                cmdlist.append(obj[5:])
        return cmdlist

    def _cmd_boardsize(self, args):
        self.size = int(args[0])

    def _cmd_clear_board(self, args):
        self.clear()

    def _cmd_play(self, args):
        self.board.play(args[0], args[1][0], args[1][1:])

    def _cmd_genmove(self, args):
        while True:
            x = random.randint(0, 18)
            y = random.randint(0, 18)
            if self.board.squares[x][y] == ".":
                break
        self.board.play(args[0], x, y)
        return self.board.wacky(x) + str(y + 1)

    def process_command(self, raw_cmd):
        cmd = raw_cmd.strip()
        if cmd in self.canned_answers:
            return [self.canned_answers[cmd]]
        splitcmd = cmd.split(" ")
        if hasattr(self, "_cmd_" + splitcmd[0]):
            response = getattr(self, "_cmd_" + splitcmd[0])(splitcmd[1:])
            if response is None:
                response = [""]
            if not isinstance(response, list):
                response = [response]
            return response
        raise UnrecognizedCommand(raw_cmd)
开发者ID:jmathes,项目名称:cotigo,代码行数:53,代码来源:cotigo.py

示例3: main

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import play [as 别名]
def main():
    file_name = "games/game" + str(time.time())
    game_file = open(file_name, "w+")
    board = Board()
    print_board(board)
    validator = Validator(board)
    while not validator.game_over():
        pos = input()
        board.play(int(pos))
        print_board(board)
        indices = [i for i, x in enumerate(board.full_board()) if x == "."]
        print indices
        game_file.write("".join(board.full_board()) + "\n")
    print "Game over!"
    game_file.close()
开发者ID:yedhukrishnan,项目名称:tic-tac-toe,代码行数:17,代码来源:main.py

示例4: run_games

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import play [as 别名]
def run_games(agent1, agent2, games, modulo, show_boards):
    results = []
    for run in range(games):
        game_state, board = Board.play(agent1, agent2, modulo)
        results.append(game_state)
        if show_boards:
            print 'Game %d ended %d\n%s' % (run, game_state, board)

    return results
开发者ID:acidghost,项目名称:RL-tictactoe,代码行数:11,代码来源:tictactoe.py

示例5: Board

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import play [as 别名]
from board import Board
from techniques import melkor, eru_iluvatar, random, tit_for_tat, massive_retaliatory_strike
techniques = [melkor, eru_iluvatar, random, tit_for_tat, massive_retaliatory_strike]

technipoints = []
for i in techniques:
	technipoints.append(0)
	for j in techniques:
		gameboard = Board(i, j)
		print(gameboard.play(100))
		print(gameboard.player_one.__name__+" spent " + str(gameboard.points[0]) + " years in prison")
		print(gameboard.player_two.__name__+" spent " + str(gameboard.points[1]) + " years in prison\n")
		technipoints[-1] += gameboard.points[0]

print("\n")
for i in range(len(techniques)):
	print(techniques[i].__name__+" spent "+str(technipoints[i]) + " years in prison")
开发者ID:Maxinary,项目名称:Iterated_Prisoners_Dilemma,代码行数:19,代码来源:play.py

示例6: optimal_action

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import play [as 别名]
        end_of_game = (winner != Board.EMPTY or not possible_actions)
        if end_of_game: # END OF EPISODE
            # There can only be one winner
            if winner == Board.EMPTY:
                y_target = 0.
            elif winner == Board.BLACK:
                y_target = 1.
            else:
                y_target = -1.
        else:
            board = old_board.clone()            
            if np.random.uniform() < epsilon:
                best_action = random_policy.take_action(color, board)
            else:
                best_action = optimal_action(board, color, possible_actions)
            board.play(color, best_action)                   
            inp = board_to_feature(board.board)
            y_target = predict(inp)[0,0]
        
        #print 'Episode {} Ply {} Color played {} ytarget {}'.format(
        #        episode, ply, board.to_string(color), y_target)
        
        # Update smoothed gradients and weights
        if ply > 0:
            update_grads(old_inp)
            update_weights_2(eta * (y_target - y_old))
            
        # Finish this episode
        if end_of_game:
            break
开发者ID:gabrielhuang,项目名称:connectfour,代码行数:32,代码来源:net.py

示例7: Game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import play [as 别名]
class Game(object):
    """
    The main Tic-Tac-Toe game.

    This forms the basis of the game & is UI-independent. With light extension,
    it can do console output, GUI clients, APIs, etc.

    Because overengineering.
    """
    def __init__(self, size=None, player_marker='X'):
        super(Game, self).__init__()
        self.board = Board(size=size)
        self.player_marker = player_marker

        if self.player_marker == 'X':
            self.computer_marker = 'O'
        else:
            self.computer_marker = 'X'

        self.ai = EasyAI()

    def player_move(self, x, y):
        self.board.play(x, y, self.player_marker)
        return self.board.check_for_win() == self.player_marker

    def computer_move(self):
        x, y = self.ai.next_move(self.board)
        self.board.play(x, y, self.computer_marker)
        return self.board.check_for_win() == self.computer_marker

    def computer_turn(self):
        if not self.board.moves_left():
            return False

        if self.computer_move():
            return True

        return False

    def run(self):
        while self.board.moves_left():
            if self.player_marker == 'X':
                # If the player is the X, they get to go first.
                self.draw_board()

                if self.player_turn():
                    self.draw_win("You win!")
                    return

                self.draw_board()

                if self.computer_turn():
                    self.draw_win('The AI wins!')
                    return
            else:
                # Otherwise, the computer gets to go first.
                self.draw_board()

                if self.computer_turn():
                    self.draw_win('The AI wins!')
                    return

                self.draw_board()

                if self.player_turn():
                    self.draw_win("You win!")
                    return

        self.draw_win('Tie game. :(')

    # The unimplemented.
    def draw_board(self):
        raise NotImplementedError("Your subclass needs to implement `draw_board`.")

    def draw_win(self, message):
        raise NotImplementedError("Your subclass needs to implement `draw_board`.")

    def player_turn(self):
        raise NotImplementedError("Your subclass needs to implement `draw_board`.")
开发者ID:toastdriven,项目名称:Tic-Tac-Toe,代码行数:81,代码来源:game.py


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