Beispiel #1
0
class OKing(OPawn):
    _sh_cross_bar = _so.ShBox(_vec3(0.06, 0.02, 0.02))
    _shape = _so.ShCompound((
        (OPawn._shape, _so.trans()),
        (_sh_cross_bar, _so.trans(_vec3(z=0.06 + _MagnetPawn.HEIGHT / 2))),
        (_sh_cross_bar,
         _so.trans(_so.matrix3(pitch=_math.pi / 2),
                   _vec3(z=0.06 + _MagnetPawn.HEIGHT / 2))),
    ))
    _mass = 0.5  # 300g to 700g
Beispiel #2
0
  def prepare(self, fconf=None):
    if fconf is None:
      self.conf = self.Conf.random()
    else:
      self.conf = self.Conf(*fconf)

    ph = self.physics

    # Ground and raised zone
    ground = OGround()
    ground.addToWorld(ph)
    self.ground = ground
    o = ORaisedZone()
    o.pos = _vec3(0, TABLE_SIZE.y-0.500, 0)/2
    o.addToWorld(ph)

    # Walls (N, E, W, S)
    color = _eb.RAL[9017]
    sh = _so.ShBox(_vec3(TABLE_SIZE.x+WALL_WIDTH, WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, TABLE_SIZE.y+WALL_WIDTH, WALL_HEIGHT)/2
    o.color = color

    sh = _so.ShBox(_vec3(WALL_WIDTH, TABLE_SIZE.y+2*WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(TABLE_SIZE.x+WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = color

    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-TABLE_SIZE.x-WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = color

    sh = _so.ShBox(_vec3(TABLE_SIZE.x-2*Bac.SIZE.x, WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, -TABLE_SIZE.y-WALL_WIDTH, WALL_HEIGHT)/2
    o.color = color

    # Bacs
    self.bacs = ( Bac(0), Bac(1) )
    for o in self.bacs:
      o.addToWorld(ph)

    # Tomatoes
    for v in TOMATOES_FPOS:
      self.addTomato(v)

    # Corns
    fakes = FAKES_FPOS_CENTER[self.conf.center] | FAKES_FPOS_SIDE[self.conf.side]
    for v in CORNS_FPOS:
      self.addCorn(v, v in fakes)

    # Oranges and trees
    self.addTree(-1,-1)
    self.addTree(-1, 1)
    self.addTree( 1,-1)
    self.addTree( 1, 1)
Beispiel #3
0
 def createOrange(self):
   o = OOrange()
   o.mass = 0  #XXX oranges not simulated
   o.addToWorld(self.physics)
   z = ORaisedZone.HEIGHT+self.h+0.050*_math.cos(_math.asin(0.025/0.050))
   o.pos = _vec3(self.pos.x, self.pos.y, z)
   return o
Beispiel #4
0
class OPawn(_MagnetPawn):
    _shape = _so.ShCylinderZ(
        _vec3(_MagnetPawn.RADIUS, _MagnetPawn.RADIUS, _MagnetPawn.HEIGHT / 2))
    _mass = 0.3  # 200g to 500g

    def __init__(self):
        _MagnetPawn.__init__(self, self._shape, self._mass)
        self.color = _eb.RAL[1023]
Beispiel #5
0
  def __init__(self, team):
    if team == 0:
      xy0 = self.XY0
    elif team == 1:
      xy0 = self.XY0 * _vec2(-1,1)
    else:
      raise ValueError("invalid team")
    self.team = int(team)

    ob = _so.OSimple(self.sh_band)
    ob.pos = _vec3(0,0, WALL_HEIGHT/2) + xy0
    ob.color = TEAM_COLORS[self.team]

    op = _so.OSimple(self.sh_plexi)
    op.pos = _vec3(0,0, -self.HEIGHT/2) + xy0
    op.color = _so.Color.plexi

    self.band = ob
    self.plexi = op
Beispiel #6
0
class OPlate(_so.OSimple):
  _mass = 0.220
  _sh_bar_x = _so.ShBox(_vec3(.170, .022, .022)/2)
  _sh_bar_y = _so.ShBox(_vec3(.022, .170, .022)/2)
  _shape = _so.ShCompound((
    (_sh_bar_x, _so.trans(_vec3(0, -(.170-.022), .005)/2)),
    (_sh_bar_x, _so.trans(_vec3(0,  (.170-.022), .005)/2)),
    (_sh_bar_y, _so.trans(_vec3(-(.170-.022), 0, .005)/2)),
    (_sh_bar_y, _so.trans(_vec3( (.170-.022), 0, .005)/2)),
    (_so.ShBox(_vec3(.170, .170, .005)/2), _so.trans(_vec3(0, 0, -.022/2))),
    ))

  def __init__(self):
    _so.OSimple.__init__(self, self._shape, self._mass)
    self.color = _eb.RAL[3015]
Beispiel #7
0
 def branchPos(cls, x, y, h):
   """Compute position of a given branch for a given tree.
   x and y are -1 or 1 and give tree position.
   """
   assert x in (1,-1) and y in (-1,1), "invalid tree position"
   assert h in (0.25, 0.20, 0.15), "invalid tree height"
   dx = {0.25: 0, 0.20: 0.055, 0.15:  0.080}[h]
   dy = {0.25: 0, 0.20: 0.075, 0.15: -0.050}[h]
   y0 = {1: 0.250-0.070-0.075, -1: -0.250+0.080+0.050}[y]
   return _vec3(
       x * (0.500/2-0.080-0.055 + dx),
       y0 + dy + TABLE_SIZE.y/2-0.250,
       ORaisedZone.HEIGHT-cls._HEIGHT/2+h
       )
Beispiel #8
0
class OBranch(_so.OSimple):

  _HEIGHT = 0.25
  _shape = _so.ShCylinderZ(_vec3(0.025, 0.025, _HEIGHT/2))

  def __init__(self, h):
    _so.OSimple.__init__(self)
    self.shape = (self._shape)
    #actual color differs from rules
    #self.color = _so.Color.white
    self.color = _so.Color(1.)
    self.h = h

  def createOrange(self):
    o = OOrange()
    o.mass = 0  #XXX oranges not simulated
    o.addToWorld(self.physics)
    z = ORaisedZone.HEIGHT+self.h+0.050*_math.cos(_math.asin(0.025/0.050))
    o.pos = _vec3(self.pos.x, self.pos.y, z)
    return o

  @classmethod
  def branchPos(cls, x, y, h):
    """Compute position of a given branch for a given tree.
    x and y are -1 or 1 and give tree position.
    """
    assert x in (1,-1) and y in (-1,1), "invalid tree position"
    assert h in (0.25, 0.20, 0.15), "invalid tree height"
    dx = {0.25: 0, 0.20: 0.055, 0.15:  0.080}[h]
    dy = {0.25: 0, 0.20: 0.075, 0.15: -0.050}[h]
    y0 = {1: 0.250-0.070-0.075, -1: -0.250+0.080+0.050}[y]
    return _vec3(
        x * (0.500/2-0.080-0.055 + dx),
        y0 + dy + TABLE_SIZE.y/2-0.250,
        ORaisedZone.HEIGHT-cls._HEIGHT/2+h
        )
Beispiel #9
0
  def prepare(self, fconf=None):
    if fconf is None:
      self.conf = self.Conf.random()
    else:
      self.conf = self.Conf(*fconf)

    ph = self.physics

    # Ground
    ground = OGround()
    ground.addToWorld(ph)
    self.ground = ground

    # Walls (N, S, E, W)
    color = _eb.RAL[9017]
    sh = _so.ShBox(_vec3(TABLE_SIZE.x+WALL_WIDTH, WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, TABLE_SIZE.y+WALL_WIDTH, WALL_HEIGHT)/2
    o.color = color

    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, -TABLE_SIZE.y-WALL_WIDTH, WALL_HEIGHT)/2
    o.color = color

    sh = _so.ShBox(_vec3(WALL_WIDTH, TABLE_SIZE.y+2*WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(TABLE_SIZE.x+WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = color

    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-TABLE_SIZE.x-WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = color

    # Starting areas, inside borders
    sh = _so.ShBox(_vec3(ground.start_size, WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-TABLE_SIZE.x+ground.start_size, TABLE_SIZE.y-WALL_WIDTH-2*ground.start_size, WALL_HEIGHT)/2
    o.color = TEAM_COLORS[0]
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(TABLE_SIZE.x-ground.start_size, TABLE_SIZE.y-WALL_WIDTH-2*ground.start_size, WALL_HEIGHT)/2
    o.color = TEAM_COLORS[1]

    # Secured zones, borders (centered on surrounded squares)
    sh_wall = _so.ShBox(_vec3(WALL_WIDTH, 0.150, WALL_HEIGHT)/2)
    sh_block = _so.ShBox(_vec3(0.700, 0.120, WALL_HEIGHT)/2)
    sh = _so.ShCompound((
      (sh_wall,  _so.trans(_vec2(-SQUARE_SIZE+WALL_WIDTH/2))),
      (sh_wall,  _so.trans(_vec2( SQUARE_SIZE-WALL_WIDTH/2))),
      (sh_block, _so.trans(_vec2(0, (-SQUARE_SIZE+0.120)/2))),
      ))
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-2*SQUARE_SIZE, -2.5*SQUARE_SIZE, WALL_HEIGHT/2)
    o.color = color
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(2*SQUARE_SIZE, -2.5*SQUARE_SIZE, WALL_HEIGHT/2)
    o.color = color


    # Pawns on the field

    self.pawns = [ self.addPiece(0,0) ]
    for j in RANDOM_POS[self.conf.line1]:
      y = (j-2)*SQUARE_SIZE
      self.pawns.append( self.addPiece(-2*SQUARE_SIZE,y) )
      self.pawns.append( self.addPiece( 2*SQUARE_SIZE,y) )
    for j in RANDOM_POS[self.conf.line2]:
      y = (j-2)*SQUARE_SIZE
      self.pawns.append( self.addPiece(-1*SQUARE_SIZE,y) )
      self.pawns.append( self.addPiece( 1*SQUARE_SIZE,y) )

    # Pieces in dispensing zones

    pos_king, pos_queen = RANDOM_POS[self.conf.kingqueen]
    x = (TABLE_SIZE.x - ground.start_size)/2
    for j in range(5):
      y = -TABLE_SIZE.y/2 + (5-j)*DISPENSING_DY
      if j == pos_king:
        self.kings = ( self.addPiece(-x, y, OKing), self.addPiece(x, y, OKing) )
      elif j == pos_queen:
        self.queens = ( self.addPiece(-x, y, OQueen), self.addPiece(x, y, OQueen) )
      else:
        self.pawns.append( self.addPiece(-x,y) )
        self.pawns.append( self.addPiece( x,y) )
Beispiel #10
0
  def prepare(self, fconf=None):

    ph = self.physics

    # Ground and cake
    ground = OGround()
    ground.addToWorld(ph)
    self.ground = ground
    cake = OCake()
    cake.addToWorld(ph)

    # sideboards (NE, SE, NW, SE)
    sh = _so.ShBox(_vec3(OGround.SQUARE_SIZE, 0.100, WALL_WIDTH)/2)
    for x in (TABLE_SIZE.x-OGround.SQUARE_SIZE, -TABLE_SIZE.x+OGround.SQUARE_SIZE):
      for y in (TABLE_SIZE.y-0.100, -TABLE_SIZE.y+0.100):
        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(x, y, 0)/2
        o.color = _eb.RAL[9016]

    # Walls (NE, NW, S, E, W)
    sh = _so.ShBox(_vec3(TABLE_SIZE.x/2+WALL_WIDTH, WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(TABLE_SIZE.x/2+WALL_WIDTH, TABLE_SIZE.y+WALL_WIDTH, WALL_HEIGHT)/2
    o.color = TEAM_COLORS[1]
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-TABLE_SIZE.x/2-WALL_WIDTH, TABLE_SIZE.y+WALL_WIDTH, WALL_HEIGHT)/2
    o.color = TEAM_COLORS[0]

    sh = _so.ShBox(_vec3(TABLE_SIZE.x+2*WALL_WIDTH, WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, -TABLE_SIZE.y-WALL_WIDTH, WALL_HEIGHT)/2
    o.color = _eb.RAL[1023]

    sh = _so.ShBox(_vec3(WALL_WIDTH, TABLE_SIZE.y+2*WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(TABLE_SIZE.x+WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = TEAM_COLORS[1]

    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-TABLE_SIZE.x-WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = TEAM_COLORS[0]

    # gifts
    for x in (-0.9, -0.3, 0.3, 0.9):
      o = OGiftSupport()
      o.addToWorld(ph)
      o.pos = _vec3(x, -TABLE_SIZE.y/2-WALL_WIDTH, WALL_HEIGHT-0.060)

    # candles
    def add_candle(r, z, a, color):
      o = OCandle()
      o.addToWorld(ph)
      o.color = color
      x, y = r*_math.cos(-_math.pi/2 + a), r*_math.sin(-_math.pi/2 + a)
      o.pos = _vec3(x, y+TABLE_SIZE.y/2, z+OCandle.HEIGHT/2)

    for i in range(6):
      a = _math.radians(-7.5*(2*i+1))
      if i < 2:
        colors = (_eb.RAL[9016], _eb.RAL[9016])
      elif i == 5:
        colors = TEAM_COLORS
      else:
        colors = random.choice((TEAM_COLORS, TEAM_COLORS[::-1]))
      add_candle(0.450, 0.100, a, colors[0])
      add_candle(0.450, 0.100, -a, colors[1])

    for i in range(4):
      a = _math.radians(-11.25*(2*i+1))
      if i == 3:
        colors = TEAM_COLORS
      else:
        colors = random.choice((TEAM_COLORS, TEAM_COLORS[::-1]))
      add_candle(0.350, 0.200, a, colors[0])
      add_candle(0.350, 0.200, -a, colors[1])


    # plates and cherries
    cherries_pos = [  # position, in cherry radii
        (-2, -2), (0, -2), (2, -2),
        (-1, 0), (1, 0),
        (-2, 2), (0, 2), (2, 2),
        ]
    for kx in (-1, 1):
      for y in (-.750, -.400, 0, .400, .750):
        o = OPlate()
        o.addToWorld(ph)
        o.pos = _vec2(kx*(TABLE_SIZE.x-OGround.SQUARE_SIZE)/2, y)
        # rotten cherry (colored)
        i_rotten = random.randrange(len(cherries_pos))
        for i,(cx,cy) in enumerate(cherries_pos):
          if i == i_rotten:
            co = OCherry(1 if kx == 1 else 0)
          else:
            co = OCherry()
          co.addToWorld(ph)
          co.pos = o.pos + _vec3(cx*co.r, cy*co.r, co.r+0.010)

    # glasses
    glasses_pos = [  # positions for x>0
        (.300,  .050), (.600,  .050),
        (.150, -.200), (.450, -.200),
        (.300, -.450), (.600, -.450),
        ]
    for kx in (-1, 1):
      for x,y in glasses_pos:
        o = OGlass()
        o.addToWorld(ph)
        o.pos = _vec2(kx*x, y)
Beispiel #11
0
"""

from _simulotter._eurobot2009 import *
import _simulotter as _so
import eurobot as _eb

from _simulotter import vec2 as _vec2, vec3 as _vec3
from eurobot import WALL_WIDTH, WALL_HEIGHT

TABLE_SIZE = _vec2(3.0, 2.1)
TEAM_COLORS = (_eb.RAL[6018], _eb.RAL[3020])

# field contants
COL_SPACE_XY = _vec2(0.250, 0.200)
COL_OFFSET_XY = _vec2(0.400, 0.125)
DISP_OFFSET = _vec3(0.289, 0.250, 0.045)

COL_POS = (
    (0,1,2), (0,2,5), (0,2,4), (0,2,3), (0,1,4),
    (0,1,5), (0,4,5), (0,1,3), (0,3,5), (0,3,4),
    )


class OGround(_so.OGroundSquareStart):
  def __init__(self):
    _so.OGroundSquareStart.__init__(self, TABLE_SIZE, _eb.RAL[5015], *TEAM_COLORS)


class Match(_eb.Match):
  """
  Gather match data.
Beispiel #12
0
  def prepare(self, fconf=None):
    if fconf is None:
      self.conf = self.Conf.random()
    else:
      self.conf = self.Conf(*fconf)

    ph = self.physics

    # Ground
    ground = OGround()
    ground.addToWorld(ph)
    self.ground = ground

    # Walls (N, S, E, W)
    color = _eb.RAL[5012]
    sh = _so.ShBox(_vec3(TABLE_SIZE.x+WALL_WIDTH, WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, TABLE_SIZE.y+WALL_WIDTH, WALL_HEIGHT)/2
    o.color = color

    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, -TABLE_SIZE.y-WALL_WIDTH, WALL_HEIGHT)/2
    o.color = color

    sh = _so.ShBox(_vec3(WALL_WIDTH, TABLE_SIZE.y+2*WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(TABLE_SIZE.x+WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = color

    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-TABLE_SIZE.x-WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = color

    # Ship borders
    W = 0.018  # border width
    deck_angle = _math.atan2(0.4-0.325, TABLE_SIZE.y-ground.start_size-W)

    sh = _so.ShBox(_vec3(0.4, W, W)/2)
    for kx in (1, -1):
      o = _so.OSimple(sh)
      o.addToWorld(ph)
      o.color = _eb.RAL[8002]
      o.pos = _vec3(kx*(TABLE_SIZE.x-0.4)/2, TABLE_SIZE.y/2-ground.start_size-W/2, W/2)

    r = 0.75
    sh = _so.ShBox(_vec3(W, r, W)/2)
    for kx in (1, -1):
      a = kx*deck_angle
      o = _so.OSimple(sh)
      o.addToWorld(ph)
      o.color = _eb.RAL[8002]
      o.trans = _so.trans(
          _so.quat(_vec3(0,0,1), a),
          # hacky offset, for better-looking result
          _vec3(kx*( TABLE_SIZE.x/2-(3*0.325+0.4)/4-W*_math.cos(a)/2 +0.002),
            (-TABLE_SIZE.y+r*_math.cos(a))/2, W/2
          ))

    # Ship's hold covers
    # static for now (cannot be opened)
    ox = (TABLE_SIZE.x-0.340)/2 + 0.018
    oy = -(TABLE_SIZE.y-0.610)/2 - 0.018
    sh_barh = _so.ShBox(_vec3(0.340, 0.018, 0.018)/2)
    sh_barv = _so.ShBox(_vec3(0.018, 0.610, 0.018)/2)
    sh = _so.ShCompound((
      (sh_barh, _so.trans(_vec3(0, 0.610-0.018, 0)/2)),
      (sh_barh, _so.trans(_vec3(0, -(0.610-0.018), 0)/2)),
      (sh_barv, _so.trans(_vec3(0.340-0.018, 0, 0)/2)),
      (sh_barv, _so.trans(_vec3(-(0.340-0.018), 0, 0)/2)),
      ))
    for kx in (1, -1):
      o = _so.OSimple(sh)
      o.addToWorld(ph)
      o.color = _eb.RAL[8002]
      o.pos = _vec3(kx*ox, oy, WALL_HEIGHT+0.018/2)

    sh = _so.ShBox(_vec3(0.340, 0.610, 0.001)/2)
    for kx in (1, -1):
      o = _so.OSimple(sh)
      o.addToWorld(ph)
      o.color = _so.Color.plexi
      o.pos = _vec3(kx*ox, oy, WALL_HEIGHT+0.018+0.001/2)

    # Palm-tree
    sh = _so.ShCylinderZ(_vec3(0.04, 0.04, 0.250)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.color = _eb.RAL[8002]
    o.pos = _vec3(0, 0, 0.250/2)
    sh = _so.ShCylinderZ(_vec3(0.150, 0.150, 0.002)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.color = _eb.RAL[6018]
    o.pos = _vec3(0, 0, 0.250+0.002/2)

    # Totems
    sh_trunk = _so.ShBox(_vec3(0.070, 0.070, 0.163)/2)
    sh_flat = _so.ShBox(_vec3(0.250, 0.250, 0.018)/2)
    sh = _so.ShCompound((
      (sh_trunk, _so.trans()),
      (sh_flat, _so.trans(_vec3(0, 0, -0.0545-0.018))),
      (sh_flat, _so.trans(_vec3(0, 0, 0))),
      (sh_flat, _so.trans(_vec3(0, 0, +0.0545+0.018))),
      ))
    for kx in (1, -1):
      o = _so.OSimple(sh)
      o.addToWorld(ph)
      o.color = _eb.RAL[8002]
      o.pos = _vec3(kx*0.8, 0, 0.163)/2

    # Treasure map
    #TODO map width is not known yet, centered on X
    map_width = 0.400
    sh_back = _so.ShBox(_vec3(map_width, 0.258, 0.010)/2)
    sh_side = _so.ShBox(_vec3(0.018, 0.258, 0.018)/2)
    # origin is the nearest point to the table
    sh = _so.ShCompound((
      (sh_back, _so.trans(_vec3(0, 0.258/2, 0.010/2))),
      (sh_side, _so.trans(_vec3(-(map_width-0.018)/2, 0.258/2, 0.010+0.018/2))),
      (sh_side, _so.trans(_vec3( (map_width-0.018)/2, 0.258/2, 0.010+0.018/2))),
      ))
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.color = _eb.RAL[5012]
    a = _math.radians(35)
    o.trans = _so.trans(
        _so.quat(_vec3(1,0,0), a),
        _vec3(0, TABLE_SIZE.y/2, 0.315-(0.258+(0.018+0.10))*_math.sin(a))
        )

    # Bottle supports
    w = WALL_WIDTH
    sh_small = _so.ShBox(_vec3(0.089, w, w)/2)
    sh_large = _so.ShBox(_vec3(0.200, w, w)/2)
    sh = _so.ShCompound((
      (sh_small, _so.trans(_vec3(-(0.089+w)/2, -w/2, w/2))),
      (sh_small, _so.trans(_vec3( (0.089+w)/2, -w/2, w/2))),
      (sh_large, _so.trans(_vec3(0, -w/2, w+w/2))),
      (sh_large, _so.trans(_vec3(0, -w-w/2, -w/2))),
      ))
    for x in (TABLE_SIZE.x/2-0.640, -(TABLE_SIZE.x/2-0.640-0.477)):
      for kx in (1, -1):
        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.color = _eb.RAL[5012]
        o.pos = _vec3(kx*x, -TABLE_SIZE.y/2, WALL_HEIGHT)

    # Bottle buttons
    # origin is the attache point on the border (y=WALL_HEIGHT)
    # reuse sh_large and w from bottle supports
    #TODO sh_buttonv Y size is not known
    sh_buttonh = _so.ShBox(_vec3(w, 2*w, w)/2)
    sh_buttonv = _so.ShBox(_vec3(w, w, 0.103)/2)
    sh = _so.ShCompound((
      (sh_large, _so.trans(_vec3(0, -w-w/2, w/2))),
      (sh_buttonh, _so.trans(_vec3(0, 0, w/2))),
      (sh_buttonv, _so.trans(_vec3(0, w+w/2, -WALL_HEIGHT+0.003+0.103/2))),
      ))
    for x in (TABLE_SIZE.x/2-0.640, -(TABLE_SIZE.x/2-0.640-0.477)):
      for kx in (1, -1):
        o = _so.OSimple(sh, 0.100)
        o.addToWorld(ph)
        o.color = TEAM_COLORS[ 1 if kx == 1 else 0 ]
        o.pos = _vec3(kx*x, -TABLE_SIZE.y/2, WALL_HEIGHT)


    # Bullions
    bsize = OBullion.SIZE
    l = []  # x, y, z_bottom, angle_z
    l.append((0, -TABLE_SIZE.y/2+0.647, 0, 0))
    for kx in (1, -1):
      # bullion along the deck
      v = _vec2(TABLE_SIZE.x/2-0.400-bsize.y/2, TABLE_SIZE.y/2-ground.start_size)
      v += _vec2(0, -0.285-bsize.x/2).rotate(deck_angle)
      l.append((kx*v.x, v.y, 0, _math.pi/2+kx*deck_angle))
      # bullions on totems
      l.append((kx*0.8/2,  (0.070+0.090)/2, 0.018+0.0545+0.018, 0))
      l.append((kx*0.8/2, -(0.070+0.090)/2, 0.018+0.0545+0.018, 0))
    for x,y,z0,a in l:
      o = OBullion()
      o.addToWorld(ph)
      o.trans = _so.trans(
          _so.quat(_vec3(0,0,1), a),
          _vec3(x, y, z0 + bsize.z/2 + ph.margin_epsilon)
          )

    # Coins
    #XXX exact position of several coins is not known
    l = [
        # (x>0, y, z_bottom, angle_z)
        (TABLE_SIZE.x/2-0.450, -TABLE_SIZE.y/2+0.300, 0, 0),
        (0.090, -TABLE_SIZE.y/2+0.300, 0, 0)
        ]
    for i in range(-3,4):
      a = i*_math.pi/4
      ca = _math.cos(a)
      sa = _math.sin(a)
      l.append( (0.8/2+0.25*ca, 0.25*sa, 0, a) )
      if i % 2 == 1:
        l.append( (0.8/2+0.100*ca, 0.110*sa, 0.018, a) )
        l.append( (0.8/2+0.100*ca, 0.110*sa, 0.163, a) )
    # group coins them by pairs for random picking of black coins
    lpairs = [(
        (0, -TABLE_SIZE.y/2+0.300+0.090, 0, _math.pi/2),
        (0, -TABLE_SIZE.y/2+0.300-0.090, 0, -_math.pi/2)
        )]
    for x,y,z0,a in l:
      lpairs.append(((x,y,z0,a), (-x,y,z0,-a+_math.pi)))

    # pick up random pairs which will be black
    import random
    black_pairs = random.sample(lpairs, 2)

    # last pair, never black
    lpairs.append((
      (  TABLE_SIZE.x/2-0.5-0.5,  TABLE_SIZE.y/2-0.5, 0, 0),
      (-(TABLE_SIZE.x/2-0.5-0.5), TABLE_SIZE.y/2-0.5, 0, _math.pi)
      ))

    # finally, created the coins
    for p in lpairs:
      white = p not in black_pairs
      for x,y,z0,a in p:
        o = OCoin(white)
        o.addToWorld(ph)
        o.trans = _so.trans(
            _so.quat(_vec3(0,0,1), a),
            _vec3(x, y, z0 + OCoin.CUBE_SIZE + ph.margin_epsilon)
            )
Beispiel #13
0
class Bac:
  """Collect bac."""

  XY0 = _vec2(TABLE_SIZE.x-0.500, -TABLE_SIZE.y)/2
  SIZE = _vec2(0.500, 0.300)
  WIDTH = 0.010
  HEIGHT = 0.300

  _band_side    = _so.ShBox(_vec3(WIDTH, SIZE.y, WALL_HEIGHT)/2)
  _plexi_side   = _so.ShBox(_vec3(WIDTH, SIZE.y, HEIGHT)/2)
  _band_back    = _so.ShBox(_vec3(SIZE.x+2*WIDTH, WIDTH, WALL_HEIGHT)/2)
  _plexi_back   = _so.ShBox(_vec3(SIZE.x+2*WIDTH, WIDTH, HEIGHT)/2)
  _plexi_front  = _so.ShBox(_vec3(SIZE.x+2*WIDTH, WIDTH, HEIGHT-0.040)/2)
  _plexi_bottom = _so.ShBox(_vec3(SIZE.x+2*WIDTH, WIDTH+SIZE.y, WIDTH)/2)

  sh_band = _so.ShCompound((
    (_band_side, _so.trans(_vec2(-SIZE.x-WIDTH, -SIZE.y)/2)),
    (_band_side, _so.trans(_vec2( SIZE.x+WIDTH, -SIZE.y)/2)),
    (_band_back, _so.trans(_vec2(0, -2*SIZE.y-WIDTH)/2)),
    ))
  sh_plexi = _so.ShCompound((
    (_plexi_side,   _so.trans(_vec3(-SIZE.x-WIDTH, -SIZE.y, 0)/2)),
    (_plexi_side,   _so.trans(_vec3( SIZE.x+WIDTH, -SIZE.y, 0)/2)),
    (_plexi_back,   _so.trans(_vec3(0, -2*SIZE.y-WIDTH, 0)/2)),
    (_plexi_front,  _so.trans(_vec3(0, -WIDTH, -0.040)/2)),
    (_plexi_bottom, _so.trans(_vec3(0, -SIZE.y-WIDTH, -HEIGHT)/2)),
    ))

  def __init__(self, team):
    if team == 0:
      xy0 = self.XY0
    elif team == 1:
      xy0 = self.XY0 * _vec2(-1,1)
    else:
      raise ValueError("invalid team")
    self.team = int(team)

    ob = _so.OSimple(self.sh_band)
    ob.pos = _vec3(0,0, WALL_HEIGHT/2) + xy0
    ob.color = TEAM_COLORS[self.team]

    op = _so.OSimple(self.sh_plexi)
    op.pos = _vec3(0,0, -self.HEIGHT/2) + xy0
    op.color = _so.Color.plexi

    self.band = ob
    self.plexi = op

  def contains(self, o):
    """Return True if the object is in the bac.
    Test is based on object's center of mass position.
    """
    d = abs(o.pos - self.plexi.pos)
    return d.x < self.SIZE.x and d.y < self.SIZE.y and d.z < self.HEIGHT

  def addToWorld(self, ph):
    self.band.addToWorld(ph)
    self.plexi.addToWorld(ph)

  def removeFromWorld(self):
    self.band.removeFromWorld()
    self.plexi.removeFromWorld()
Beispiel #14
0
    def prepare(self, fconf=None):
        if fconf is None:
            self.conf = self.Conf.random()
        else:
            self.conf = self.Conf(*fconf)

        ph = self.physics

        # Ground
        ground = OGround()
        ground.addToWorld(ph)
        self.ground = ground

        # Walls (N, S, E, W)
        color = _eb.RAL[9017]
        sh = _so.ShBox(
            _vec3(TABLE_SIZE.x + WALL_WIDTH, WALL_WIDTH, WALL_HEIGHT) / 2)
        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(0, TABLE_SIZE.y + WALL_WIDTH, WALL_HEIGHT) / 2
        o.color = color

        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(0, -TABLE_SIZE.y - WALL_WIDTH, WALL_HEIGHT) / 2
        o.color = color

        sh = _so.ShBox(
            _vec3(WALL_WIDTH, TABLE_SIZE.y + 2 * WALL_WIDTH, WALL_HEIGHT) / 2)
        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(TABLE_SIZE.x + WALL_WIDTH, 0, WALL_HEIGHT) / 2
        o.color = color

        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(-TABLE_SIZE.x - WALL_WIDTH, 0, WALL_HEIGHT) / 2
        o.color = color

        # Starting areas, inside borders
        sh = _so.ShBox(_vec3(ground.start_size, WALL_WIDTH, WALL_HEIGHT) / 2)
        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(-TABLE_SIZE.x + ground.start_size, TABLE_SIZE.y -
                      WALL_WIDTH - 2 * ground.start_size, WALL_HEIGHT) / 2
        o.color = TEAM_COLORS[0]
        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(TABLE_SIZE.x - ground.start_size, TABLE_SIZE.y -
                      WALL_WIDTH - 2 * ground.start_size, WALL_HEIGHT) / 2
        o.color = TEAM_COLORS[1]

        # Secured zones, borders (centered on surrounded squares)
        sh_wall = _so.ShBox(_vec3(WALL_WIDTH, 0.150, WALL_HEIGHT) / 2)
        sh_block = _so.ShBox(_vec3(0.700, 0.120, WALL_HEIGHT) / 2)
        sh = _so.ShCompound((
            (sh_wall, _so.trans(_vec2(-SQUARE_SIZE + WALL_WIDTH / 2))),
            (sh_wall, _so.trans(_vec2(SQUARE_SIZE - WALL_WIDTH / 2))),
            (sh_block, _so.trans(_vec2(0, (-SQUARE_SIZE + 0.120) / 2))),
        ))
        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(-2 * SQUARE_SIZE, -2.5 * SQUARE_SIZE, WALL_HEIGHT / 2)
        o.color = color
        o = _so.OSimple(sh)
        o.addToWorld(ph)
        o.pos = _vec3(2 * SQUARE_SIZE, -2.5 * SQUARE_SIZE, WALL_HEIGHT / 2)
        o.color = color

        # Pawns on the field

        self.pawns = [self.addPiece(0, 0)]
        for j in RANDOM_POS[self.conf.line1]:
            y = (j - 2) * SQUARE_SIZE
            self.pawns.append(self.addPiece(-2 * SQUARE_SIZE, y))
            self.pawns.append(self.addPiece(2 * SQUARE_SIZE, y))
        for j in RANDOM_POS[self.conf.line2]:
            y = (j - 2) * SQUARE_SIZE
            self.pawns.append(self.addPiece(-1 * SQUARE_SIZE, y))
            self.pawns.append(self.addPiece(1 * SQUARE_SIZE, y))

        # Pieces in dispensing zones

        pos_king, pos_queen = RANDOM_POS[self.conf.kingqueen]
        x = (TABLE_SIZE.x - ground.start_size) / 2
        for j in range(5):
            y = -TABLE_SIZE.y / 2 + (5 - j) * DISPENSING_DY
            if j == pos_king:
                self.kings = (self.addPiece(-x, y,
                                            OKing), self.addPiece(x, y, OKing))
            elif j == pos_queen:
                self.queens = (self.addPiece(-x, y, OQueen),
                               self.addPiece(x, y, OQueen))
            else:
                self.pawns.append(self.addPiece(-x, y))
                self.pawns.append(self.addPiece(x, y))
Beispiel #15
0
class OQueen(OPawn):
    _sh_figure = _so.ShSphere(0.16 / 2)
    _shape = _so.ShCompound(
        ((OPawn._shape, _so.trans()), (_sh_figure,
                                       _so.trans(_vec3(z=0.16 / 2 - 0.02)))))
    _mass = 0.5  # 300g to 700g
Beispiel #16
0
 def add_candle(r, z, a, color):
   o = OCandle()
   o.addToWorld(ph)
   o.color = color
   x, y = r*_math.cos(-_math.pi/2 + a), r*_math.sin(-_math.pi/2 + a)
   o.pos = _vec3(x, y+TABLE_SIZE.y/2, z+OCandle.HEIGHT/2)
Beispiel #17
0
  def prepare(self, fconf=None):
    if fconf is None:
      self.conf = self.Conf.random()
    else:
      self.conf = self.Conf(*fconf)

    ph = self.physics

    # Ground
    ground = OGround()
    ground.addToWorld(ph)
    self.ground = ground

    # Walls (N, E, W, S, small SE, small SW, plexi S)
    sh = _so.ShBox(_vec3(TABLE_SIZE.x+2*WALL_WIDTH, WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, TABLE_SIZE.y+WALL_WIDTH, WALL_HEIGHT)/2
    o.color = _so.Color.white
    sh = _so.ShBox(_vec3(WALL_WIDTH, TABLE_SIZE.y+2*WALL_WIDTH, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(TABLE_SIZE.x+WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = _so.Color.white
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-TABLE_SIZE.x-WALL_WIDTH, 0, WALL_HEIGHT)/2
    o.color = _so.Color.white

    sh = _so.ShBox(_vec3(WALL_WIDTH, 0.100, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(1.800+WALL_WIDTH, -TABLE_SIZE.y+0.100, WALL_HEIGHT)/2
    o.color = _so.Color.white
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-1.800-WALL_WIDTH, -TABLE_SIZE.y+0.100, WALL_HEIGHT)/2
    o.color = _so.Color.white

    sh = _so.ShBox(_vec3(1.800+WALL_WIDTH, ph.margin_epsilon, 0.250)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, -TABLE_SIZE.y/2, 0.125)
    o.color = _so.Color.plexi
    sh = _so.ShBox(_vec3(0.578+WALL_WIDTH, ph.margin_epsilon, WALL_HEIGHT)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(2.400, -TABLE_SIZE.y, WALL_HEIGHT)/2
    o.color = _so.Color.plexi
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(-2.400, -TABLE_SIZE.y, WALL_HEIGHT)/2
    o.color = _so.Color.plexi


    # Building areas
    sh = _so.ShBox(_vec3(1.800, 0.100, ph.margin_epsilon)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, 0.050-TABLE_SIZE.y/2, ph.margin_epsilon)
    o.color = _eb.RAL[8017]

    sh = _so.ShBox(_vec3(0.600, 0.100, 0.030)/2)
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, 0.050-TABLE_SIZE.y/2, 0.015)
    o.color = _eb.RAL[8017]

    sh = _so.ShCylinderZ(_vec3(0.150, 0.150, 0.060/2))
    o = _so.OSimple(sh)
    o.addToWorld(ph)
    o.pos = _vec3(0, 0, 0.030)
    o.color = _eb.RAL[8017]


    # Random column elements
    for j in COL_POS[self.conf.col]:
      # first team
      o = OColElem()
      o.addToWorld(ph)
      o.color = TEAM_COLORS[0]
      o.pos = COL_SPACE_XY * _vec2(j%3-2, 3-j//3) - COL_OFFSET_XY
      o = OColElem()
      o.addToWorld(ph)
      o.color = TEAM_COLORS[0]
      o.pos = COL_SPACE_XY * _vec2(j%3-2, j//3) - COL_OFFSET_XY
      # second team
      o = OColElem()
      o.addToWorld(ph)
      o.color = TEAM_COLORS[1]
      o.pos = (COL_SPACE_XY * _vec2(j%3-2, 3-j//3) - COL_OFFSET_XY)*_vec2(-1,1)
      o = OColElem()
      o.addToWorld(ph)
      o.color = TEAM_COLORS[1]
      o.pos = (COL_SPACE_XY * _vec2(j%3-2, j//3) - COL_OFFSET_XY)*_vec2(-1,1)


    # Dispensers

    # Fixed
    od = ODispenser()
    od.addToWorld(ph)
    od.setPos( DISP_OFFSET*_vec3(-1,0,1) - TABLE_SIZE/2*_vec2(-1,1), 2 )
    for i in range(4):
      o = OColElem()
      o.addToWorld(ph)
      o.color = TEAM_COLORS[0]
      od.fill(o, (i+1)*0.035)
    od = ODispenser()
    od.addToWorld(ph)
    od.setPos( DISP_OFFSET*_vec3(1,0,1) - TABLE_SIZE/2, 2 )
    for i in range(4):
      o = OColElem()
      o.addToWorld(ph)
      o.color = TEAM_COLORS[1]
      od.fill(o, (i+1)*0.035)

    # Random
    ky = 1 if self.conf.disp == 0 else -1
    od = ODispenser()
    od.addToWorld(ph)
    od.setPos( _vec3(TABLE_SIZE.x-WALL_WIDTH, DISP_OFFSET.y, DISP_OFFSET.z)*_vec3(.5,ky,1), 1 )
    for i in range(4):
      o = OColElem()
      o.addToWorld(ph)
      o.color = TEAM_COLORS[0]
      od.fill(o, (i+1)*0.035)
    od = ODispenser()
    od.addToWorld(ph)
    od.setPos( _vec3(TABLE_SIZE.x-WALL_WIDTH, DISP_OFFSET.y, DISP_OFFSET.z)*_vec3(-.5,ky,1), 3 )
    for i in range(4):
      o = OColElem()
      o.addToWorld(ph)
      o.color = TEAM_COLORS[1]
      od.fill(o, (i+1)*0.035)


    # Lintels and lintel storages
    ols = OLintelStorage()
    ols.addToWorld(ph)
    ols.setPos(-0.200, 0)
    ol = OLintel()
    ol.addToWorld(ph)
    ol.color = TEAM_COLORS[0]
    ols.fill(ol)

    ols = OLintelStorage()
    ols.addToWorld(ph)
    ols.setPos(-0.600, 0)
    ol = OLintel()
    ol.addToWorld(ph)
    ol.color = TEAM_COLORS[0]
    ols.fill(ol)

    ols = OLintelStorage()
    ols.addToWorld(ph)
    ols.setPos(0.200, 0)
    ol = OLintel()
    ol.addToWorld(ph)
    ol.color = TEAM_COLORS[1]
    ols.fill(ol)

    ols = OLintelStorage()
    ols.addToWorld(ph)
    ols.setPos(0.600, 0)
    ol = OLintel()
    ol.addToWorld(ph)
    ol.color = TEAM_COLORS[1]
    ols.fill(ol)