예제 #1
0
    def __init__(self, bzrc):
        self.bzrc = bzrc
        self.constants = self.bzrc.get_constants()
        self.shotspeed = int(self.constants['shotspeed'])
        # {'shotspeed': '100', 'tankalive': 'alive', 'truepositive': '1', 'worldsize': '800', 'explodetime': '5', 'truenegative': '1', 'shotrange': '350', 'flagradius': '2.5', 'tankdead': 'dead', 'tankspeed': '25', 'shotradius': '0.5', 'tankangvel': '0.785398163397', 'linearaccel': '0.5', 'team': 'purple', 'tankradius': '4.32', 'angularaccel': '0.5', 'tankwidth': '2.8', 'tanklength': '6'}
        # self.obstacles = self.bzrc.get_obstacles()
        self.bases = self.bzrc.get_bases()
        self.commands = []
        self.mytanks = {
            tank.callsign: tank
            for tank in self.bzrc.get_mytanks()
        }
        self.othertanks = {
            tank.callsign: tank
            for tank in self.bzrc.get_othertanks()
        }
        self.setup_common_potential_fields()

        self.kalmantanks = {
            tank.callsign: KalmanTank(tank)
            for tank in self.bzrc.get_othertanks()
        }
        self.lines = {}

        fig = plt.figure()
        axis = plt.axes(xlim=(-400, 400), ylim=(-400, 400))

        for callsign, tank in self.othertanks.iteritems():
            self.lines[callsign] = axis.plot([], [], lw=1)[0]
            # add another line for the Kalman line
            self.lines[callsign + "kalman"] = axis.plot([], [], lw=1)[0]
            self.lines[callsign + "estimate"] = axis.plot([], [], lw=2)[0]

        for callsign, tank in self.mytanks.iteritems():
            self.mytanks[callsign].role = None
            self.mytanks[callsign].field = None
            self.mytanks[callsign].goal = None

        self.get_mycolor()
        for base in self.bases:
            if base.color == self.color:
                x = base.corner1_x + base.corner2_x + base.corner3_x + base.corner4_x
                y = base.corner1_y + base.corner2_y + base.corner3_y + base.corner4_y
                x = x / 4.0
                y = y / 4.0
                self.fields['base'] = GoalField(x, y, 15, 70, 0.15)
            else:
                continue

        anim = animation.FuncAnimation(fig,
                                       self.tick,
                                       init_func=self.init_graph,
                                       interval=1000 * FIXED_TIME_STEP,
                                       blit=True)
        plt.show()
예제 #2
0
    def scout(self, tank):
        no_points = False
        # check to see if we've made it to our scout point
        if tank.field != None and \
            tank.field.x + self.vision_range > tank.x and tank.field.x - self.vision_range < tank.x and \
            tank.field.y + self.vision_range > tank.y and tank.field.y - self.vision_range < tank.y:
            print "Made it to the point"
            tank.field = None
        elif tank.field != None:
            if self.grid[tank.field.y - 400][tank.field.x - 400] == 0 or \
                self.grid[tank.field.y - 400][tank.field.x - 400] == 1:
                print "Point is already discovered"
                tank.field = None
        # if we don't have a field, lets get one unless there are none to get
        if tank.field == None:
            if len(self.fields['scout_points']) > 0:
                if tank.index == 0:
                    r = 0
                elif tank.index == 1:
                    r = -1
                else:
                    r = randint(0, len(self.fields['scout_points']) - 1)
                point = self.fields['scout_points'][r]
                print "Assigning point: %d,%d" % (point.x, point.y)
                tank.field = GoalField(point.x, point.y, 25, 75, 0.15)
                del self.fields['scout_points'][r]
            else:
                no_points = True
        if no_points:
            # we have searched all the base points, now we need to see where we haven't fulled searched
            # check the grid to see if there are any non resolved points
            # once we are out of unresolved points we are all good and can call it quits
            self.vision_range = 50
            print "explored all points"
            print "grid %r " % self.grid.shape[0]
            for i in range(0, self.grid.shape[0]):
                for j in range(0, self.grid.shape[1]):
                    if tank.index == 0:
                        point = Point(j - 400, i - 400)
                    else:
                        point = Point(400 - j - 1, 400 - i - 1)
                    if self.grid[point.y + 400][point.x + 400] != 0 and \
                        self.grid[point.y + 400][point.x + 400] != 1:
                        self.fields['scout_points'].append(point)
                        break

            if len(self.fields['scout_points']) == 0:
                print "no uncertainty remains"
            return
        dx, dy = self.calculate_field(tank)
        self.move_to_position(tank, dx + tank.x, dy + tank.y)
예제 #3
0
    def setup_potential_fields(self):
        self.fields['goal'] = []
        n = 25
        sx = 1
        sy = 1
        f = True
        f2 = True

        # if self.base_pos.x > 0.0:
        #     sx = -1
        # elif self.base_pos.y > 0.0:
        #     f = False
        #     f2 = False
        #     sy = -1
        # else:
        #     f = False
        #     f2 = False

        for t in range(0, 12):
            if t % 3 == 0:
                x, y = 0, 0
            if t % 3 == 1:
                if f:
                    x, y = n * 3 * sx, n * sy
                else:
                    x, y = n * sx, n * 3 * sy
            if t % 3 == 2:
                if f:
                    x, y = n * sx, n * 3 * sy
                else:
                    x, y = n * 3 * sx, n * sy
                f = not f
            if t == 3 or t == 9:
                if f2:
                    sy *= -1
                else:
                    sx *= -1
            if t == 6:
                if f2:
                    sx *= -1
                else:
                    sy *= -1
            self.fields['goal'].append(
                GoalField(x + self.base_pos.x, self.base_pos.y, 5, 30, 0.2))
예제 #4
0
 def __init__(self, bzrc):
     self.bzrc = bzrc
     self.constants = self.bzrc.get_constants()
     # self.obstacles = self.bzrc.get_obstacles()
     self.bases = self.bzrc.get_bases()
     self.commands = []
     self.mytanks = [tank for tank in self.bzrc.get_mytanks()]
     self.setup_common_potential_fields()
     for idx, tank in enumerate(self.mytanks):
         self.mytanks[idx].role = None
         self.mytanks[idx].field = None
         self.mytanks[idx].goal = None
     self.get_mycolor()
     for base in self.bases:
         if base.color == self.color:
             x = base.corner1_x + base.corner2_x + base.corner3_x + base.corner4_x
             y = base.corner1_y + base.corner2_y + base.corner3_y + base.corner4_y
             x = x / 4.0
             y = y / 4.0
             self.fields['base'] = GoalField(x, y, 15, 70, 0.15)
         else:
             continue
예제 #5
0
 def setup_potential_fields(self):
     self.fields['goal'] = []
     for flag in self.flags:
         self.fields['goal'].append(GoalField(flag.x, flag.y, 15, 70, 0.15))