コード例 #1
0
    def positiveMove(self, currentBoard):
        # setUp:
        self.pMove.clear()
        # Your code:
        mL = []
        if (self.white):
            m1 = self.point + Point(0, 1)
            mL.append(m1)

            if (self.point.y > 4):
                for i in range(-1, 2, 2):
                    mL.append(self.point + Point(i, 0))
            for m in mL:
                if ((not self.isTeammatePoint(m, currentBoard))
                        and m.checkOnBoard()):
                    # add tP in Positive Move:
                    self.pMove.append(m)
                # _____________________________________
        elif (not self.white):
            m1 = self.point + Point(0, -1)
            mL.append(m1)

            if (self.point.y < 5):
                for i in range(-1, 2, 2):
                    mL.append(self.point + Point(i, 0))
            for m in mL:
                if ((not self.isTeammatePoint(m, currentBoard))
                        and m.checkOnBoard()):
                    # add tP in Positive Move:
                    self.pMove.append(m)
コード例 #2
0
def test_point_setters():
    point = Point()
    point.x = 42
    point.y = 42

    assert point.x == 42.0
    assert point.y == 42.0
コード例 #3
0
def test_point_distance():
    a = Point()
    b = Point(10, 10)

    distance = a.distance(b)

    assert distance == 14.142135623730951
コード例 #4
0
    def test_point_distance(self):
        p1 = Point(2, 5)
        p2 = Point(2, 5)
        p3 = Point(10, 9)

        self.assertEqual(p1.distance(p2), 0.0)
        self.assertEqual(p1.distance(p3), round(8.94427190999916, 2))
コード例 #5
0
def test_point_constructor():
    point = Point()
    assert point.x == 0.0
    assert point.y == 0.0

    point = Point(1, 3)
    assert point.x == 1.0
    assert point.y == 3.0
コード例 #6
0
    def test_point_setters(self):
        point = Point()
        self._test_point(point, 0, 0)

        point.x = 42
        point.y = 20

        self._test_point(point, 42, 20)
コード例 #7
0
ファイル: test_point.py プロジェクト: Dilor/UnitPython
def test_point_setters_exception(value, exception_type):
    point = Point()

    with pytest.raises(exception_type):
        point.x = value

    with pytest.raises(exception_type):
        point.y = value
コード例 #8
0
def createTot(board):
    for i in range(2):
        for j in range(5):
            if (i == 0):
                tot = Tot(Point(j * 2, 3), 1)
            elif (i == 1):
                tot = Tot(Point(j * 2, 6), 0)
            board.chesses.append(tot)
            board.activeChesses.append(tot)
コード例 #9
0
def test_point_not_implemented():
    class Test:
        pass

    test = Test()
    p1 = Point()

    assert p1.__eq__(test) == NotImplemented
    assert p1.__ne__(test) == NotImplemented
コード例 #10
0
def test_comparison_operators():
    p1 = Point()
    p2 = Point()
    p3 = Point(2.0, 4.0)

    assert p1 == p2
    assert not p1 == p3
    assert p1 != p3
    assert not p1 != p2
コード例 #11
0
ファイル: test_point.py プロジェクト: Dilor/UnitPython
def test_point_operators():
    p1 = Point()
    p2 = Point()
    p3 = Point(1, 10)

    assert p1 == p2
    assert not p1 == p3
    assert not p1 != p2
    assert p1 != p3
コード例 #12
0
def test_point_operators():
    a = Point()
    b = Point()
    c = Point(2, 10)

    assert a == b
    assert not a != b
    assert b != c
    assert not b == c
コード例 #13
0
def test_point_setters():
    p = Point()

    assert p.x == 0.0
    assert p.y == 0.0

    p.x = 10
    p.y = 22

    assert p.x == 10.0
    assert p.y == 22.0
コード例 #14
0
def test_setters():
    point = Point()

    assert point.x == POINT_DEFAULT
    assert point.y == POINT_DEFAULT

    point.x = POINT_NEW_VALUE
    point.y = POINT_NEW_VALUE

    assert point.x == POINT_NEW_VALUE
    assert point.y == POINT_NEW_VALUE
コード例 #15
0
def test_point_properties():
    point = Point()

    assert point.x == 0.0
    assert point.y == 0.0

    point.x = 10.0
    point.y = 10.0

    assert point.x == 10.0
    assert point.y == 10.0
コード例 #16
0
def createTot():
    for i in range(2):
        for j in range(5):
            if (i == 0):
                tot = Tot(Point(j * 2, 3), 1)
            elif (i == 1):
                tot = Tot(Point(j * 2, 6), 0)
            chess.add(tot)
            for c in chesses:
                if type(c) == TempPoint:
                    if (c.point == tot.point):
                        c.deactivate()
コード例 #17
0
    def test_point_cmp_methods(self):
        p1 = Point(2, 5)
        p2 = Point(2, 5)
        p3 = Point(10, 9)

        self.assertEqual(p1, p2)
        self.assertNotEqual(p1, p3)

        self.assertTrue(p1 == p2)
        self.assertFalse(p1 == p3)

        self.assertTrue(p1 != p3)
        self.assertFalse(p1 != p2)
コード例 #18
0
ファイル: tuong.py プロジェクト: duchoa117/xiangqi
    def __init__(self, point, white):
        if (white == 1):
            Chess.__init__(self, point, "E", white)
            self.primitiveMove = []
            for i in range(0, 9, 1):
                for j in range(0, 5, 1):
                    self.primitiveMove.append(Point(i, j))

        elif (white == 0):
            Chess.__init__(self, point, "e", white)
            self.primitiveMove = []
            for i in range(0, 9, 1):
                for j in range(5, 10, 1):
                    self.primitiveMove.append(Point(i, j))

        self.value = 120
コード例 #19
0
ファイル: king.py プロジェクト: duchoa117/xiangqi
    def __init__(self, point, white):
        if (white == 1):
            Chess.__init__(self, point, "K", white)
            self.primitiveMove = []
            for i in range(3, 6, 1):
                for j in range(0, 3, 1):
                    self.primitiveMove.append(Point(i, j))

        elif (white == 0):
            Chess.__init__(self, point, "k", white)
            self.primitiveMove = []
            for i in range(3, 6, 1):
                for j in range(7, 10, 1):
                    self.primitiveMove.append(Point(i, j))

        self.value = 10000
コード例 #20
0
 def drive(self, destination: Point) -> None:
     distance: float = destination.distance(self.location)
     fuel_needed: float = distance * self.fuel_consumption
     if fuel_needed > self.fuel_amount:
         raise OutOfFuel
     self.location = destination
     self.fuel_amount -= fuel_needed
コード例 #21
0
def createKing():
    for i in range(2):
        king = King(Point(4, 0 + i * 9), 1 - i)
        chess.add(king)
        for c in chesses:
            if type(c) == TempPoint:
                if (c.point == king.point):
                    c.deactivate()
コード例 #22
0
def test_point_representation():
    point = Point()

    repr_string = repr(point)
    point_string = str(point)

    assert repr_string == '(0.0, 0.0)'
    assert point_string == '(0.0, 0.0)'
コード例 #23
0
def test_operators_exception():
    class Test:
        pass

    p = Point()

    with pytest.raises(TypeError):
        assert p == Test()
コード例 #24
0
def createSi():
    for i in range(2):
        for j in range(2):
            si = Si(Point(3 + j * 2, i * 9), 1 - i)
            chess.add(si)
            for c in chesses:
                if type(c) == TempPoint:
                    if (c.point == si.point):
                        c.deactivate()
コード例 #25
0
def normalize(points):
    from point.point import Point
    from point.coordinates.coordinates import lat_lng
    return [
        Point(
            lat_lng(lat=(point.coord.lat / (90 * 2)) + 0.5,
                    lng=(point.coord.lng / (180 * 2)) + 0.5,
                    r=2), point.timestamp, point.extra) for point in points
    ]
コード例 #26
0
 def positiveMove(self, currentBoard):
     # setUp:
     self.pMove.clear()
     # Your code:
     for i in range(self.point.x + 1, 9, 1):
         tPoint = Point(i, self.point.y)
         if (not chess.isChessPoint(tPoint, currentBoard)):
             self.pMove.append(tPoint)
         else:
             if (self.isTeammatePoint(tPoint, currentBoard)):
                 break
             else:
                 self.pMove.append(tPoint)
                 break
     for i in range(self.point.x - 1, -1, -1):
         tPoint = Point(i, self.point.y)
         if (not chess.isChessPoint(tPoint, currentBoard)):
             self.pMove.append(tPoint)
         else:
             if (self.isTeammatePoint(tPoint, currentBoard)):
                 break
             else:
                 self.pMove.append(tPoint)
                 break
     for i in range(self.point.y + 1, 10, 1):
         tPoint = Point(self.point.x, i)
         if (not chess.isChessPoint(tPoint, currentBoard)):
             self.pMove.append(tPoint)
         else:
             if (self.isTeammatePoint(tPoint, currentBoard)):
                 break
             else:
                 self.pMove.append(tPoint)
                 break
     for i in range(self.point.y - 1, -1, -1):
         tPoint = Point(self.point.x, i)
         if (not chess.isChessPoint(tPoint, currentBoard)):
             self.pMove.append(tPoint)
         else:
             if (self.isTeammatePoint(tPoint, currentBoard)):
                 break
             else:
                 self.pMove.append(tPoint)
                 break
コード例 #27
0
 def test_closest(self):
     result = closest(Test.points[0], Test.points[1:])
     expected = \
     DistanceTuple(
         point=Point(
             coord=lat_lng(lat=-56, lng=111, r=6371),
             timestamp=1,
             extra={'status': 'HAPPY'}),
         distance=566605.5984774233)
     self.assertEqual(result, expected)
コード例 #28
0
 def test_furthest(self):
     result = furthest(Test.points[0], Test.points[1:])
     expected = \
     DistanceTuple(
         point=Point(
             coord=lat_lng(lat=-76, lng=-134, r=6371),
             timestamp=2,
             extra={'status': 'HAPPY'}),
         distance=711820.7738464935)
     self.assertEqual(result, expected)
コード例 #29
0
 def __init__(self,
              capacity: float = 60,
              consumption: float = 0.6,
              location: Point = Point(0, 0),
              model: str = 'Mercedes') -> None:
     self._fuel_amount = 0
     self._fuel_capacity = float(capacity)
     self._fuel_consumption = float(consumption)
     self._model = str(model)
     self._location = location
コード例 #30
0
    def __init__(self, point, white):
        if (white == 1):
            Chess.__init__(self, point, "X", white)

        elif (white == 0):
            Chess.__init__(self, point, "x", white)
        self.primitiveMove = []
        for i in range(9):
            for j in range(10):
                self.primitiveMove.append(Point(i, j))
        self.value = 600