コード例 #1
0
 def move(self, move):
     array = copy.deepcopy(self.state)
     x, y = self.getBlankPosition()
     if (move == Direction(1)):
         array[x][y], array[x - 1][y] = array[x - 1][y], array[x][y]
     if (move == Direction(2)):
         array[x][y], array[x + 1][y] = array[x + 1][y], array[x][y]
     if (move == Direction(3)):
         array[x][y - 1], array[x][y] = array[x][y], array[x][y - 1]
     if (move == Direction(4)):
         array[x][y + 1], array[x][y] = array[x][y], array[x][y + 1]
     return array
コード例 #2
0
 def __init__(self, start, target, strategy):
     self.target = target
     self.start = Base(None, start, Direction(5), 0)
     self.strategy = strategy
     self.maxDepth = 0
     if (self.start.state != self.target):
         self.frontier.put(self.start.state)
         self.explored[str(self.start.state)] = self.start
コード例 #3
0
 def __init__(self, x, y, dir=None):
     direction = Direction()
     self.point = Point()
     self.point.x, self.point.y = x, y
     self.g = 0
     self.h = 0
     self.parent = None
     if (dir == None):
         self.step_direction = direction.start
     else:
         self.step_direction = dir
コード例 #4
0
def verifyGetNextDirection():
    #start with base class
    #check value after two calls to the function
    d = Direction()
    testGetNextDirection(d, 1, "Direction()")
    testGetNextDirection(d, 2, "Direction()")

    #verify with subclass
    #RightDirection sets currentDirection = 1
    d = RightDirection()
    testGetNextDirection(d, 2, "RightDirection()")
    testGetNextDirection(d, 3, "RightDirection()")
コード例 #5
0
 def getValidMoves(self):
     x, y = self.getBlankPosition()
     rows = len(self.state)
     cols = len(self.state[0])
     moves = []
     if (x > 0 and self.lastMove != Direction(2)):
         moves.append(Direction(1))
     if ((x < (rows - 1)) and self.lastMove != Direction(1)):
         moves.append(Direction(2))
     if (y > 0 and self.lastMove != Direction(4)):
         moves.append(Direction(3))
     if ((y < (cols - 1)) and self.lastMove != Direction(3)):
         moves.append(Direction(4))
     return moves
コード例 #6
0
 def __init__(self, size, mappy):
     """
     Initialize the Snake
     :param size The size of the Snake
     :param mappy A map
     """
     self.mappy = mappy
     self.direction = Direction()
     self.direction.direction = 0
     self.size = size
     self.speed = 1
     self.positions = []
     self.__generate__()
コード例 #7
0
 def __init__(self, start, target, strategy):
     self.target = target
     self.strategy = strategy
     self.start = Base(None, start, Direction(5), 0)
     self.maxDepth = 0
     self.rows = len(start)
     self.columns = len(start[0])
     if (self.start.state != self.target):
         if (self.strategy == 'manh'):
             distance = self.Manhattan(self.start.state)
         elif (self.strategy == 'hamm'):
             distance = self.Hamming(self.start.state)
         self.frontier.setdefault(distance, []).append(self.start.state)
         self.explored[str(self.start.state)] = self.start
コード例 #8
0
 def __init__(self, ns, name, direction):
     Parameterization.__init__(self, ns, name)
     if isinstance(direction, Direction):
         self.direction = direction
     else:
         if not isinstance(direction, (list, tuple)) or len(direction) != 2:
             raise TypeError, "direction: Direction object or (ra,dec) tuple expected"
         ra, dec = direction
         self.direction = Direction(ns, name, ra, dec)
     # If the source uses station decomposition (i.e. if the sqrt_visibilities() method has been called),
     # this will be set to True.
     self.using_station_decomposition = False
     # if source should include a time/bandwidth smearing correction, this will be true
     self.smearing = False
     # user-defined attributes. May be used for anything.
     self.attrs = {}
コード例 #9
0
 def __init__(self,
              ns,
              circular=False,
              linear=False,
              phase_centre=None,
              quals=[],
              kwquals={}):
     """Creates an Observation object.
 If phase_centre is known and static, it may be passed in here
 """
     self.ns = ns
     if circular and linear:
         raise ValueError, "either circular=True or linerar=True must be specified, not both"
     self._circular = circular
     self._quals = quals
     self._kwquals = kwquals
     self.phase_centre = self.phase_center = \
         Direction(ns,None,static=bool(phase_centre),quals=quals,kwquals=kwquals,*(phase_centre or (0,0)))
コード例 #10
0
def pixel_to_hex(x, y):
    q = (x * sqrt(3)/3 - y / 3) / size
    r = y * 2/3 / size
    return hex_round(Direction(q, r))
コード例 #11
0
 Topologie(5,"Vapor pool",(255,255,255,0.50)),
 Topologie(4,"Rise",(146,109,39,0.50)),
 Topologie(7,"Cliffside",(255,206,154,0.50)),
 Topologie(8,"Mesa-Top",(240,195,0,0.50)),
 Topologie(9,"Crater",(0,0,0,0.50))]

Scenario=Scenario(DISPLAY)
UniteLegionnaire= [Legionnaire_Trouper(1)]
def evenr_offset_to_pixel(direction):
    x = size * sqrt(3) * (direction.q - 0.5 * (direction.r&1))
    y = size * 3/2 * direction.r
    return Point(x, y)

for q in range(0,12):
    for r in range(0,14):
        hexagones.append(Hexagone(evenr_offset_to_pixel(Direction(q,r)),listetopo[random.randint(0,8)]))

grid = Grid(hexagones)
grid.display()

while True:
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                Mouse_x, Mouse_y = pygame.mouse.get_pos()
                print(" CLICK ")
                print(Mouse_x)
                print(Mouse_y)
                grid.setSelectedHexagon(Mouse_x,Mouse_y)
                grid.display()
            elif event.type == pygame.MOUSEBUTTONUP:
                print(" CLICK UP")