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


Python Board.load方法代码示例

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


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

示例1: test_constructor

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
    def test_constructor(self):
        board = Board()
        board.load('ooxxxo   ')
        root = Node(board)

        self.assertEquals(root.children, [])
        self.assertEquals(root.best_x_outcome, None)
开发者ID:sjbrown,项目名称:tictactoe,代码行数:9,代码来源:test_generate.py

示例2: make_root

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
def make_root():
    '''Creates a datastructure with all possible tic tac toe boards.
    Takes about 5 minutes
    '''
    b = Board()
    b.load('         ')
    root = Node(b)
    root.descend()
    memo_dict[root.board.dump()] = root
    return root
开发者ID:sjbrown,项目名称:tictactoe,代码行数:12,代码来源:generate_all_possible.py

示例3: test_leaf_nodes

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
    def test_leaf_nodes(self):
        b = Board()
        b.load('ooxxxox  ')
        root = Node(b)

        root.descend()

        self.assertEquals(root.best_x_outcome, 1)
        self.assertEquals(root.best_o_outcome, -1)
        self.assertEquals(root.minmax_choice, None)

        b = Board()
        b.load('oooxx    ')
        root = Node(b)

        root.descend()

        self.assertEquals(root.best_x_outcome, -1)
        self.assertEquals(root.best_o_outcome, 1)
        self.assertEquals(root.minmax_choice, None)
开发者ID:sjbrown,项目名称:tictactoe,代码行数:22,代码来源:test_generate.py

示例4: test_load

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
    def test_load(self):
        board = Board()
        board.load('xoxoxoxox')
        self.assertEquals(str(board), '''\
                      1   2   3
                        |   |   
                 A    x | o | x 
                        |   |   
                     ---+---+---
                        |   |   
                 B    o | x | o 
                        |   |   
                     ---+---+---
                        |   |   
                 C    x | o | x 
                        |   |   
''')

        board.load('xo ox xo ')
        self.assertEquals(str(board), '''\
                      1   2   3
                        |   |   
                 A    x | o |   
                        |   |   
                     ---+---+---
                        |   |   
                 B    o | x |   
                        |   |   
                     ---+---+---
                        |   |   
                 C    x | o |   
                        |   |   
''')

        with self.assertRaises(BoardException):
            board.load('') # too few chars
        with self.assertRaises(BoardException):
            board.load('xxxoooxxxo') # too many chars
        with self.assertRaises(BoardException):
            board.load('Axxoooxxx') # wrong chars
开发者ID:sjbrown,项目名称:tictactoe,代码行数:42,代码来源:test_board.py

示例5: test_open_spots

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
    def test_open_spots(self):
        board = Board()
        board.load('         ')
        self.assertEquals( range(9), list(board.open_spots))

        board.load('xxo   oox')
        self.assertEquals( [3,4,5], list(board.open_spots))

        board.load('xxoooxoox')
        self.assertEquals( [], list(board.open_spots))
开发者ID:sjbrown,项目名称:tictactoe,代码行数:12,代码来源:test_board.py

示例6: test_descend

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
    def test_descend(self):
        board = Board()
        board.load('ooxxxo   ')
        root = Node(board)

        root.descend()

        b1 = Board()
        b1.load('ooxxxoo  ')
        c1 = Node(b1)
        b2 = Board()
        b2.load('ooxxxo o ')
        c2 = Node(b2)
        b3 = Board()
        b3.load('ooxxxo  o')
        c3 = Node(b3)
        expected = [c1, c2, c3]

        self.assertEquals(root.children, expected)
开发者ID:sjbrown,项目名称:tictactoe,代码行数:21,代码来源:test_generate.py

示例7: test_calc_winner

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
    def test_calc_winner(self):
        board = Board()
        board.load('         ')
        winner = calc_winner(board)
        self.assertEquals(None, winner)

        board.load('xxxo o o ')
        winner = calc_winner(board)
        self.assertEquals('x', winner)

        board.load(' x x xooo')
        winner = calc_winner(board)
        self.assertEquals('o', winner)
开发者ID:sjbrown,项目名称:tictactoe,代码行数:15,代码来源:test_board.py

示例8: test_minmax

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
    def test_minmax(self):
        # Game with a clear winner
        b = Board()
        b.load('oo xx    ')
        root = Node(b)
        root.descend()

        self.assertEquals(root.board.next_player, 'o')

        b1 = Board()
        b1.load('oooxx    ')
        node1 = Node(b1)

        self.assertEquals(root.minmax_choice, node1)

        # Tie game
        b = Board()
        b.load('ooxxxoo  ')
        root = Node(b)
        root.descend()

        self.assertEquals(root.board.next_player, 'x')
        self.assertEquals(root.best_x_outcome, 0)
        self.assertEquals(root.best_o_outcome, 0)
开发者ID:sjbrown,项目名称:tictactoe,代码行数:26,代码来源:test_generate.py

示例9: Game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]

#.........这里部分代码省略.........
            "board": self.board.get_data(),
            "small_boards": [[
                self.get_small_board((x, y)).get_data()
                for x in range(self.cells_x)]
                for y in range(self.cells_y)],
            "board_win": self.board.get_data_win(),
            "small_boards_win": [
                self.get_small_board(coords).get_data_win()
                for coords in self.board.iter_coords()],
            "small_boards_lines": [[
                (self.get_small_board((x, y)).get_data_win()
                    and self.get_small_board((x, y)).get_data_win()[1])
                for x in range(self.cells_x)]
                for y in range(self.cells_y)],
            "last_turn": (
                self.get_last_turn() and
                (self.get_last_turn()[1] + self.get_last_turn()[2])),
            "last_turn_player": (
                self.get_last_turn() and self.get_last_turn()[0].get_team()),
        }

    def dump(self):
        return {
            "board": self.board.dump(),
            "small_boards": dict([
                (coords, self.get_small_board(coords).dump())
                for coords in self.board.iter_coords()]),
            "data_dumped": self.data_dumped,
            "winner": self.winner,
            "player": self.player,
            "player_turn": copy.deepcopy(self.player_turn),
        }

    def load(self, data):
        self.board.load(data["board"])
        for coords in self.board.iter_coords():
            self.get_small_board(coords).load(data["small_boards"][coords])
        self.data_dumped = data["data_dumped"]
        self.winner = data["winner"]
        # self.player = data["player"]
        self.player_turn = data["player_turn"]

    def get_possible_coords(self, player):
        'Get all cell coords that player can turn into.'
        result = []

        for coords in self.board.iter_coords():
            force_turn_coords = player.get_force_turn()
            if force_turn_coords and force_turn_coords != coords:
                continue

            small_board = self.get_small_board(coords)
            for small_coords in small_board.iter_coords():
                if small_board.is_field_empty(small_coords):
                    result.append((coords, small_coords))

        return result

    def get_winner(self):
        return self.winner

    def draw_boards(self):
        res = []
        for y in range(self.board.size_y ** 2 + self.board.size_y - 1):
            res.append([])
            res[-1].append('-' * self.board.size_x)
开发者ID:Volshebnyi,项目名称:python-deeptactoe,代码行数:70,代码来源:game.py

示例10: genRandomBoard

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import load [as 别名]
		print self.board.toString()
		self.printLines()

def genRandomBoard(xSize, ySize):
	board = Board(xSize, ySize)

	print board.getBoard()

	for i in xrange(xSize):
		for j in xrange(ySize):
			state = random.choice([True, False])
			board.setState(i,j,state)

	return board




initialBoard = Board(25,25)
initialBoard.load('cool.txt')


#initialBoard = genRandomBoard(30,190)
#initialBoard.save('board.txt')


game = Game(initialBoard)

game.printBoard()
game.playGame()
开发者ID:DownMoney,项目名称:Conway,代码行数:32,代码来源:game.py


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