本文整理汇总了Python中square.Square类的典型用法代码示例。如果您正苦于以下问题:Python Square类的具体用法?Python Square怎么用?Python Square使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Square类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decode
def test_decode(self):
a= Square.SQ_SIZE
b = a*(Square.GRID_SIZE+3)
rect = [(a,a),(b,a),(b,b),(a,b)]
m_d = SquareDetector(Square.generate(1),0)
for i in range(32):
img = Square.generate(i)
sq = Square(i,m_d)
m_d.gray_img=img
a,b = sq._decode_rect(rect)
self.assertTrue((sq.TOP_LEFT,i)==(a,b),"Wrong %d: (%d,%d)"%(i,a,b))
cv.Transpose(img, img)
cv.Flip(img)
a,b = sq._decode_rect(rect)
self.assertTrue((sq.BOT_LEFT,i)==(a,b),"Wrong %d: (%d,%d)"%(i,a,b))
cv.Transpose(img, img)
cv.Flip(img)
a,b = sq._decode_rect(rect)
self.assertTrue((sq.BOT_RIGHT,i)==(a,b),"Wrong %d: (%d,%d)"%(i,a,b))
cv.Transpose(img, img)
cv.Flip(img)
a,b = sq._decode_rect(rect)
self.assertTrue((sq.TOP_RIGHT,i)==(a,b),"Wrong %d: (%d,%d)"%(i,a,b))
m_d.flip_H=True
for i in range(32):
img = Square.generate(i)
sq = Square(i,m_d)
m_d.gray_img=img
cv.Flip(img,img,1)
_,b = sq._decode_rect(rect)
self.assertTrue(i==b,"Wrong Flip %d: (%d)"%(i,b))
示例2: from_x88
def from_x88(cls, source, target, promotion=''):
if not cls._x88_moves:
raise ValueError
# try to use the cache
if not promotion:
return cls._x88_moves[(source, target)]
return Move(Square.from_x88(source), Square.from_x88(target), promotion)
示例3: test_create_square_with_copy_constructor
def test_create_square_with_copy_constructor(self):
sq = Square('e7')
sq2 = Square(sq)
self.assertTrue(sq2.tuple() == (4, 6))
self.assertTrue(str(sq2) == 'e7')
self.assertTrue(sq2 == sq)
self.assertFalse(sq.square is sq2.square) # are they really copies?
示例4: test___eq__
def test___eq__(self):
square = Square("a1")
same = Square("a1")
other = Square("a2")
self.assertEqual(True, square.__eq__(same))
self.assertEqual(False, square.__eq__(other))
示例5: next
def next(self):
raw_entry = self.next_raw()
source_x = ((raw_entry[1] >> 6) & 077) & 0x7
source_y = (((raw_entry[1] >> 6) & 077) >> 3) & 0x7
target_x = (raw_entry[1] & 077) & 0x7
target_y = ((raw_entry[1] & 077) >> 3) & 0x7
promote = (raw_entry[1] >> 12) & 0x7
move = Move(
source=Square.from_x_and_y(source_x, source_y),
target=Square.from_x_and_y(target_x, target_y),
promotion="nbrq"[promote + 1] if promote else None)
# Replace the non standard castling moves.
if move.uci == "e1h1":
move = Move.from_uci("e1g1")
elif move.uci == "e1a1":
move = Move.from_uci("e1c1")
elif move.uci == "e8h8":
move = Move.from_uci("e8g8")
elif move.uci == "e8a8":
move = Move.from_uci("e8c8")
return {
"position_hash": raw_entry[0],
"move": move,
"weight": raw_entry[2],
"learn": raw_entry[3]
}
示例6: test_create_square_with_tuple
def test_create_square_with_tuple(self):
sq = Square((3, 3))
self.assertTrue(sq.tuple() == (3,3))
self.assertTrue(str(sq) == 'd4')
sq = Square((999999, 999999))
self.assertTrue(sq.tuple() == (999999, 999999))
self.assertRaises(ValueError, Square, (-4, 5))
self.assertRaises(ValueError, Square, (4, -5))
示例7: get_all
def get_all(cls):
'''Yield all moves combinations that do not have promotion.'''
#FIXME add in promotion
for source in Square.get_all():
for target in Square.get_all():
if source != target:
move = cls(Square.from_x88(source.x88), Square.from_x88(target.x88))
yield(move)
示例8: TestSquare
class TestSquare(unittest.TestCase):
def setUp(self):
self.square = Square(5)
def test_perimeter(self):
self.assertEqual(self.square.perimeter(), 20)
def test_area(self):
self.assertEqual(self.square.area(), 25)
示例9: main
def main():
sh = Shape()
print sh
t = Triangle(5, 10)
print t.area()
print "%s Static Method" % t.static_area(10, 20)
s = Square(20)
print s.area()
print s.perimeter()
示例10: to_move
def to_move(cls, position, san):
san = str(san)
# Castling moves.
if san == "O-O" or san == "O-O-O":
# TODO: Support Chess960, check the castling moves are valid.
rank = 1 if position.fen.turn == "w" else 8
if san == "O-O":
return Move(
source=Square.from_rank_and_file(rank, 'e'),
target=Square.from_rank_and_file(rank, 'g'))
else:
return Move(
source=Square.from_rank_and_file(rank, 'e'),
target=Square.from_rank_and_file(rank, 'c'))
# Regular moves.
else:
matches = cls.san_regex.match(san)
if not matches:
raise ValueError("Invalid SAN: %s." % repr(san))
if matches.group(1):
klass = Piece.klass(matches.group(1).lower())
else:
klass = PAWN
piece = Piece.from_klass_and_color(klass, position.fen._to_move)
target = Square(matches.group(4))
source = None
for m in position.get_legal_moves():
if position._pieces[m.source._x88] != piece or m.target != target:
continue
if matches.group(2) and matches.group(2) != m.source.file:
continue
if matches.group(3) and matches.group(3) != str(m.source.rank):
continue
# Move matches. Assert it is not ambiguous.
if source:
raise MoveError(
"Move is ambiguous: %s matches %s and %s."
% san, source, m)
source = m.source
if not source:
raise MoveError("No legal move matches %s." % san)
return Move(source, target, matches.group(5) or None)
示例11: SquareTest
class SquareTest(unittest.TestCase):
def setUp(self):
self.square = Square(side=3)
def test_it_has_a_side(self):
self.square.side |should| equal_to(3)
def test_it_changes_its_side(self):
self.square.side = 5
self.square.side |should| equal_to(5)
def test_it_calculates_its_area(self):
self.square.area() |should| equal_to(9)
示例12: __init__
def __init__(self):
self.maze_squares = get_maze_squares()
self.maze_map = make_maze_map(self.maze_squares)
print self.maze_map
self.player = Square(start = [50,50], color=BLUE)
self.enemies = []
self.lasers = []
for i in range(10):
x = random.randint(0, WIDTH)
y = random.randint(0, HEIGHT)
enemy = Square(start = (x,y), color=RED)
self.enemies.append(enemy)
示例13: Play
class Play(Scene):
def __init__(self):
Scene.__init__(self)
self.BACKGROUND_COLOR = (0, 0, 0, 255)
self.slider1 = Slider(
(50, utils.SCREEN_H // 2 - Slider.HEIGHT),
(pygame.K_w, pygame.K_s),
)
self.slider2 = Slider(
(utils.SCREEN_W - Slider.WIDTH - 50, utils.SCREEN_H // 2 - Slider.HEIGHT),
(pygame.K_UP, pygame.K_DOWN),
)
self.square = Square(
(utils.SCREEN_W // 2 - Square.WIDTH // 2, utils.SCREEN_H // 2 - Square.HEIGHT // 2),
)
def go_to_menu(self):
from menu import Menu
utils.set_scene( Menu() )
def on_escape(self):
self.go_to_menu()
def update(self):
keys = pygame.key.get_pressed()
self.slider1.update(keys)
self.slider2.update(keys)
self.square.update( (self.slider1.fPos, self.slider2.fPos) )
def blit(self):
self.slider1.blit(utils.screen)
self.slider2.blit(utils.screen)
self.square.blit(utils.screen)
示例14: __init__
def __init__(self):
Scene.__init__(self)
self.BACKGROUND_COLOR = (0, 0, 0, 255)
self.slider1 = Slider(
(50, utils.SCREEN_H // 2 - Slider.HEIGHT),
(pygame.K_w, pygame.K_s),
)
self.slider2 = Slider(
(utils.SCREEN_W - Slider.WIDTH - 50, utils.SCREEN_H // 2 - Slider.HEIGHT),
(pygame.K_UP, pygame.K_DOWN),
)
self.square = Square(
(utils.SCREEN_W // 2 - Square.WIDTH // 2, utils.SCREEN_H // 2 - Square.HEIGHT // 2),
)
示例15: get_king
def get_king(self, color):
"""Gets the square of the king.
:param color:
`"w"` for the white players king. `"b"` for the black
players king.
:return:
The first square with a matching king or `None` if that
player has no king.
"""
#if not color in ["w", "b"]:
# raise KeyError("Invalid color: %s." % repr(color))
for square, piece in [(s, self._pieces[s._x88]) for s in Square.get_all() if self._pieces[s._x88]]:
if Piece.is_klass_and_color(piece, KING, color):
return square