Beispiel #1
0
 def add_glass (pos):
     glass = RoundObstacle (40, 0)
     glass.pos = pos
     self.glasses.append (glass)
     glass = RoundObstacle (40, 0)
     glass.pos = (3000 - pos[0], pos[1])
     self.glasses.append (glass)
Beispiel #2
0
 def __init__ (self, cards = None):
     simu.model.table.Table.__init__ (self)
     # Draw cards.
     if cards is None:
         cards = (randint (1, 9), randint (1, 4))
     self.cards = cards
     # Well, this is a boring write only code which create every elements.
     # Put corn on the table.
     self.corns = [ ]
     corns_pos = ((0, 5), (0, 3), (0, 1), (1, 4), (1, 2), (1, 0), (2, 3),
             (2, 1), (3, 0), (3, 2))
     black_corns_cards = (
             (None, (1, 4), (0, 4), (2, 4), (2, 3), (0, 3), (1, 3), (1, 6),
                 (0, 6), (2, 6)),
             (None, (5, 8), (7, 8), (5, 9), (7, 9)),
             )
     black_corns = (black_corns_cards[0][cards[0]] +
             black_corns_cards[1][cards[1]])
     for i in xrange (len (corns_pos)):
         if corns_pos[i][0] == 3:
             poss = (corns_pos[i], )
         else:
             poss = (corns_pos[i], (6 - corns_pos[i][0], corns_pos[i][1]))
         for pos in poss:
             corn = RoundObstacle (25, 1)
             corn.pos = (150 + pos[0] * 450, 128 + pos[1] * 250)
             corn.black = i in black_corns
             self.corns.append (corn)
     # Put tomatos on the table.
     self.tomatos = [ ]
     tomatos_pos = ((0, 4), (0, 2), (1, 3), (1, 1), (2, 2), (2, 0), (3, 3),
             (3, 1))
     for tomato_pos in tomatos_pos:
         if tomato_pos[0] == 3:
             poss = (tomato_pos, )
         else:
             poss = (tomato_pos, (6 - tomato_pos[0], tomato_pos[1]))
         for pos in poss:
             tomato = RoundObstacle (50, 1)
             tomato.pos = (150 + pos[0] * 450, 128 + pos[1] * 250)
             self.tomatos.append (tomato)
     # Put oranges.
     self.oranges = [ ]
     self.oranges_pos = ((250 - 80, 70), (250 - 80 - 55, 70 + 75),
             (250 - 55, 70 + 75 + 50), (250 - 80, 70 + 75 + 50 + 100),
             (250 - 80 - 55, 70 + 75 + 50 + 100 + 75),
             (250 - 55, 70 + 75 + 50 + 100 + 75 + 50))
     for pos in self.oranges_pos:
         orange = RoundObstacle (50, 5)
         orange.pos = (1500 - pos[0], 2100 - pos[1])
         self.oranges.append (orange)
         orange = RoundObstacle (50, 5)
         orange.pos = (1500 + pos[0], 2100 - pos[1])
         self.oranges.append (orange)
     # Add everything to obstacles.
     self.obstacles += self.corns
     self.obstacles += self.tomatos
     self.obstacles += self.oranges
Beispiel #3
0
 def add_plate (pos, color):
     plate = RectangularObstacle ((170, 170), 0)
     plate.pos = pos
     plate.angle = 0
     plate.cherries = [ ]
     self.plates.append (plate)
     cpos = ((-42, -42), (-42, 0), (-42, +42), (0, -21), (0, 21),
             (42, -42), (42, 0), (42, +42))
     ccol = [ color ] + 7 * [ None ]
     random.shuffle (ccol)
     for p, c in zip (cpos, ccol):
         cherry = RoundObstacle (20, 0)
         cherry.pos = p
         cherry.color = c
         plate.cherries.append (cherry)
Beispiel #4
0
 def check_tower (self):
     """Check whether several elements can make a tower."""
     for slots in (self.front_slots, self.back_slots):
         if slots[0].pawn is not None and slots[1].pawn is not None:
             assert slots[0].pawn.kind != 'tower'
             tower = RoundObstacle (100, 1)
             tower.kind = 'tower'
             tower.tower = [ slots[0].pawn, slots[1].pawn ]
             slots[0].pawn, slots[1].pawn = tower, None
             self.table.add_pawn (tower)
         if slots[0].pawn is not None and slots[0].pawn.kind == 'tower' \
                 and slots[2].pawn and slots[2].door_motor.angle:
             slots[0].pawn.tower.append (slots[2].pawn)
             slots[2].pawn = None
         if slots[0].pawn is None and slots[1].pawn is None \
                 and slots[2].pawn and slots[2].door_motor.angle:
             slots[0].pawn, slots[2].pawn = slots[2].pawn, None
Beispiel #5
0
 def __init__ (self, pucks_card = None, dispensers_card = None):
     simu.model.table.Table.__init__ (self)
     # Draw cards.
     if pucks_card is None:
         pucks_card = randint (1, 10)
     if dispensers_card is None:
         dispensers_card = randint (1, 2)
     self.pucks_card = pucks_card
     self.dispensers_card = dispensers_card
     # Put pucks on the table.
     self.pucks = [ ]
     puck_n = { 1: (1, 2, 3), 2: (1, 3, 4), 3: (1, 3, 5), 4: (1, 3, 6),
             5: (2, 3, 4), 6: (2, 3, 5), 7: (2, 3, 6), 8: (3, 4, 5),
             9: (3, 4, 6), 10: (3, 5, 6) }
     for n in puck_n[pucks_card]:
         pos1 = ((n - 1) % 3, (n - 1) / 3)
         pos2 = (pos1[0], 3 - pos1[1])
         for pos in pos1, pos2:
             p = RoundObstacle (35, 1)
             p.pos = (1500 - 400 - 250 * pos[0], 1050 - 125 + 200 * pos[1])
             p.color = False
             self.pucks.append (p)
             p = RoundObstacle (35, 1)
             p.pos = (1500 + 400 + 250 * pos[0], 1050 - 125 + 200 * pos[1])
             p.color = True
             self.pucks.append (p)
     # Put pucks in dispensers.
     if self.dispensers_card == 1:
         ds = -250
     else:
         ds = +250
     for pos, color in (
             ((289, 40), True),
             ((3000 - 289, 40), False),
             ((40, 1050 + ds), True),
             ((3000 - 40, 1050 + ds), False),
             ):
         for i in range (5):
             p = RoundObstacle (35, 1)
             p.pos = (pos[0] + i * 2, pos[1] + i * 2)
             p.color = color
             self.pucks.append (p)
     # Add pucks in obstacles.
     self.obstacles += self.pucks
Beispiel #6
0
 def add_coin (pos, angle, level = 1):
     coin = RoundObstacle (60, level)
     coin.pos = pos
     coin.angle = angle
     coin.value = 1
     self.coins.append (coin)
Beispiel #7
0
 def add_candle (pos, level, color):
     candle = RoundObstacle (40, level)
     candle.pos = pos
     candle.color = color
     candle.state = False
     self.candles.append (candle)
Beispiel #8
0
 def __init__ (self, cards = None):
     simu.model.table.Table.__init__ (self)
     # Candles.
     self.candles = [ ]
     def add_candle (pos, level, color):
         candle = RoundObstacle (40, level)
         candle.pos = pos
         candle.color = color
         candle.state = False
         self.candles.append (candle)
     def add_candle_circle (center, radius, start, step, colors, level):
         angle = start
         for color in colors:
             pos = (center[0] + radius * math.cos (angle),
                     center[1] + radius * math.sin (angle))
             add_candle (pos, level, color)
             angle += step
     colors_r = [ False, False, False, True, True, True ]
     random.shuffle (colors_r)
     colors = [ False ] + colors_r + [ True ]
     add_candle_circle ((1500, 2000), 350, pi + pi / 16, pi / 8, colors, 3)
     colors_r = [ False, False, False, True, True, True ]
     random.shuffle (colors_r)
     colors = ([ False ] + colors_r[0:3] + [ None, None, None, None ]
             + colors_r[3:6] + [ True ])
     add_candle_circle ((1500, 2000), 450, pi + pi / 24, pi / 12, colors, 2)
     cake = RoundObstacle (500, 0)
     cake.pos = (1500, 2000)
     cake_us = RoundObstacle (400, 4)
     cake_us.pos = (1500, 2000)
     # Glasses.
     self.glasses = [ ]
     def add_glass (pos):
         glass = RoundObstacle (40, 0)
         glass.pos = pos
         self.glasses.append (glass)
         glass = RoundObstacle (40, 0)
         glass.pos = (3000 - pos[0], pos[1])
         self.glasses.append (glass)
     add_glass ((900, 550))
     add_glass ((1200, 550))
     add_glass ((1050, 800))
     add_glass ((1350, 800))
     add_glass ((900, 1050))
     add_glass ((1200, 1050))
     # Cherries.
     self.plates = [ ]
     def add_plate (pos, color):
         plate = RectangularObstacle ((170, 170), 0)
         plate.pos = pos
         plate.angle = 0
         plate.cherries = [ ]
         self.plates.append (plate)
         cpos = ((-42, -42), (-42, 0), (-42, +42), (0, -21), (0, 21),
                 (42, -42), (42, 0), (42, +42))
         ccol = [ color ] + 7 * [ None ]
         random.shuffle (ccol)
         for p, c in zip (cpos, ccol):
             cherry = RoundObstacle (20, 0)
             cherry.pos = p
             cherry.color = c
             plate.cherries.append (cherry)
     for py in (250, 600, 1000, 1400, 1750):
         add_plate ((200, py), False)
         add_plate ((3000 - 200, py), True)
     self.cherries = Cherries ()
     # Gifts.
     self.gifts = [ ]
     def add_gift (pos, color):
         gift = RectangularObstacle ((150, 50), 0)
         gift.pos = pos
         gift.color = color
         gift.state = False
         self.gifts.append (gift)
     def add_gifts (pos):
         add_gift ((pos[0] - 176 / 2, pos[1] - 72), False)
         add_gift ((pos[0] + 176 / 2, pos[1] - 72), True)
     add_gifts ((600, 0))
     add_gifts ((1200, 0))
     add_gifts ((1800, 0))
     add_gifts ((2400, 0))
     # Add everything to obstacles.
     self.obstacles.append (cake)
     self.obstacles.append (cake_us)
     self.obstacles += self.candles
     self.obstacles += self.glasses
     self.obstacles += self.plates
     self.obstacles += self.gifts
Beispiel #9
0
 def __init__ (self, cards = None):
     simu.model.table.Table.__init__ (self)
     # Draw cards.
     cards = [ ]
     while len (cards) != 3:
         card = randrange (20)
         if card not in cards:
             cards.append (card)
     self.cards = cards
     def pos (card):
         king_pos = card // 4
         queen_pos = card % 4
         if queen_pos >= king_pos:
             queen_pos += 1
         return (king_pos, queen_pos)
     # Well, this is a boring write only code which create every elements.
     self.pawns = [ ]
     # Put pawns in green zones.
     green_pos = pos (cards[0])
     for i in xrange (5):
         if i == green_pos[0]:
             kind = 'king'
         elif i == green_pos[1]:
             kind = 'queen'
         else:
             kind = 'pawn'
         pawn = RoundObstacle (100, 1)
         pawn.pos = (200, 10 + 280 * (5 - i))
         pawn.kind = kind
         self.pawns.append (pawn)
         pawn = RoundObstacle (100, 1)
         pawn.pos = (3000 - 200, 10 + 280 * (5 - i))
         pawn.kind = kind
         self.pawns.append (pawn)
     # Put pawns in playing zone.
     kind = 'pawn'
     for j in xrange (2):
         play_pos = pos (cards[2 - j])
         for i in xrange (5):
             if i in play_pos:
                 pawn = RoundObstacle (100, 1)
                 pawn.pos = (1500 - 350 * (1 + j), 350 * (5 - i))
                 pawn.kind = kind
                 self.pawns.append (pawn)
                 pawn = RoundObstacle (100, 1)
                 pawn.pos = (1500 + 350 * (1 + j), 350 * (5 - i))
                 pawn.kind = kind
                 self.pawns.append (pawn)
     # Put center pawn.
     kind = 'pawn'
     pawn = RoundObstacle (100, 1)
     pawn.pos = (1500, 350 * 3)
     pawn.kind = kind
     self.pawns.append (pawn)
     # Add everything to obstacles.
     self.obstacles += self.pawns
Beispiel #10
0
 def new_round_obstacle (self):
     o = RoundObstacle (self.new_obstacle_radius.get ())
     o.pos = (5, -5)
     self.area_view.area.table.obstacles.append (o)
     self.update ()
Beispiel #11
0
        o = RoundObstacle (self.new_obstacle_radius.get ())
        o.pos = (5, -5)
        self.area_view.area.table.obstacles.append (o)
        self.update ()

    def new_rectangular_obstacle (self):
        o = RectangularObstacle ((float (self.new_obstacle_dim0.get ()),
            float (self.new_obstacle_dim1.get ())))
        o.pos = (5, -5)
        o.angle = 0
        self.area_view.area.table.obstacles.append (o)
        self.update ()

    def new_polygonal_obstacle (self):
        s = float (self.new_obstacle_scale.get ())
        p = [ (s * x, s * y) for x, y in ((1, 1), (0.7, -0.7), (0, -0.2),
            (-0.8, -0.7), (-1, 1.5)) ]
        o = PolygonalObstacle (*p)
        o.pos = (5, -5)
        o.angle = 0
        self.area_view.area.table.obstacles.append (o)
        self.update ()

if __name__ == '__main__':
    app = TestTable ()
    o = RoundObstacle (2)
    o.pos = (5, 5)
    app.area_view.area.table.obstacles.append (o)
    app.update (False)
    app.mainloop ()
Beispiel #12
0
            m.rotate (i.angle)
        pos, target = m.apply (pos, target)
        # Find intersection.
        i = self.table.intersect (pos, target, level = self.level,
                comp = lambda a, b: a < b, exclude = self.exclude)
        if i is not None:
            self.distance = i.distance
        else:
            self.distance = None

if __name__ == '__main__':
    from simu.model.table import Table
    from simu.model.round_obstacle import RoundObstacle
    from math import pi
    t = Table ()
    ro1 = RoundObstacle (0.5)
    ro1.pos = (0, 0)
    t.obstacles.append (ro1)
    ro2 = RoundObstacle (1)
    ro2.pos = (1, 0)
    t.obstacles.append (ro2)
    ds = DistanceSensor (t, (-1, 0), 0, 1)
    ds.evaluate ()
    assert ds.distance == 0.5
    ds = DistanceSensor (t, (-1, -1), 0, 1)
    ds.evaluate ()
    assert ds.distance is None
    ds = DistanceSensor (t, (3, 0), pi, 3)
    ds.evaluate ()
    assert ds.distance == 1.0