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


Python Board类代码示例

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


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

示例1: parseSgfHeader

 def parseSgfHeader(header, filename=None):
     """ Returns a board initialized based on the header information (e.g 
     size, handicap stones). 
     
     filename gets passed through to the Board object that gets returned."""
     
     size_match = re.search('SZ\\[(.+?)\\]', header)
     if size_match:
         try:
             board_size = size_match.group(1)
             board_size = int(board_size)
         except ValueError:
             raise SgfParsingError("Non-integer board size \"" + str(board_size) + \
                 "\" found while parsing SGF file.")
     else:
         board_size = 19
     board = Board(board_size, filename)
     
     starting_black_stones = re.search('AB((?:\\[.+?\\])*)', header)
     if starting_black_stones:
         tokens = starting_black_stones.group(1)
         for i in range(0, len(tokens), 4):
             board.applyIntersections([SgfParser.parseSgfToken('B'+tokens[i:i+4], board_size)])
     starting_white_stones = re.search('AW((?:\\[.+?\\])*)', header)
     if starting_white_stones:
         tokens = starting_white_stones.group(1)
         for i in range(0, len(tokens), 4):
             board.applyIntersections([SgfParser.parseSgfToken('W'+tokens[i:i+4], board_size)])
     
     return board
开发者ID:DuskEagle,项目名称:PyGo,代码行数:30,代码来源:SgfParser.py

示例2: main

def main():
    
    print "Welcome to King Saul Checkers! [5x5, two Kings each]"
    
    # test default CTOR
    B = Board()
    print B
    
    # test setting up an initial board
    B.initializeBoard()
    print B
    
    # test iterating over all the pieces (kings) on the board
    # whichKing is hash: key: name, value: King object
    for nextKing in B.whichKing.keys():
	print B.whichKing[nextKing]
	
	
    
    # test making (potential) moves of each King on board B
    nextMoves = []
    for moveThisKing in B.whichKing.keys():
	newBoards = B.getNextMoves( B.whichKing[moveThisKing] )
	
	print "----------------------------------------------"
	print "Potential Moves for King: ", moveThisKing
	for nextBoard in newBoards:
	    print "\tFROM", B.whichKing[ moveThisKing ].chinookNum, "TO", nextBoard.whichKing[ moveThisKing ].chinookNum
开发者ID:bawjensen,项目名称:COMP-255-AI,代码行数:28,代码来源:KingSaul_main.py

示例3: evaluateBoard

    def evaluateBoard(self, board, color, combined, start_row = 0, start_col = 0, end_row = 7, end_col = 7):
        
        value = 0
        

        for row in range(start_row, end_row + 1):
            for col in range (start_col, end_col + 1):
                piece = board[row][col]

                # If it's my piece, then add to my total.
                if color == Piece.pieceColor(piece):
                    value = value + self.__getMaterialValue(board, color, piece)
                    value = value + self.__getPositionValue(color, piece, row, col)
                
                    if Board.isFrozen(board, piece, row, col):
                        value = value + self.__getFrozenValue(color, piece, row, col)  
                   
                # Else, it's the opponent's piece, the value goes down.
                elif combined == True:
                    value = value - self.__getMaterialValue(board, color, piece)
                    value = value - self.__getPositionValue(color, piece, row, col)

                    if Board.isFrozen(board, piece, row, col):
                        value = value - self.__getFrozenValue(color, piece, row, col)
        
        return value
开发者ID:boomft,项目名称:arimaa,代码行数:26,代码来源:Evaluation.py

示例4: _approach

    def _approach (self, enemy, faceTorsoEnemy):
        i = 0
        x = 0
        while True:
            x = Board.adjacent_cells(enemy, (faceTorsoEnemy+i)%6, self.board)
            i += 1
            if (not x in self.mechs.enemys_cell()) and x != 0: break
        pf = pathfinder.PathFinder(self.board.successors, self.board.move_cost, self.board.heuristic_to_goal)
        A = Pos(self.playerCell, self.playerFace)
        B = Pos(x, Board.facing_side(x, enemy))
        if A == B: return ([], 3)

        path, can, cost = pf.compute_path_until_PM (A, B, 0, self.player.walk)

        if can == False and self.player.run != 0:
            path2, can2, cost2 = pf.compute_path_until_PM(A, B, 1, self.player.run)

            if can2 == True:
                return (path2, 1)
        if can == False and self.player.jump != 0:
            print "ESTO K ES!: walk then jump"
            print self.player.walk
            print self.player.jump
            path3, can3, cost3 = pf.compute_path_until_PM(A, B, 2, self.player.jump)
            if (can3 == True) or  (self.player.jump >= self.player.walk):
                return (path3,2)
        return (path, 0)
开发者ID:kostspielig,项目名称:smart-player,代码行数:27,代码来源:Movement.py

示例5: buttonStandardBoard

def buttonStandardBoard():
    GameState.s.setGameState(2)
    for row in range(8):
        for column in range(8):
            if (0<= row <= 2) and (((row+column) %2) == 1):
                Board.insertPiece(row,column,"B")
            if (5<=row<=8) and (((row+column) %2) == 1):
                Board.insertPiece(row,column,"W")
开发者ID:harwooja,项目名称:Checkers,代码行数:8,代码来源:Menu.py

示例6: set_new_game_id

class Game:
    def set_new_game_id(self):        
        previous_ids = []
        for filename in os.listdir("games"):
            previous_ids.append(int(filename))
        if len(previous_ids) == 0:
            self.game_id = 1
        else:
            self.game_id = max(previous_ids) + 1

    def is_game_in_progress(gid):
        for filename in os.listdir("games"):
            if str(gid) == filename:
                return True
        return False

    def start_new_game(self,player):
        self.set_new_game_id()

        # Create the board
        self.board = Board(400,400,player,Player("Player 2",""))
        self.board.refill(player)
        self.board.display_tiles()

        # Set up the rest of the current game state
        self.current_player = player # Default to the first person
        self.prev_result = None        

    def run(self):
        self.players = []
        # Read the players from the database
        self.db = Database("db.txt")
        self.db.read()
        # From our tic-tac-toe game, we need to have the user login
        start_screen = StartScreen()
        while True:
            result = start_screen.login(self.db)
            if result == "new":
                self.start_new_game(start_screen.getPlayer())
                break
            elif result == "quit": # Quit was hit, so end the game
                return
            else: # Must be a game id
                self.load(result,start_screen.getPlayer())
        
        while True:
            self.result = self.board.take_turn(self.current_player)
            if self.result == "pass" and self.prev_result == "pass":
                break # Show result
            if self.result == "quit":
                return
            if self.result == "submit":
                self.current_player.refill()
                
            self.prev_result = self.result

    def load(self,game_id,player):
        return
开发者ID:itsallvoodoo,项目名称:csci-school,代码行数:58,代码来源:Game.py

示例7: main

def main():
    
    print "\nWelcome to King Saul Checkers! [6x6, two Kings each]\n"
    
    
    B = Board()            # get new board  
    B.initializeBoard()    # set up starting board
    
    playGame(B)   
开发者ID:cpudvar,项目名称:Past-Work-Samples,代码行数:9,代码来源:KingSaul_main.py

示例8: main

def main():
	
	numPlayers = -1
	#test Ben
	#sublime text can't work with stdin, so hardcoded it as a 2 player game while on sublime
	while(True):
		try:
			response = raw_input('How many players do you want? ')
			numPlayers = int(response)
		except ValueError:
			print "Please enter a number"
			continue
		if (numPlayers >= 0 and numPlayers <= 4):
			break
		else:
			print "Please enter a number betweeen 0 and 4"
	players = []
	for i in range (0, numPlayers):
		players.append(Player.player(i))
	AiNum = -1
	try:
            response = raw_input("Add an Ai player?")
            if response == "Yes" or response == "yes" or response == "y":
                AiNum = len(players)			
                players.append(Ai.ai(AiNum))
                numPlayers +=1
	except EOFError:
		print " Not building, on sublime"
        if AiNum != -1 and numPlayers == 1:
	   numRuns = input('How many runs? ')
	else:
	   numRuns = 1
	if numRuns > 1:
	        stats = []
           	for x in xrange(numRuns):
           	    numPlayers = 1
           	    players = []
           	    AiNum = len(players)			
                    players.append(Ai.ai(AiNum))
                    board = Board.board()
               	    devCardsDeck = Devcards.devcards()
                    #board.createBatchCSV(players)
                    #board.batchUpdate()
                    #print board.printBoard()
                    firstPlacement(numPlayers, players, board, AiNum)
                    stats.append(playMainGame(numPlayers, players, board, devCardsDeck, AiNum))
                print stats
                print "average turns (excluding robber) = ", sum(stats)/float(numRuns)
        else:
            board = Board.board()
            devCardsDeck = Devcards.devcards()
            board.createBatchCSV(players)
            board.batchUpdate()
            print board.printBoard()
            firstPlacement(numPlayers, players, board, AiNum)
            playMainGame(numPlayers, players, board, devCardsDeck, AiNum)
开发者ID:ulmerb,项目名称:CatanBackend,代码行数:56,代码来源:Controller.py

示例9: main

def main():
    domain = "http://localhost:8080"  # domain al que nos vamos a conectar
    pid = int(input("Ingrese el id del jugador: "))
    name = input("Ingrese el nombre del jugador: ")
    taquin.create_player(domain, pid, name)

    option = int(input("1) Single player, 2) Resolver un reto (Multiplayer), 3) Retar a un jugador, -1) salir\n"))
    while option != -1:
        if option == 1:
            size = int(input("Ingrese el tamaño N del tablero: "))
            matrix = taquin.generate_matrix(size)  # generamos una matriz de size * size
            board = Board(matrix, size, size-1, size-1)

            # -------------- PARA PROBAR 2x2 ------------
            #matrix = [[3, 1],
            #         [2, None]]

            #board = Board(matrix, 2, 1, 1)
            # -------------------------------------------

            # -------------- PARA PROBAR 3x3 ------------
            #matrix = [[1, 3, 4],
            #          [2, 5, 6],
            #          [7, 8, None]]

            #board = Board(matrix, 3, 2, 2)
            # -------------------------------------------
            while not board.is_solvable():
                matrix = taquin.generate_matrix(size)  # generamos una matriz de size * size
                board = Board(matrix, size, size - 1, size - 1)

            taquin.generateBoard(domain, matrix, size-1, size-1)   # mandamos la matriz para que se display en la pagina

            if board.is_solvable():
                print("El tablero SI se puede resolver")
                solver = Solver(board)
                movements = solver.solve()
                print("Movimientos: ", movements)
                if len(movements) != 0:
                    send_movements(domain, pid, movements)

            else:
                print("El tablero NO se puede resolver")

        elif option == 2:  # todavia no sirve
            taquin.get_challenge(domain, pid)
        elif option == 3:
            opponent = input("Ingrese el id del oponente: ")
            opponent = int(opponent)
            size = int(input("Ingrese el tamaño N del tablero: "))
            matrix_challenge = taquin.generate_matrix(size)
            taquin.challenge(domain, matrix_challenge, size-1, size-1, opponent)
            print("Reto enviado: ")
            print(matrix_challenge)

        option = int(input("1) Single player, 2) Resolver un reto (Multiplayer), 3) Retar a un jugador, -1) salir\n"))
开发者ID:torresjeff,项目名称:TaquinSolver-Py,代码行数:56,代码来源:main.py

示例10: test_if_game_has_finnished_by_user_winning

    def test_if_game_has_finnished_by_user_winning(self):
        b = Board(3)
        p = {"andy": "X", "nick": "O"}
        g = Game(b, p)

        for i in range(3):
            for j in range(3):
                b.fill_position(i, j, "X")

        self.assertTrue(g.is_game_finnished(), "game is not finnished")
开发者ID:andrebrito,项目名称:py-studies,代码行数:10,代码来源:GameTest.py

示例11: test_if_game_has_finnished_by_board_completion

    def test_if_game_has_finnished_by_board_completion(self):
        b = Board(3)
        p = {"andy": "X", "nick": "O"}
        g = Game(b, p)

        for i in range(3):
            for j in range(3):
                b.fill_position(i, j, choice(ascii_uppercase))

        self.assertTrue(g.is_game_finnished(), "game is not finnished")
开发者ID:andrebrito,项目名称:py-studies,代码行数:10,代码来源:GameTest.py

示例12: setup

def setup():
    global board,players

    win = GraphWin("Search", widthSize, heightSize)
    win.setBackground("black")


    player1 = Player(2, p1Color, p1Pos)
    player2 = Player(3, p2Color, p2Pos)

    players = [player1, player2]

    board = Board(players)
    board.drawGrid(win, "white")

    board.drawPlayer(win, *p1Pos, player1)
    board.drawPlayer(win, *p2Pos, player2)

    while True:
        pos = win.getMouse()

        if win.checkKey():
            break

        pos = (pos.x//rectSize, pos.y//rectSize)
        board.createObstacle(win, *pos)

    board.drawGrid(win, "black")

    executePlayer(win, board, players[0])

    win.getMouse()
开发者ID:AlejandroSalgadoG,项目名称:MachineLearning,代码行数:32,代码来源:Search.py

示例13: __updateBoard

    def __updateBoard(self, steps):
 
        # Needs to be called before using updateHashkey so that hashkey can reinitialize itself
        # Only needs to be reinitialized when not currently in a push
        if not self.__nextMoveTypeStr(steps) == Step.Step.MUST_PUSH:
           self.hash.initTempHashKey()
        
        
        # The steps with any traps done.
        final_steps = ""
        
        for step in steps.split():
            final_steps = final_steps + " " + step
            step = Step.Step(step)

            # The piece we are trying to move
            piece = self.board[step.start_row][step.start_col]

            # Update the hash for this position.
            self.hash.updateHashKey(step.start_row, step.start_col, piece, " ")

            # Delete the pieces starting position
            if (step.start_row == 2 and step.start_col == 2) or \
               (step.start_row == 2 and step.start_col == 5) or \
               (step.start_row == 5 and step.start_col == 2) or \
               (step.start_row == 5 and step.start_col == 5):
                self.board[step.start_row][step.start_col] = "X"
            else:   
                self.board[step.start_row][step.start_col] = " "
            
            # Put this piece in its new place
            self.board[step.end_row][step.end_col] = step.piece 
            
            trapped_piece = ""
            # Is the piece in a trap square?
            if not Board.isSafe(self.board, 2, 2):
               trapped_piece = self.board[2][2] + "c6x"
               self.board[2][2] = "X"
            elif not Board.isSafe(self.board, 2, 5):
               trapped_piece = self.board[2][5] + "f6x"
               self.board[2][5] = "X"
            elif not Board.isSafe(self.board, 5, 2):
               trapped_piece = self.board[5][2] + "c3x"
               self.board[5][2] = "X"
            elif not Board.isSafe(self.board, 5, 5):
               trapped_piece = self.board[5][5] + "f3x"
               self.board[5][5] = "X"
           
            piece = self.board[step.end_row][step.end_col] 
            self.hash.updateHashKey(step.end_row, step.end_col, " ", piece)    
            
            if trapped_piece != "":
                final_steps = final_steps + " " + trapped_piece
         
        return final_steps
开发者ID:boomft,项目名称:arimaa,代码行数:55,代码来源:MoveGenerator.py

示例14: test_if_can_mark_in_out_of_bound_position

    def test_if_can_mark_in_out_of_bound_position(self):
        b = Board(3)
        p = {"andy": "X", "nick": "O"}
        g = Game(b, p)

        for i in range(3):
            for j in range(3):
                b.fill_position(i, j, "X")

        self.assertFalse(b.can_mark(3, 3), "can mark in 3, 3")
        self.assertFalse(b.can_mark(4, 4), "can mark in 4, 4")
        self.assertFalse(b.can_mark(-1, -1), "can mark in -1, -1")
开发者ID:andrebrito,项目名称:py-studies,代码行数:12,代码来源:GameTest.py

示例15: test_feature_planes

def test_feature_planes():
    board = Board(5)
    moves = [(0,0), (1,1), (2,2), (3,3), (4,4)]
    play_color = Color.Black
    for x,y in moves:
        board.show()
        feature_planes = make_feature_planes(board, play_color)
        move_arr = make_move_arr(x, y)
        show_feature_planes_and_move(feature_planes, move_arr)
        print
        board.play_stone(x, y, play_color)
        play_color = flipped_color[play_color]
开发者ID:TheDuck314,项目名称:go-NN,代码行数:12,代码来源:MakeMoveData.py


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