예제 #1
0
def NeighborChecker(xar, yar, zar, switch):
	""" Check the distance to neighbors, and count the number of neighbors below thdist. """
	global thdist
	neighborA = zeros('d', len(xar))
	if switch:
		for i in range(len(xar)):
			cx = xar[i]
			cy = yar[i]
			cz = zar[i]	 
			for j in range(len(xar)):
				if j != i :
					dist = Math.sqrt( Math.pow((cx - xar[j]), 2) + Math.pow((cy - yar[j]), 2))
					if dist < thdist:
						if Math.abs(cz - zar[j]) < 2:
							logstr = ".... Dot%d - Dot%d too close: dist = %d" % (i, j, dist)
							IJ.log(logstr)
							print logstr
							neighborA[i] += 1
			if neighborA[i] > 0:
				IJ.log("---> Dot%d rejected" % (i))
				print "---> Dot", i, " rejected"
	return neighborA
예제 #2
0
def processEnv():
	if my._direction_ttl:
		my._direction_ttl -= 1
	percepts = self.getPercepts()
	best = None
	rocket = None
	for p in percepts:
		if p.getTeam() != my.getTeam():
			if p.getPerceptType() == 'RocketLauncher': # or i.getPerceptType() == 'Explorer':
				if not best or distance(p.getX(), p.getY()) < distance(best.getX(), best.getY()):
					best = p
			elif p.getPerceptType() == 'Home':
				my.setHome(p.getX(), p.getY())
		if p.getPerceptType() == 'Rocket' or p.getTeam() != my.getTeam():
			if not rocket or distance(p.getX(), p.getY()) < distance(rocket.getX(), rocket.getY()) and Math.abs(self.towards(p.getX(), p.getY()))-Math.abs(self.getHeading()) < 20:
				rocket = p
	if not best:
		return
	my.setTarget(p.getX(), p.getY())
	# évitement des rockets et des mechants !
	if rocket and not my._direction_ttl:
		self.setHeading(self.towards(rocket.getX(), rocket.getY())+120)
		my._direction_ttl = 30
예제 #3
0
        def isZero(self, value):
	    import java.lang.Math as Math
            return Math.abs(value) < 0.0001