• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python square.Square类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Square类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: is_insufficient_material

    def is_insufficient_material(self):
        """Checks if there is sufficient material to mate.

        Mating is impossible in:

        * A king versus king endgame.
        * A king with bishop versus king endgame.
        * A king with knight versus king endgame.
        * A king with bishop versus king with bishop endgame, where both
          bishops are on the same color. Same goes for additional
          bishops on the same color.

        Assumes that the position is valid and each player has exactly
        one king.

        :return:
            Whether there is insufficient material to mate.
        """
        piece_counts = self.get_piece_counts()

        # King versus king.
        if sum(piece_counts.values()) == 2:
            return True

        # King and knight or bishop versus king.
        elif sum(piece_counts.values()) == 3:
            if piece_counts["b"] == 1 or piece_counts["n"] == 1:
                return True

        # Each player with only king and any number of bishops, 
        # where all bishops are on the same color.
        elif sum(piece_counts.values()) == 2 + piece_counts[BISHOP]:
            white_has_bishop = self.get_piece_counts([WHITE])[BISHOP] != 0
            black_has_bishop = self.get_piece_counts([BLACK])[BISHOP] != 0
            if white_has_bishop and black_has_bishop:
                color = None
                for square in Square.get_all():
                    p = self._pieces[square._x88]
                    if p and Piece.klass(p) == BISHOP:
                        if color and color != square.is_light():
                            return False
                        color = square.is_light()
                return True
        return False
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:44,代码来源:position.py


示例17: test_create_square_with_string

 def test_create_square_with_string(self):
     sq = Square('a1')
     self.assertTrue(sq.tuple() == (0,0))
     self.assertTrue(str(sq) == 'a1')
     sq = Square('1A')
     self.assertTrue(sq.tuple() == (0,0))
     self.assertTrue(str(sq) == 'a1')
     self.assertTrue(Square('f6').tuple() == (5,5))
     self.assertTrue(str(Square('f6')) == 'f6')
     self.assertTrue(Square('10 J').tuple() == (9,9))
     self.assertTrue(str(Square('10 J')) == 'j10')
     sq = Square('z999999')
     self.assertTrue(sq.tuple() == (25,999998))
     self.assertTrue(str(sq) == 'z999999')
开发者ID:bishopw,项目名称:GameOfTheAmazons,代码行数:14,代码来源:test_square.py


示例18: hash_position

    def hash_position(self, position):
        """Computes the Zobrist hash of a position.

        :param position:
            The position to hash.

        :return:
            The hash as an integer.
        """
        key = 0

        # Hash in the board setup.
        for square in Square.get_all():
            piece = position[square]
            if piece:
                i = "pPnNbBrRqQkK".index(piece.symbol)
                key ^= self.__random_array[64 * i + 8 * square.y + square.x]

        # Hash in the castling flags.
        if position.get_castling_right("K"):
            key ^= self.__random_array[768]
        if position.get_castling_right("Q"):
            key ^= self.__random_array[768 + 1]
        if position.get_castling_right("k"):
            key ^= self.__random_array[768 + 2]
        if position.get_castling_right("q"):
            key ^= self.__random_array[768 + 3]

        # Hash in the en-passant file.
        if (position.ep_file and
               position.get_theoretical_ep_right(position.ep_file)):
            i = ord(position.ep_file) - ord("a")
            key ^= self.__random_array[772 + i]

        # Hash in the turn.
        if position.turn == "w":
            key ^= self.__random_array[780]

        return key
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:39,代码来源:zobrist_hasher.py


示例19: Square

import pygame
from vector import Vector
from square import Square
import random

pygame.init()

screen = pygame.display.set_mode((700, 500))
pygame.display.set_caption("Studsaren")

square = Square(screen, random.randint(0, screen.get_size()[0] - 50), random.randint(0, screen.get_size()[1] - 50), 50, 50)
square.velocity = 200 * Vector(random.uniform(-10, 10), random.uniform(-10, 10)).normalized()

clock = pygame.time.Clock()
done = False
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    t = clock.get_time() / 1000

    width, height = screen.get_size()
    if square.pos.x <= 0 or square.pos.x >= width - square.w:
        square.velocity = Vector(-square.velocity.x, square.velocity.y)
    if square.pos.y <= 0 or square.pos.y >= height - square.h:
        square.velocity = Vector(square.velocity.x, -square.velocity.y)
    square.update(t)

    screen.fill((0, 0, 0))
开发者ID:gkraften,项目名称:Programmering-1,代码行数:30,代码来源:studsaren.py


示例20: target

 def target(self):
     """The target square."""
     return Square.from_x88(self._target_x88)
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:3,代码来源:move.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util_client.encode函数代码示例发布时间:2022-05-27
下一篇:
Python sqltap.start函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap