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


Python piece.Piece类代码示例

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


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

示例1: rule_6

 def rule_6(self, moves, game, pieces, data):
     """
     try to create bridges across other players gaps if at all possible.
     """
     metric = []
     test_board = copy.deepcopy(game.board)
     for move in moves:
         t_board = test_board
         t_piece = Piece(
             move['pieceID'],
             move['playerID'],
             rotation=move['rotation'],
             parity=move['parity'])
         position = move['position']
         before = find_bridge_instances(
             t_board,
             game.current_playerID,
             position=move['position'],
             size=t_piece.geometry.shape)
         t_board = t_piece.place_on_board(t_board, position)
         after = find_bridge_instances(
             t_board,
             game.current_playerID,
             position=move['position'],
             size=t_piece.geometry.shape)
         # using before and after, encourages starting and crossing bridges
         metric += [before + after]
     return np.array(metric)
开发者ID:b-r-oleary,项目名称:games,代码行数:28,代码来源:player.py

示例2: __init__

	def __init__(self, pos, board, player):
		Piece.__init__(self, pos, board, player)		
		
		if self.player.colour == 0:
			self.img = pygame.image.load("images/wpawn.png").convert_alpha()
		else:
			self.img = pygame.image.load("images/bpawn.png").convert_alpha()
开发者ID:Greymerk,项目名称:PyChess,代码行数:7,代码来源:pawn.py

示例3: get_piece_counts

    def get_piece_counts(self, colors=[WHITE, BLACK]):
        """Counts the pieces on the board.

        :param color:
            list of colors to check. Defualts to black and white

        :return:
            A dictionary of piece counts, keyed by lowercase piece type
            letters.
        """
        #if not color in ["w", "b", "wb", "bw"]:
        #   raise KeyError(
        #       "Expected color filter to be one of 'w', 'b', 'wb', 'bw', "
        #       "got: %s." % repr(color))

        counts = {
            PAWN:   0,
            BISHOP: 0,
            KNIGHT: 0,
            ROOK:   0,
            KING:   0,
            QUEEN:  0,
        }
        for piece in self._pieces:
            if piece and Piece.color(piece) in colors:
                counts[Piece.klass(piece)] += 1
        return counts
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:27,代码来源:position.py

示例4: getValidMoves

    def getValidMoves(self):
        ret = [
            # One space away
            (self.x, self.y+2),
            (self.x, self.y-2),
            (self.x-1, self.y-1),
            (self.x-1, self.y+1),
            (self.x+1, self.y-1),
            (self.x+1, self.y+1),

            # Two spaces away
            (self.x, self.y+4),
            (self.x, self.y-4),

            (self.x+1, self.y+3),
            (self.x+1, self.y-3),
            (self.x-1, self.y+3),
            (self.x-1, self.y-3),

            (self.x-2, self.y),
            (self.x+2, self.y),

            (self.x+2, self.y-2),
            (self.x+2, self.y+2),
            (self.x-2, self.y-2),
            (self.x-2, self.y+2)
        ]

        ret = filterValidSpots(ret, Piece.getState().getWidth(), Piece.getState().getHeight())
        ret = filterBlockedSpots(ret, Piece.getState())
        ret.append((self.x, self.y))

        return ret
开发者ID:cddude229,项目名称:Gaveldor,代码行数:33,代码来源:cavalry.py

示例5: __init__

    def __init__(self, position, move):

        resulting_position = position.copy().make_move(move)
        captured = position._pieces[move.target._x88]
        piece = position._pieces[move.source._x88]
        ocolor = Piece.opposite_color(position.fen._to_move)

        # Pawn moves.
        enpassant = False
        if Piece.klass(piece) == PAWN:
            # En-passant.
            if move.target.file != move.source.file and not captured:
                enpassant = True
                captured = Piece.from_klass_and_color(PAWN, ocolor)

        # Castling.
        # TODO: Support Chess960.
        # TODO: Validate the castling move.
        if Piece.klass(piece) == KING:
            self.is_king_side_castle = move.target.x - move.source.x == 2
            self.is_queen_side_castle = move.target.x - move.source.x == -2
        else:
            self.is_king_side_castle = self.is_queen_side_castle = False

        # Checks.
        self.is_check = resulting_position.is_check()
        self.is_checkmate = resulting_position.is_checkmate()

        self.move = move
        self.piece = piece
        self.captured = captured
        self.is_enpassant = enpassant

        self._set_text(position)
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:34,代码来源:notation.py

示例6: new_game

def new_game():
  global gs,spaces,game_begun,done,gameover, \
          turn_stage,selected_piece,hover_piece, \
          attackable_pieces,credits_showing,rules_showing, \
          paused,moveCounter,saved_piece,movedPieces
  gs = State(cols,rows)
  Piece.setState(gs)

  spaces = pygame.sprite.RenderPlain()
  #sets up board
  for i in xrange(cols):
      for j in xrange(rows/2+1):
          if i%2==0:
              s=Space(screenw,screenh,cols,rows,i*screenw/cols-i*screenw/cols/4,2*j*screenh/rows+50,i,j*2)
          else:
              if j < rows/2:
                s=Space(screenw,screenh,cols,rows,i*screenw/cols-i*screenw/cols/4,2*int((j+.5)*screenh/rows)+50,i,j*2+1)
          spaces.add(s)

  game_begun = False
  done = False
  gameover = False
  credits_showing = False
  rules_showing = False
  paused = False

  # stages: piece_select, move, dir_sel, attack
  turn_stage = 'piece_sel'  
  selected_piece = None
  saved_piece = None # for cancel button
  hover_piece = None
  attackable_pieces = []
  moveCounter = 0
  movedPieces = []
开发者ID:cddude229,项目名称:Gaveldor,代码行数:34,代码来源:game.py

示例7: final

  def final(self):
    side = 2.1*sin(pi/5.0)

    # The first piece
    first = Piece(vector(-1,-1.6*side,0),vector(0,0,1))

    # We form the first pentagon
    self.pieces = [first,
        first.clone().rotate(vector(0,1,0), 2.0/5.0*pi),
        first.clone().rotate(vector(0,1,0), 4.0/5.0*pi),
        first.clone().rotate(vector(0,1,0), 6.0/5.0*pi),
        first.clone().rotate(vector(0,1,0), 8.0/5.0*pi)]

    # Rotate the pentagon an create the bown
    defased = self.clone().rotate(vector(0,1,0),0.2*pi)

    faces = []
    for rot in defased.pieces:
      o = vector(rot.box.x * side, rot.box.y, rot.box.z* side)
      faces.append(self.clone().rotate(rot.box.axis, -16.7/5.0*pi, o))

    for face in faces:
      self.merge(face)
      face.delete()

    defased.delete()

    # the other half
    roted = self.clone().rotate(vector(1,0,0),pi).rotate(vector(0,1,0),pi/5.0)
    self.merge(roted)
    roted.delete()
开发者ID:sudoaza,项目名称:kal-toh,代码行数:31,代码来源:board.py

示例8: __init__

	def __init__(self, pos, grid, player):
		Piece.__init__(self, pos, grid, player)
		self.directions = dict(Directions.diagonals.items() + Directions.straight.items())
		
		if self.player.colour == 0:
			self.img = pygame.image.load("images/wqueen.png").convert_alpha()
		else:
			self.img = pygame.image.load("images/bqueen.png").convert_alpha()
开发者ID:Greymerk,项目名称:PyChess,代码行数:8,代码来源:queen.py

示例9: test_piece_one_block

 def test_piece_one_block(self):
     piece = Piece(fake_client, 1, 2**14, 'abc', test_dir)
     self.assertEqual(piece.num_blocks, 1)
     self.assertTrue(piece.not_all_blocks_requested()) 
     block_info = piece.get_next_block()
     self.assertEqual(block_info[0], 1)
     self.assertEqual(block_info[1], 0)
     self.assertEqual(block_info[2], 2**14)
     self.assertFalse(piece.not_all_blocks_requested())
开发者ID:wevial,项目名称:downpour,代码行数:9,代码来源:piece_test.py

示例10: __init__

	def __init__(self, pos, board, player):
		Piece.__init__(self, pos, board, player)		
		
		if self.player.colour == 0:
			self.img = pygame.image.load("images/wpawn.png").convert_alpha()
		else:
			self.img = pygame.image.load("images/bpawn.png").convert_alpha()
			
		self.img = pygame.transform.scale(self.img, (self.board.grid.cellsize, self.board.grid.cellsize))
开发者ID:claytondicks,项目名称:PyChess,代码行数:9,代码来源:pawn.py

示例11: __init__

	def __init__(self, pos, grid, player):
		Piece.__init__(self, pos, grid, player)
		self.validMoves = []
		self.directions = Directions.diagonals
				
		if self.player.colour == 0:
			self.img = pygame.image.load("images/wbishop.png").convert_alpha()
		else:
			self.img = pygame.image.load("images/bbishop.png").convert_alpha()
开发者ID:Greymerk,项目名称:PyChess,代码行数:9,代码来源:bishop.py

示例12: __init__

	def __init__(self, pos, grid, player):
		Piece.__init__(self, pos, grid, player)
		
		self.directions = Directions.knight
		
		if self.player.colour == 0:
			self.img = pygame.image.load("images/wknight.png").convert_alpha()
		else:
			self.img = pygame.image.load("images/bknight.png").convert_alpha()
开发者ID:Greymerk,项目名称:PyChess,代码行数:9,代码来源:knight.py

示例13: __init__

    def __init__(self, piece):
        """Create a ghost of piece.

        The ghost's initial position is that of piece, but you can
        update the ghost's position without affecting the piece's position.
        """
        Piece.__init__(self, piece.description)
        self.piece = piece
        self.position = None if piece.position is None else list(piece.position)
开发者ID:jneem,项目名称:clashadash,代码行数:9,代码来源:ghost_piece.py

示例14: __init__

	def __init__(self, pos, board, player):
		Piece.__init__(self, pos, board, player)
		self.validMoves = []
		
		self.directions = Directions.straight
		
		if self.player.colour == 0:
			self.img = pygame.image.load("images/wrook.png").convert_alpha()
		else:
			self.img = pygame.image.load("images/brook.png").convert_alpha()
开发者ID:Greymerk,项目名称:PyChess,代码行数:10,代码来源:rook.py

示例15: test_piece_queue_random

 def test_piece_queue_random(self):
     test_bytes = '\x00'
     test_hash = hashlib.sha1(test_bytes).digest()
     piece = Piece(fake_client, 1, 1, test_hash, test_dir)
     piece_queue = PieceQueue([piece])
     test_piece = piece_queue.get_next_random()
     self.assertEqual(test_piece.index, piece.index)
     test_piece.add_block(0, test_bytes)
     self.assertTrue(piece.check_if_finished())
     self.assertTrue(piece.check_info_hash())
开发者ID:wevial,项目名称:downpour,代码行数:10,代码来源:piece_test.py


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