本文整理汇总了Python中game.game_module.BoardState.make_initial_setup方法的典型用法代码示例。如果您正苦于以下问题:Python BoardState.make_initial_setup方法的具体用法?Python BoardState.make_initial_setup怎么用?Python BoardState.make_initial_setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game.game_module.BoardState
的用法示例。
在下文中一共展示了BoardState.make_initial_setup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_piece_path
# 需要导入模块: from game.game_module import BoardState [as 别名]
# 或者: from game.game_module.BoardState import make_initial_setup [as 别名]
def test_piece_path(self):
board = BoardState()
board.make_initial_setup()
path1 = board[('a', 2)].path
board = board.next(MoveParser().parse("a4", Color.WHITE))
path2 = board[('a', 4)].path
self.assertEqual([Square('a',2)], path1)
self.assertEqual([Square('a',2), Square('a', 4)], path2)
示例2: test_serialize_initial_setup
# 需要导入模块: from game.game_module import BoardState [as 别名]
# 或者: from game.game_module.BoardState import make_initial_setup [as 别名]
def test_serialize_initial_setup(self):
board = BoardState()
board.make_initial_setup()
blob = board.serialize()
white_rows_blob = ((((((((((((((0*16+1)*16+2)*16+3)*16+4)*16+2)*16+1)*16+0)*16+5)*16+5)*16+5)*16+5)*16+5)*16+5)*16+5)*16+5
black_rows_blob = (((((((((((((((5+8)*16+5+8)*16+5+8)*16+5+8)*16+5+8)*16+5+8)*16+5+8)*16+5+8)*16+0+8)*16+1+8)*16+2+8)*16+3+8)*16+4+8)*16+2+8)*16+1+8)*16+0+8
two_empty_rows_blob = ((((((((((((((14*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14)*16+14
self.assertEqual([white_rows_blob, two_empty_rows_blob, two_empty_rows_blob, black_rows_blob], blob)
示例3: _show_first_move
# 需要导入模块: from game.game_module import BoardState [as 别名]
# 或者: from game.game_module.BoardState import make_initial_setup [as 别名]
def _show_first_move(self):
if not self.current_game is None:
try:
self.current_move_num = 0
self.move_list.setCurrentRow(self.current_move_num)
self.board.redraw(self.current_game.board_states[self.current_move_num])
except Exception as err:
print err
else:
board_state = BoardState()
board_state.make_initial_setup()
self.board.redraw(board_state)
示例4: BoardScene
# 需要导入模块: from game.game_module import BoardState [as 别名]
# 或者: from game.game_module.BoardState import make_initial_setup [as 别名]
class BoardScene(QtGui.QGraphicsScene):
def __init__(self, board_state = None):
if board_state is None:
self.board_state = BoardState()
self.board_state.make_initial_setup()
else:
self.board_state = board_state
super(BoardScene, self).__init__()
self.piece_images = []
self.painted_squares = []
self.path = []
self.acceptDrag = False
self.drag_num = 0
self.initUI()
def dragEnterEvent(self, event):
x = event.scenePos().x()
y = event.scenePos().y()
self.dragging_piece = self.itemAt(event.scenePos())
file = int(math.floor(x/40))
rank = int(9 - math.floor(y/40))
self.drag_from = Square(file, rank)
# event.acceptProposedAction()
def dragMoveEvent(self, event):
event.acceptProposedAction()
def dropEvent(self, event):
if self.dragging_piece.__class__.__name__ != 'PieceItem':
return
x = event.scenePos().x()
y = event.scenePos().y()
file = int(math.floor(x/40))
rank = int(9 - math.floor(y/40))
try:
try:
self.drag_to = Square(file, rank)
except InvalidSquareCoordException:
self.removeItem(self.dragging_piece)
self.board_state.pieces.remove(self.board_state[self.drag_from])
return
if self.board_state[self.drag_to] is None:
if self.drag_num == 0:
self.board_state = copy.deepcopy(self.board_state)
self.drag_num += 1
self.board_state[self.drag_from].square = self.drag_to
self.dragging_piece.setOffset(40*file, 400 - 40*rank - 40)
except Exception as err:
print err
def _get_image_filename(self, piece):
if piece is None:
return
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..%simg' % os.sep)
filename += os.sep
if piece.type == PieceType.BISHOP:
filename += 'bishop'
if piece.type == PieceType.KING:
filename += 'king'
if piece.type == PieceType.KNIGHT:
filename += 'knight'
if piece.type == PieceType.PAWN:
filename += 'pawn'
if piece.type == PieceType.QUEEN:
filename += 'queen'
if piece.type == PieceType.ROOK:
filename += 'rook'
filename+= '_'
if piece.color == Color.WHITE:
filename += 'white'
else:
filename += 'black'
filename += '.png'
return filename
def initUI(self):
self.setSceneRect(0,0, 400, 400)
font=QtGui.QFont()
font.setPointSize(15)
black_brush = QtGui.QBrush(QtGui.QColor(50, 125, 215), QtCore.Qt.SolidPattern)
white_brush = QtGui.QBrush(QtGui.QColor(255, 240, 225), QtCore.Qt.SolidPattern)
squares = list()
for i in range(1,9):
row = list()
squares.append(row)
for i in range(1,9):
file=QtGui.QGraphicsTextItem(Square.digit_to_file(i))
file.setPos(40*i + 13 , 370)
file.setFont(font)
self.addItem(file)
file=QtGui.QGraphicsTextItem(Square.digit_to_file(i))
#.........这里部分代码省略.........