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


Python square.Square类代码示例

本文整理汇总了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))
开发者ID:BrainTech,项目名称:eyetracker,代码行数:31,代码来源:test_square.py

示例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)
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:7,代码来源:move.py

示例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?
开发者ID:bishopw,项目名称:GameOfTheAmazons,代码行数:7,代码来源:test_square.py

示例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))
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:7,代码来源:test_square.py

示例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]
        }
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:32,代码来源:polyglot_opening_book.py

示例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))
开发者ID:bishopw,项目名称:GameOfTheAmazons,代码行数:8,代码来源:test_square.py

示例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)
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:9,代码来源:move.py

示例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)
开发者ID:marco-buttu,项目名称:pybook2nd,代码行数:10,代码来源:tests_ch01.py

示例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()
开发者ID:rsg17,项目名称:Python,代码行数:10,代码来源:main.py

示例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)
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:50,代码来源:notation.py

示例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)
开发者ID:rodrigomanhaes,项目名称:forkinrio,代码行数:14,代码来源:square_test.py

示例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)
开发者ID:nimbusgo,项目名称:squares,代码行数:12,代码来源:game_state.py

示例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)
开发者ID:gragas,项目名称:buffalo,代码行数:36,代码来源:play.py

示例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),
        )
开发者ID:gragas,项目名称:buffalo,代码行数:16,代码来源:play.py

示例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
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:17,代码来源:position.py


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