Beispiel #1
0
    def __init__(self, bzrTank, game, color):
        self.field = FieldManager()
        self.field.addField("world", game.fields)
        flagPos = game.teams[color].flagPosition
        self.goalField = GoalField(flagPos.real, flagPos.imag)
        self.field.addField("flag", self.goalField)

        super(CaptureFlagTank, self).__init__(bzrTank, self.field)
        self.game = game
        self.targetColor = color
Beispiel #2
0
    def __init__(self, socket):
        self.socket = socket
        self.obstacles = []
        self.points = []
        self.fields = FieldManager()
        self.mycolor = None

        self.teams = {}
        # 'color' : BZRTeam object

        #Build Obstacles
        self.buildTeams()
        self.buildConstants()
        self.buildObstacles()
	def __init__(self, bzrTank, game, color):
		self.field = FieldManager()
		self.field.addField("world", game.fields)
		flagPos = game.teams[color].flagPosition
		self.goalField = GoalField(flagPos.real, flagPos.imag)
		self.field.addField("flag", self.goalField)

		super(CaptureFlagTank,self).__init__(bzrTank, self.field)
		self.game = game
		self.targetColor = color
Beispiel #4
0
	def __init__(self, socket):
		self.socket = socket
		self.obstacles = []
		self.points = []
		self.fields = FieldManager()
		self.mycolor = None

		self.teams = {}
			# 'color' : BZRTeam object

		#Build Obstacles
		self.buildTeams()
		self.buildConstants()
		self.buildObstacles()
Beispiel #5
0
class CaptureFlagTank(FieldFollowTank):
    def __init__(self, bzrTank, game, color):
        self.field = FieldManager()
        self.field.addField("world", game.fields)
        flagPos = game.teams[color].flagPosition
        self.goalField = GoalField(flagPos.real, flagPos.imag)
        self.field.addField("flag", self.goalField)

        super(CaptureFlagTank, self).__init__(bzrTank, self.field)
        self.game = game
        self.targetColor = color

    def update(self):
        if self.bzrTank.flag == '-':
            flagPos = self.game.teams[self.targetColor].flagPosition
            self.goalField.x = flagPos.real
            self.goalField.y = flagPos.imag
        else:
            homePos = self.game.teams[self.game.mycolor].basePosition
            self.goalField.x = homePos.real
            self.goalField.y = homePos.imag

        super(CaptureFlagTank, self).update()
class CaptureFlagTank(FieldFollowTank):
	def __init__(self, bzrTank, game, color):
		self.field = FieldManager()
		self.field.addField("world", game.fields)
		flagPos = game.teams[color].flagPosition
		self.goalField = GoalField(flagPos.real, flagPos.imag)
		self.field.addField("flag", self.goalField)

		super(CaptureFlagTank,self).__init__(bzrTank, self.field)
		self.game = game
		self.targetColor = color


	def update(self):
		if self.bzrTank.flag == '-':
			flagPos = self.game.teams[self.targetColor].flagPosition
			self.goalField.x = flagPos.real
			self.goalField.y = flagPos.imag
		else:
			homePos = self.game.teams[self.game.mycolor].basePosition
			self.goalField.x = homePos.real
			self.goalField.y = homePos.imag

		super(CaptureFlagTank,self).update()
Beispiel #7
0
def main():

    Temp.allFields = FieldManager()
    flagField = GoalField(200, 200)
    avoidField2 = RepulsionField(-200, -300)
    Temp.allFields.addField("flag", flagField)
    Temp.allFields.addField("avoid3", avoidField2)

    triangle = ((0, 0), (100, 100), (-100, 50))
    square = ((100, -100), (200, -100), (200, -200), (100, -200))

    obstacles = [triangle, square]
    for o in obstacles:
        obstacle = ObstacleField(o)
        Temp.allFields.addField("%d, %d" % (obstacle.x, obstacle.y), obstacle)


#         for ob in o:
#             Temp.allFields.addField("%d, %d" % (ob[0], ob[1]), PotentialField.TangentField(ob[0], ob[1], 50))

    plot_single(fields, obstacles, 'fields.png')
Beispiel #8
0
class BZRGame(object):
	def __init__(self, socket):
		self.socket = socket
		self.obstacles = []
		self.points = []
		self.fields = FieldManager()
		self.mycolor = None

		self.teams = {}
			# 'color' : BZRTeam object

		#Build Obstacles
		self.buildTeams()
		self.buildConstants()
		self.buildObstacles()

	def buildObstacles(self):
		obstacleResponse = self.socket.issueCommand("obstacles")

		for rl in obstacleResponse:
			x = -1
			y = -1
			points = []
			for param in rl.parameters:
				if(x == -1):
					x = float(param)
				elif(y == -1):
					y = float(param)
					points.append((x, y))
					x = -1
					y = -1

			obstacle = ObstacleField(points)

			self.fields.addField("ObstacleField (%d, %d)" % (obstacle.x, obstacle.y), obstacle)
			self.obstacles.append(obstacle)
			self.points.append(points)
			points = []

		return self.obstacles

	def buildTeams(self):
		teamsResponse = self.socket.issueCommand("bases")

		for res in teamsResponse:
			team = BZRTeam()
			team.color = res.parameters[0]
			team.basePosition = complex(float(res.parameters[1]), float(res.parameters[2]))
			self.teams[team.color] = team

		otherTankResponse = self.socket.issueCommand("othertanks")
		for res in otherTankResponse:
			team = self.teams[res.parameters[1]]
			team.tanks[res.parameters[0]] = BZREnemyTank()
			team.tanks[res.parameters[0]].updateParameters(res)

		self.enemyTeamColors = self.teams.keys()
			

	def updateTeams(self):
		flagsResponse = self.socket.issueCommand("flags")


		for res in flagsResponse:
			#color, possesing, positionx, positiony
			team = self.teams[res.parameters[0]]
			team.flagPosition = complex(float(res.parameters[2]), float(res.parameters[3]))
			team.flagCarriedBy = res.parameters[1]

		otherTankResponse = self.socket.issueCommand("othertanks")
		
		for res in otherTankResponse:
			team = self.teams[res.parameters[1]]
			tank = team.tanks[res.parameters[0]]
			tank.updateParameters(res)
			tankField = TankField(tank.position.real, tank.position.imag)
			self.fields.addField("enemy_tank_%s" % (res.parameters[0]), tankField)

	def buildConstants(self):
		constants = self.socket.issueCommand("constants")

		for i in xrange(len(constants)):
			if(i == 0):
				self.mycolor = constants[i].parameters[1]
				break

		self.enemyTeamColors.remove(self.mycolor)

	def update(self):
		self.updateShots()
		self.updateTeams()

	def updateShots(self):
		#shot 242.490422334 77.1400313101 78.5985078261 61.8245466422
		#shot x y origin_x origin_y
		shotResponse = self.socket.issueCommand("shots")

		#remove all shots fields
		self.fields.removeShotFields()

		shotNum = 0
		for shot in shotResponse:
			if shot.response == 'shot':
				shotField = ShotField(float(shot.parameters[0]), float(shot.parameters[1]))
				self.fields.addField("shot_%d" % (shotNum, ), shotField)
				shotNum+=1
Beispiel #9
0
class BZRGame(object):
    def __init__(self, socket):
        self.socket = socket
        self.obstacles = []
        self.points = []
        self.fields = FieldManager()
        self.mycolor = None

        self.teams = {}
        # 'color' : BZRTeam object

        #Build Obstacles
        self.buildTeams()
        self.buildConstants()
        self.buildObstacles()

    def buildObstacles(self):
        obstacleResponse = self.socket.issueCommand("obstacles")

        for rl in obstacleResponse:
            x = -1
            y = -1
            points = []
            for param in rl.parameters:
                if (x == -1):
                    x = float(param)
                elif (y == -1):
                    y = float(param)
                    points.append((x, y))
                    x = -1
                    y = -1

            obstacle = ObstacleField(points)

            self.fields.addField(
                "ObstacleField (%d, %d)" % (obstacle.x, obstacle.y), obstacle)
            self.obstacles.append(obstacle)
            self.points.append(points)
            points = []

        return self.obstacles

    def buildTeams(self):
        teamsResponse = self.socket.issueCommand("bases")

        for res in teamsResponse:
            team = BZRTeam()
            team.color = res.parameters[0]
            team.basePosition = complex(float(res.parameters[1]),
                                        float(res.parameters[2]))
            self.teams[team.color] = team

        otherTankResponse = self.socket.issueCommand("othertanks")
        for res in otherTankResponse:
            team = self.teams[res.parameters[1]]
            team.tanks[res.parameters[0]] = BZREnemyTank()
            team.tanks[res.parameters[0]].updateParameters(res)

        self.enemyTeamColors = self.teams.keys()

    def updateTeams(self):
        flagsResponse = self.socket.issueCommand("flags")

        for res in flagsResponse:
            #color, possesing, positionx, positiony
            team = self.teams[res.parameters[0]]
            team.flagPosition = complex(float(res.parameters[2]),
                                        float(res.parameters[3]))
            team.flagCarriedBy = res.parameters[1]

        otherTankResponse = self.socket.issueCommand("othertanks")

        for res in otherTankResponse:
            team = self.teams[res.parameters[1]]
            tank = team.tanks[res.parameters[0]]
            tank.updateParameters(res)
            tankField = TankField(tank.position.real, tank.position.imag)
            self.fields.addField("enemy_tank_%s" % (res.parameters[0]),
                                 tankField)

    def buildConstants(self):
        constants = self.socket.issueCommand("constants")

        for i in xrange(len(constants)):
            if (i == 0):
                self.mycolor = constants[i].parameters[1]
                break

        self.enemyTeamColors.remove(self.mycolor)

    def update(self):
        self.updateShots()
        self.updateTeams()

    def updateShots(self):
        #shot 242.490422334 77.1400313101 78.5985078261 61.8245466422
        #shot x y origin_x origin_y
        shotResponse = self.socket.issueCommand("shots")

        #remove all shots fields
        self.fields.removeShotFields()

        shotNum = 0
        for shot in shotResponse:
            if shot.response == 'shot':
                shotField = ShotField(float(shot.parameters[0]),
                                      float(shot.parameters[1]))
                self.fields.addField("shot_%d" % (shotNum, ), shotField)
                shotNum += 1