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


Python Board.render方法代码示例

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


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

示例1: Game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import render [as 别名]
class Game(object):
    def __init__(self):
        self.board = Board()
        # self.display = Display(self.board)
        self.players = {"white": HumanPlayer("white"), "black": HumanPlayer("black")}
        self.current_player = "white"

    def play(self):
        # print "Game starts!"
        while not self.board.checkmate():
            # raw_input("next step")
            from_pos, to_pos = self.players[self.current_player].make_move(self.board)
            if not self.board.try_move_piece(self.current_player, from_pos, to_pos):
                continue

            self.__swap_turn()
            # self.__notify_players()

        self.board.render()

    # def __notify_players():
    #     if board.is_in_check(self.current_player)

    def __swap_turn(self):
        # self.current_player = (current_player == "white") ? "black" : "white"
        self.current_player = "black" if self.current_player == "white" else "white"
开发者ID:arthuryip723,项目名称:py-chess,代码行数:28,代码来源:game.py

示例2: main

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import render [as 别名]
def main():
	random_seed = int( time.time() * 1000 )
	print "seeding random with", random_seed
	random.seed( random_seed )

	player_one = Player( PlayerNumber.one, sys.argv[ 1 ] )
	player_two = Player( PlayerNumber.two, sys.argv[ 2 ] )

	board = Board( player_one, player_two )

	board_state = board.get_state()
	while board_state != BoardState.game_finished:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				pygame.quit()
				return

		pygame.display.update()
		board.update()
		board_state = board.get_state()

		display_surface.fill( ( 10, 10, 10 ) )
		board.render( display_surface )

		time.sleep( 0.01 )

	winning_player = board.get_winner()
	if winning_player is None:
		print "Game is a tie"
	else:
		print winning_player, "has won"


	while True:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				pygame.quit()
				return

		pygame.display.update()
		display_surface.fill( ( 10, 10, 10 ) )
		board.render( display_surface )

		time.sleep( 0.1 )
开发者ID:tomcraven,项目名称:hive,代码行数:46,代码来源:hive.py

示例3: test_render_board

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import render [as 别名]
def test_render_board():
    '''
    board: [['A', 'B'], ['B', 'A']]
    render: |'B'|'A'|
            |'A'|'B'|
            GAMEOVER? False

    '''
    player_a = Player("A")
    player_b = Player("B")
    board = Board([[player_a, player_b], [player_b, player_a]])
    assert board.render() == [['|', 'B', '|', 'A', '|'],
                              ['|', 'A', '|', 'B', '|'],
                              ["GAMEOVER? False\n"]]

    '''
    board: [['A', -], ['C', 'A']]
    render: | - | A |
            | A | C |
            GAMEOVER? True\n
    '''
    player_c = Player("C")
    board = Board([[player_a, None], [player_c, player_a]])
    board._gameover = True
    assert board.render() == [['|', '-', '|', 'A', '|'],
                              ['|', 'A', '|', 'C', '|'],
                              ["GAMEOVER? True\n"]]

    '''
    board: [[None, None, None], [None, None, None], [None, None, None]]
    render:  | - | - | - |
             | - | - | - |
             | - | - | - |
            GAMEOVER? False\n
    '''
    board = Board([[None, None, None], [None, None, None], [None, None, None]])
    assert board.render() == [['|', '-', '|', '-', '|', '-', '|'],
                              ['|', '-', '|', '-', '|', '-', '|'],
                              ['|', '-', '|', '-', '|', '-', '|'],
                              ["GAMEOVER? False\n"]]
开发者ID:gsinkin,项目名称:command_line_games,代码行数:42,代码来源:test_board.py

示例4: main

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import render [as 别名]
def main():
    pygame.init()
    screen_size = w, h = (1024, 768)

    screen = pygame.display.set_mode(screen_size)
    pygame.display.set_caption("WBRD")

    # Initialize clock
    clock = pygame.time.Clock()

    # Set up our game objects
    p1 = Player('1', Color('red'))
    p2 = Player('2', Color('blue'))
    p1.set_input_map(K_a, K_d, K_w, K_s)
    p2.set_input_map(K_j, K_l, K_i, K_k)
    # Make a new board with our two players on it
    board = Board('test_board.brd', [p1, p2])
    pixel_x = w / board.width
    pixel_y = h / board.height
    pixel_size = min(pixel_x, pixel_y)
    print("pixel size: %s" % pixel_size)

    done = False
    while not done:
        clock.tick(60) # don't run faster than 60FPS
        pygame.event.pump() # refresh the event queue
        pressed_keys = pygame.key.get_pressed()
        # Process input
        board.process_input(pressed_keys)
        # Update
        board.update()
        # Render
        screen.fill(Color('black'))
        board.render(screen, pixel_size)
        pygame.display.flip()

    pygame.quit()
开发者ID:p-buse,项目名称:wbrd,代码行数:39,代码来源:main.py

示例5: Simulator

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import render [as 别名]
class Simulator(object):
    """Simulates agents in a dynamic smartcab environment.

    Uses PyGame to display GUI, if available.
    """

    def __init__(self, env, size=None, update_delay=1.0, display=True):
        self.env = env

        self.display = display

        self.quit = False
        self.start_time = None
        self.current_time = 0.0
        self.last_updated = 0.0
        self.update_delay = update_delay  # duration between each step (in secs)

        if self.display:
            try:
                self.board = Board(grid_size=self.env.grid_size)
                self.paused = False
            except ImportError as e:
                self.display = False
                print "Simulator.__init__(): Unable to import pygame; display disabled.\n{}: {}".format(e.__class__.__name__, e)
            except Exception as e:
                self.display = False
                print "Simulator.__init__(): Error initializing GUI objects; display disabled.\n{}: {}".format(e.__class__.__name__, e)

    def run(self, n_trials=1):
        self.quit = False
        for trial in xrange(n_trials):
            # print "Simulator.run(): Trial {}".format(trial)  # [debug]
            self.env.reset()
            self.current_time = 0.0
            self.last_updated = 0.0
            self.start_time = time.time()

            while True:
                try:
                    # Update current time
                    self.current_time = time.time() - self.start_time
                    # print "Simulator.run(): current_time = {:.3f}".format(self.current_time)

                    # Update environment
                    if self.current_time - self.last_updated >= self.update_delay:

                        self.last_updated = self.current_time

                        if (self.env.step() is False):
                            self.env.reset()
                            break;

                    # Render GUI and sleep
                    if self.display:
                        self.board.render(self.env.state)

                except KeyboardInterrupt:
                    self.quit = True
                finally:
                    if self.quit or self.env.done:
                        break

            if self.quit:
                break
开发者ID:mleonardallen,项目名称:machine-learning,代码行数:66,代码来源:simulator.py

示例6: Board

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

    pygame.init()
    screen = pygame.display.set_mode(constants.SCREEN)
    media.load()

    gamemode = gamemodes.get_game_mode('standard')
    board = Board()
    trough = TileTrough()
    tileset = gamemode.get_tileset()
    tilebag = TileBag(tileset)
    
    # draw random tiles
    for row in range(0, 5):
        for i in range(0, gamemode.TILE_BANK):
            tile = tilebag.draw()
            board.set_tile(tile, i, row)
    
    # draw player tiles
    for i in range(0, gamemode.TILE_BANK):
        trough.insert(tilebag.draw())

    trough.render(screen)
    board.render(screen)

    pygame.display.flip()
    while(True):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.exit()
开发者ID:dbreen,项目名称:warwords,代码行数:32,代码来源:tiles.py


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