Beispiel #1
0
def create_walker(event,x,y,flags,param):
    global drawing

    if event == cv2.EVENT_LBUTTONDOWN :
        drawing = True
        #walkers.append(Walker.Walker(x,y,[255,0,0],img.shape[0],img.shape[1]))
        walkers.append(Walker.Walker(x,y,[255,0,0],img[y][x],img.shape[0],img.shape[1]))
    if event == cv2.EVENT_MOUSEMOVE:
        if drawing == True:
            walkers.append(Walker.Walker(x,y,[255,0,0],img[y][x],img.shape[0],img.shape[1]))
    if event == cv2.EVENT_LBUTTONUP:
        drawing = False
Beispiel #2
0
    def act(self,i, j, evento):
        pos = evento.pos
        if(evento.button == 1):
            if(self.grid[i][j].selecionado):
                if(self.grid[i][j].ataques > 0):
                    try:
                        click = self.findclick(pos)
                        dis = self.distance(i,j,click)
                    except: pass
                    if(click and dis == 1):
                        try:
                            if( isinstance(self.grid[click[0]][click[1]], Sobrevivente) ):
                                self.meleeHit(i, j, click[0], click[1], self.grid[i][j].dano)
                        except: pass

                if(self.grid[i][j].movimentos > 0):
                    self.move(i,j, pos)
        if(evento.button == 3):
            if(self.grid[i][j].selecionado):
                if(self.grid[i][j].pontos > 0):
                    try:
                        click = self.findclick(pos)
                        dis = self.distance(i,j,click)
                    except: pass
                    if(click and dis == 1):
                        self.area.spawn_sound.play()
                        self.area.addZombie( Walker(self.area, image.load("./Assets/Zumbis/Walker.png"), "Walker"), click[0], click[1])
                        self.grid[i][j].pontos -= 2
Beispiel #3
0
def breed():

    # Select parent from the this generation
    selected_parents = select()

    # Add them to new generation
    new_generation = selected_parents[:]

    # Shuffle it to keep the variety of population
    shuffle(selected_parents)

    # Let them cross over to create 1 child each couple
    # The 1/4 population remain will be generate randomly
    children = []
    for i in range(0, len(selected_parents), 2):
        children += selected_parents[i].cross_over(selected_parents[i + 1])
        new_generation.append(Gen(life_time.get()))

    # Let the children mutate
    mutation(children)

    # Add children to new generation
    new_generation += children

    # Clear out the population
    walkers.clear()

    # Create new population from the selected gens
    for i in range(len(new_generation)):
        walkers.append(
            Walker(map_blocks, map_blocks[start_point[0]][start_point[1]],
                   new_generation[i], game_canvas))

    # Track the best walker
    walkers[0].best = True
Beispiel #4
0
def uncompyle(version, co, out=None, showasm=0, showast=0):
    """
    diassembles a given code block 'co'
    """
    assert type(co) == types.CodeType

    # store final output stream for case of error
    __real_out = out or sys.stdout
    if co.co_filename:
        print >> __real_out, '#Embedded file name: %s' % co.co_filename

# diff scanner
    if version == 2.7:
        import Scanner27 as scan
    elif version == 2.6:
        import Scanner26 as scan
    elif version == 2.5:
        import Scanner25 as scan

    scanner = scan.Scanner(version)
    scanner.setShowAsm(showasm, out)
    tokens, customize = scanner.disassemble(co)

    #sys.exit(0)
    #  Build AST from disassembly.
    walker = Walker.Walker(out, scanner, showast=showast)
    try:
        ast = walker.build_ast(tokens, customize)
    except Walker.ParserError, e:  # parser failed, dump disassembly
        print >> __real_out, e
        raise
Beispiel #5
0
def do_run(filename, compressions=10000):
	walker = Walker()
	walker.initialise()
	print(walker.direction)

	plt.ion()
	plt.hold(False)
	for i in xrange(0, compressions):
		success = walker.advance()

		walker.point.plot_state(i, walker.direction)
		plt.draw()

		if success is False:
			break

	import cPickle as pickle
	pickle.dump(walker, open(filename, 'wb'))
def decompyle(version, co, out=None, showasm=0, showast=0):
    assert type(co) == types.CodeType
    __real_out = out or sys.stdout
    scanner = Scanner.getscanner(version)
    scanner.setShowAsm(showasm, out)
    tokens, customize = scanner.disassemble(co)
    walker = Walker.Walker(out, scanner, showast=showast)
    try:
        ast = walker.build_ast(tokens, customize)
    except Walker.ParserError, e:
        print >> __real_out, e
        raise
Beispiel #7
0
def demo():
    print "Walker Animation Demo"
    if not yesno(): return
    print "Silly Walk"
    w = W.Walker()
    SillyWalk(w)
    if not yesno(): return
    w = W.Walker()
    print "Simple Walk, gamma=0.009"
    SimpleWalk(w, gamma=0.009)
    if not yesno(): return
    print "Simple Walk, gamma=0.012"
    SimpleWalk(w, gamma=0.012)
    if not yesno(): return
    print "Simple Walk, gamma=0.015"
    SimpleWalk(w, gamma=0.015)
    if not yesno(): return
    print "Simple Walk, gamma=0.017"
    SimpleWalk(w, gamma=0.017)
    if not yesno(): return
    print "Simple Walk, gamma=0.020"
    SimpleWalk(w, gamma=0.020)
Beispiel #8
0
def init_population():

    # Randomly create the initial population
    # Size of POPULATION_SIZE
    Walker.block_size = block_size.get()
    Walker.life_time = life_time.get()
    Walker.goal_point = goal_point
    population = []
    for i in range(population_size.get()):
        population.append(
            Walker(map_blocks, map_blocks[start_point[0]][start_point[1]],
                   Gen(life_time.get()), game_canvas))
    return population
Beispiel #9
0
    def __init__(self, number_walkers):

        # Get fractal points that our walkers will move around
        self.fractal_points = fp.getFractalPoints(self.area_side,
                                                  self.area_side,
                                                  self.num_waypoints,
                                                  self.levels)
        self.fractal_clusters = cfp.computeClusters(self.contact_distance,
                                                    self.fractal_points)

        self.number_walkers = number_walkers

        # Make walkers
        self.walkers = w.randomWalkers(self.number_walkers,
                                       self.fractal_clusters,
                                       self.fractal_points, self.speed)

        # Locations of walkers, hasn't been determined yet
        # Once set, the ith entry is the location of the ith walker
        self.locations = []
Beispiel #10
0
def decompyle(version, co, out=None, showasm=0, showast=0):
    """
    diassembles a given code block 'co'
    """
    assert type(co) == types.CodeType

    # store final output stream for case of error
    __real_out = out or sys.stdout

    scanner = Scanner.getscanner(version)
    scanner.setShowAsm(showasm, out)
    tokens, customize = scanner.disassemble(co)

    #  Build AST from disassembly.
    walker = Walker.Walker(out, scanner, showast=showast)
    try:
        ast = walker.build_ast(tokens, customize)
    except Walker.ParserError, e :  # parser failed, dump disassembly
        print >>__real_out, e
        raise
def WalkerAttractor(gamma,
                    theta0=0.235,
                    thetaDot0=-0.23,
                    phi0=0.475,
                    phiDot0=-0.026,
                    numPoints=25,
                    numTransient=25):
    """
    Returns the theta-values on the attractor for a walker run with 
    particular slope "gamma"
    Initial condition theta=0.235,thetaDot=-0.23,phi=0.475,phiDot=-0.026
    was empirically found allow the walker to avoid falling down for 
    gamma in an interesting range (from 0.014 to 0.019).
    (1) Create a walker with the given initial conditions
    (2) Set walker.gamma
    (3) Start an empty list of thetas
    (3) Run for numTransient steps to get onto the attractor 
    	(probably you'll want 50 for gamma > 0.018)
	Presume the time between steps is less than 20 
	(so tnew = w.Step(t, t+20.) will typically give a new step)
	If Step returns a step, remember to execute the heel strike
    (4) Run for numPoints further steps, appending theta after each heel strike
    Return the list of thetas
    """
    w = Walker.Walker(theta=theta0,
                      thetaDot=thetaDot0,
                      phi=phi0,
                      phiDot=phiDot0)
    w.gamma = gamma
    t = 0.
    thetas = []
    for n in range(numTransient + numPoints):
        tnew = w.Step(t, t + 20.)
        if tnew is not None:
            w.ExecuteHeelstrike()
            t = tnew
        else:
            t += 20.
        if n >= numTransient:
            thetas.append(w.theta)
    return thetas
def StanceAngleIntelligentWalker():
    """
    Stance angle theta vs. slope gamma for stable and unstable orbits
    of walker (duplicating figure 3 of Garcia, Chatterjee, Ruina, and Coleman, 
    "The Simplest Walking Model: Stability, Complexity, and Scaling".)
    We discovered through trial and error that the heelstrike condition
    for gamma=0.009, used as an initial condition, put us on one branch
    or the other, depending at whether we started at gamma=0.01 or gamma=0.02.
    We work outward slowly from that initial condition.
    #
    Set up lists of gammas starting from 0.01->0.046, 0.01->0, 0.02->0.046,
    and 0.02->0, with a step size somewhere near 0.003. (Bigger step sizes will
    cause the orbit to get lost.)
    For each list of gammas, 
        make a list of fixed--point thetaStar's
        start the walker in its default state (heelstrike condition for 0.009)
	work outward through the gammas, 
	    use FindPeriodicOrbit to find periodic (theta, thetaDot) for gamma
            set the walker to that pair
	    execute the heel strike
            append theta to thetaStar
        plot thetaStar vs. gammas
    """
    gammalists = [
        Walker.arange(0.01, 0.046, 0.003),
        Walker.arange(0.01, 0.0, -0.0025),
        Walker.arange(0.02, 0.046, 0.00325),
        Walker.arange(0.02, 0.0, -0.0025)
    ]
    for gammas in gammalists:
        thetaStar = []
        w = Walker.Walker()
        for gamma in gammas:
            root_theta, root_thetaDot = \
                        FindPeriodicOrbit(w, gamma, \
                                          -w.theta, \
                                          w.thetaDot/Walker.cos(2.*w.theta))
            w.theta, w.thetaDot = root_theta, root_thetaDot
            w.ExecuteHeelstrike()
            thetaStar.append(w.theta)
        pylab.plot(gammas, thetaStar)
    pylab.show()
Beispiel #13
0
    walker = Walker.Walker(out, scanner, showast=showast)
    try:
        ast = walker.build_ast(tokens, customize)
    except Walker.ParserError, e :  # parser failed, dump disassembly
        print >>__real_out, e
        raise

    del tokens # save memory

    if not showasm and not showast:
        # add a hint for emacs
        print >> out, '# emacs-mode: -*- python-*-'

    # convert leading '__doc__ = "..." into doc string
    assert ast == 'stmts'
    if ast[0] == Walker.ASSIGN_DOC_STRING(co.co_consts[0]):
        walker.print_docstring('', co.co_consts[0])
        del ast[0]
    if ast[-1] == Walker.RETURN_NONE:
        ast.pop() # remove last node
        #todo: if empty, add 'pass'

    walker.gen_source(ast, customize)

    if not showasm and not showast:
        # add another hint for emacs
        print >> out, '# local variables:'
        print >> out, '# tab-width:', TABWIDTH


def decompyle_file(filename, outstream=None, showasm=0, showast=0):
def demo():
    print "Walker Animation Demo"
    w = W.Walker()
    SimpleWalk(w)
Beispiel #15
0
    tokens, customize = scanner.disassemble(co, deob=deob)

    #  Build AST from disassembly.
    walker = Walker.Walker(out, scanner, showast=showast)
    try:
        ast = walker.build_ast(tokens, customize)
    except Walker.ParserError, e:  # parser failed, dump disassembly
        print >> __real_out, e
        raise

    del tokens  # save memory

    # convert leading '__doc__ = "..." into doc string
    assert ast == 'stmts'
    try:
        if ast[0][0] == Walker.ASSIGN_DOC_STRING(co.co_consts[0]):
            walker.print_docstring('', co.co_consts[0])
            del ast[0]
        if ast[-1] == Walker.RETURN_NONE:
            ast.pop()  # remove last node
            #todo: if empty, add 'pass'
    except:
        pass
    walker.mod_globs = Walker.find_globals(ast, set())
    walker.gen_source(ast, customize)
    for g in walker.mod_globs:
        walker.write('global %s ## Warning: Unused global\n' % g)
    if walker.pending_newlines:
        print >> __real_out
    if walker.ERROR:
        raise walker.ERROR
Beispiel #16
0
        raise

    del tokens # save memory

    # convert leading '__doc__ = "..." into doc string
    assert ast == 'stmts'
    try:
        if ast[0][0] == Walker.ASSIGN_DOC_STRING(co.co_consts[0]):
            walker.print_docstring('', co.co_consts[0])
            del ast[0]
        if ast[-1] == Walker.RETURN_NONE:
            ast.pop() # remove last node
            #todo: if empty, add 'pass'
    except:
        pass
    walker.mod_globs = Walker.find_globals(ast, set())
    walker.gen_source(ast, customize)
    for g in walker.mod_globs:
        walker.write('global %s ## Warning: Unused global\n' % g)
    if walker.ERROR:
        raise walker.ERROR

def uncompyle_file(filename, outstream=None, showasm=0, showast=0):
    """
    decompile Python byte-code file (.pyc)
    """
    version, co = _load_module(filename)
    uncompyle(version, co, outstream, showasm, showast)
    co = None

#---- main -------
Beispiel #17
0
        m.compliant = False
        #~ m.torque_limit = 80

    time.sleep(0.5)

    for m in poppy.motors:
        m.goto_position(0.0, 1., wait=False)

    #~ time.sleep(2)
else:
    poppy = None

#~ import Walker4 as Walker
import Walker

walker = Walker.Walker(poppy, razor)

if walker.init():
    walker.startWalk()

    #~ for i in range(0,4):
    while not walker.mustStopWalk():
        walker.oneStep()

    walker.stopWalk()

    walker.clean()

if HAS_REAL_ROBOT:
    time.sleep(0.5)
    for m in poppy.motors: