本文整理汇总了Python中Move.Move类的典型用法代码示例。如果您正苦于以下问题:Python Move类的具体用法?Python Move怎么用?Python Move使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Move类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_negamax
def test_negamax(self):
board = Board("""
1 W
..k..
.....
.....
.....
..Q..
...K.
""")
player = NegamaxPlayer()
best_value, best_move = player.negamax(board, 1)
self.assertEqual(Move.from_string("c2-c6"), best_move)
random.seed(0)
board = Board("""
1 W
kp...
.p...
.....
.....
.Q...
...K.
""")
player = NegamaxPlayer()
best_value, best_move = player.negamax(board, 3)
self.assertEqual(Move.from_string("b2-b4"), best_move)
示例2: test_scan_no_capture
def test_scan_no_capture(self):
b = Board("""
1 W
.....
.....
..Qp.
.....
.....
.....
""")
startpos = (3,4)
# not capturing right
movelist = []
b.scan(movelist, startpos, 1, 0, no_capture=True)
expected = []
self.assertEqual(expected, movelist)
# to the top
movelist = []
b.scan(movelist, startpos, 0, 1, no_capture=True)
expected = []
expected.append(Move.from_string("c4-c5"))
expected.append(Move.from_string("c4-c6"))
self.assertEqual(expected, movelist)
示例3: test_legal_moves_combined
def test_legal_moves_combined(self):
b = Board("""
1 W
..k..
q..p.
.....
.P...
....r
N...K
""")
# get legal moves for all white pieces
legal_moves = b.legal_moves()
expected = []
# knight
expected.append(Move.from_string("a1-c2"))
# king
expected.append(Move.from_string("e1-e2"))
expected.append(Move.from_string("e1-d2"))
expected.append(Move.from_string("e1-d1"))
# pawn
expected.append(Move.from_string("b3-b4"))
self.assertEqual(len(expected), len(legal_moves))
for move in expected:
self.assertIn(move, legal_moves)
示例4: test_undo_last_move
def test_undo_last_move(self):
b = Board("""
1 W
...k.
..P..
.....
.....
.....
.....
""")
b2 = Board("""
1 W
...k.
..P..
.....
.....
.....
.....
""")
b.move(Move.from_string("c5-c6"))
b.undo_last_move()
self.assertEqual(b, b2)
b.move(Move.from_string("c5-d6"))
b.undo_last_move()
self.assertEqual(b, b2)
示例5: __init__
class Remove:
trashPath = 'Operate/TrashBox'
#
# [String] targetEntries : 作成するディレクトリ名
#
def __init__(self, targetEntries):
self.targetEntries = targetEntries
self.move = None
#
# 実行
#
def execute(self):
self.move = None
pairPaths = []
for targetEntry in self.targetEntries:
entryName = targetEntry.rsplit(os.sep, 1)[1]
inTrashPath = os.path.join(Remove.trashPath, entryName)
pairPaths.append(PairPath(targetEntry, inTrashPath))
self.move = Move(pairPaths)
self.move.execute()
#
# 実行取り消し
#
def unexecute(self):
self.move.unexecute()
示例6: test_scan_one_step
def test_scan_one_step(self):
b = Board("""
1 W
.....
.....
.....
.Kq..
.....
.....
""")
startpos = (2,3)
# capturing right
movelist = []
b.scan(movelist, startpos, 1, 0, one_step=True)
expected = []
expected.append(Move.from_string("b3-c3"))
self.assertEqual(expected, movelist)
# to the top
movelist = []
b.scan(movelist, startpos, 0, 1, one_step=True)
expected = []
expected.append(Move.from_string("b3-b4"))
self.assertEqual(expected, movelist)
示例7: explore
def explore(motor, buzzer):
'''
Function will initialize and execute a new "move"
Args:
motor(motor_obj): used to control robot movement
buzzer(buzzer_obj): signals start of exploration
'''
# Test output
print "Exploring (moving to a new location) ..."
# Beep to indicate begining of explore step
buzzer.play(5)
# Initialize new move object
move = Move()
# Vector of movement used
move.get_move_vector()
# Break down movement vector into motion primitives that robot can execute
move.get_motion_plan()
# Debug print move fields
print(str(move))
# Execute motion from given move primitives
for (direction, amount) in move.primitives:
print "Moving " + str(direction) + " " + str(amount)
motor.move_bot(direction, distance=amount)
示例8: Move
def Move(self, sReactor, sReactPosition):
"""Performs a move unit operation"""
pParams = {"ReactorID":sReactor,
"reactPosition":sReactPosition}
pMove = Move(self.__pSystemModel, pParams, username = "CLI", database = self.__pDatabase)
pMove.setDaemon(True)
pMove.start()
return pMove
示例9: test_equal_operator
def test_equal_operator(self):
b = Move.from_string("a1-a2")
c = Move.from_string("a1-a2")
self.assertEqual(b, c)
b = Move.from_string("e1-a2")
c = Move.from_string("a1-a4")
self.assertNotEqual(b, c)
示例10: getValidMoves
def getValidMoves(self, player):
validMoves = []
for rowNumber in range(8):
for columnNumber in range(8):
move = Move(player.shape, rowNumber, columnNumber, self)
if move.isMoveValid():
validMoves.append(move)
return validMoves
示例11: test_move_game_result
def test_move_game_result(self):
# white win
b = Board("""
1 W
.k...
P....
.....
.....
.....
.....
""")
result = b.move(Move.from_string("a5-b6"))
self.assertEqual(result, 'W')
# black win
b = Board("""
1 B
..r..
.....
.....
.....
..K..
.....
""")
result = b.move(Move.from_string("c6-c2"))
self.assertEqual(result, 'B')
# undecided
b = Board("""
1 W
.....
P....
.....
.....
.....
.....
""")
result = b.move(Move.from_string("a5-a6"))
self.assertEqual(result, '?')
# draw
b = Board("""
40 B
.....
p....
.....
.....
.....
.....
""")
result = b.move(Move.from_string("a5-a4"))
self.assertEqual(result, '=')
示例12: test_legal_moves_bishop
def test_legal_moves_bishop(self):
b = Board("""
1 W
.....
.....
...p.
.p...
.B...
.....
""")
# get legal moves for white bishop 'B'
legal_moves = b.legal_moves()
expected = []
expected.append(Move.from_string("b2-a1"))
expected.append(Move.from_string("b2-c3"))
expected.append(Move.from_string("b2-d4"))
expected.append(Move.from_string("b2-a3"))
expected.append(Move.from_string("b2-c1"))
expected.append(Move.from_string("b2-b1"))
expected.append(Move.from_string("b2-a2"))
expected.append(Move.from_string("b2-c2"))
self.assertEqual(len(expected), len(legal_moves))
for move in expected:
self.assertIn(move, legal_moves)
示例13: test_legal_moves_rook
def test_legal_moves_rook(self):
b = Board("""
1 W
.....
.....
..Rr.
.....
.....
.....
""")
# get legal moves for white rook 'R'
legal_moves = b.legal_moves()
expected = []
expected.append(Move.from_string("c4-d4"))
expected.append(Move.from_string("c4-c3"))
expected.append(Move.from_string("c4-c2"))
expected.append(Move.from_string("c4-c1"))
expected.append(Move.from_string("c4-b4"))
expected.append(Move.from_string("c4-a4"))
expected.append(Move.from_string("c4-c5"))
expected.append(Move.from_string("c4-c6"))
self.assertEqual(len(expected), len(legal_moves))
for move in expected:
self.assertIn(move, legal_moves)
示例14: test_try_move_and_score
def test_try_move_and_score(self):
b = Board("""
1 W
..k..
q..p.
.....
.P...
....r
N...K
""")
self.assertEqual(b.score_after(Move.from_string("b3-b4")), 1150) # score for black!
# moving pawn, no change in score, Black has advantage
b.move(Move.from_string("b3-b4"))
self.assertEqual(b.score_after(Move.from_string("e2-e1")), -100000) # score for white!
示例15: test_scan_only_capture
def test_scan_only_capture(self):
b = Board("""
1 W
.....
...p.
..P..
..K..
.....
.....
""")
startpos = (3,4)
# to the top
movelist = []
b.scan(movelist, startpos, 0, 1, only_capture=True)
expected = []
self.assertEqual(expected, movelist)
# capturing enemy
movelist = []
b.scan(movelist, startpos, 1, 1, only_capture=True)
expected = []
expected.append(Move.from_string("c4-d5"))
self.assertEqual(expected, movelist)
# not capturing own
movelist = []
b.scan(movelist, startpos, 0, -1, only_capture=True)
expected = []
self.assertEqual(expected, movelist)