<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import random
import vector
# we import field just because
import fieldobject

class Robot(fieldobject.FieldObject):
    """
    A server-side robot.
    """
    def __init__(self, name, field, location, scanner=5, weapon=2, armor=2,
            engine=2, heatsink=1,mines=0,shield=0):
        self.name = name
        self.throttle = 0 # How fast we WANT to go
        self.speed = 0 # How fast we're ACTUALLY going
        self.steer = random.uniform(0, 2*math.pi) # Where we WANT to turn
        self.rotation = self.steer # Where we ARE turning
        self.turret_rot = 0 # Where our turret is pointing
                            # relative to self.steer
        self.field = field
        self.location = vector.Vector(location)
        self.scan_width = math.pi / 2
        self.heat = 0

        assert sum([scanner,weapon,armor,engine,heatsink,mines,shield]) <= 12, "You can only have 12 points"
        self.scanrange = [250,  350, 500, 700, 1000, 1500][scanner]
        self.weapon =    [0.5,  0.8,  1., 1.2, 1.35,  1.5][weapon]
        self.armor =     [ 50,   66, 100, 120,  130,  150][armor]
        self.engine = (  [0.5,  0.8,  1., 1.2, 1.35,  1.5][engine]
                       * [1.33, 1.2,  1., 0.8, 0.75, 0.66][armor])
        self.heatsink = [0.75, 1.0, 1.125, 1.25, 1.33, 1.5][heatsink]

    def __json__(self):
        return {'name': self.name,
                'armor': self.armor,
                'heat': self.heat}

    def field_info(self):
        # return enough information for the client to draw on the screen. This
        # should usually be kept secret (ie not in self.__json__).
        return {'type': 'robot',
                'name': self.name,
                'location': self.location,
                'rotation': self.rotation,
                'turret_rot': self.turret_rot,
                'speed': self.speed,
               }

    def __str__(self):
        return "<Robot '%s' (%s armor)>" % (self.name, self.armor)

    def __repr__(self):
        return str(self)
             
    def pump(self):
        """
        Performs time-sensitive actions over a tic.
        - Accelerates or decelerates
        - Rotates self by ever so much
        - Detects collisions against robots and other walls, stops and hits self
          if necessary.
        - Reduces heat
        """
        if not self.dead and self.heat < 350:
            angle_diff = vector.angle_normalize(self.steer - self.rotation)
            if angle_diff < 0:
                self.rotation -= min(abs(angle_diff), self.engine/5)
            elif angle_diff > 0:
                self.rotation += min(abs(angle_diff), self.engine/5)

    def hit(self, damage):
        """
        We were hit!<commit_msg>Rotation angle is now just a tad saner than before.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import random
import vector
# we import field just because
import fieldobject

class Robot(fieldobject.FieldObject):
    """
    A server-side robot.
    """
    def __init__(self, name, field, location, scanner=5, weapon=2, armor=2,
            engine=2, heatsink=1,mines=0,shield=0):
        self.name = name
        self.throttle = 0 # How fast we WANT to go
        self.speed = 0 # How fast we're ACTUALLY going
        self.steer = random.uniform(0, 2*math.pi) # Where we WANT to turn
        self.rotation = self.steer # Where we ARE turning
        self.turret_rot = 0 # Where our turret is pointing
                            # relative to self.steer
        self.field = field
        self.location = vector.Vector(location)
        self.scan_width = math.pi / 2
        self.heat = 0

        assert sum([scanner,weapon,armor,engine,heatsink,mines,shield]) <= 12, "You can only have 12 points"
        self.scanrange = [250,  350, 500, 700, 1000, 1500][scanner]
        self.weapon =    [0.5,  0.8,  1., 1.2, 1.35,  1.5][weapon]
        self.armor =     [ 50,   66, 100, 120,  130,  150][armor]
        self.engine = (  [0.5,  0.8,  1., 1.2, 1.35,  1.5][engine]
                       * [1.33, 1.2,  1., 0.8, 0.75, 0.66][armor])
        self.heatsink = [0.75, 1.0, 1.125, 1.25, 1.33, 1.5][heatsink]

    def __json__(self):
        return {'name': self.name,
                'armor': self.armor,
                'heat': self.heat}

    def field_info(self):
        # return enough information for the client to draw on the screen. This
        # should usually be kept secret (ie not in self.__json__).
        return {'type': 'robot',
                'name': self.name,
                'location': self.location,
                'rotation': self.rotation,
                'turret_rot': self.turret_rot,
                'speed': self.speed,
               }

    def __str__(self):
        return "<Robot '%s' (%s armor)>" % (self.name, self.armor)

    def __repr__(self):
        return str(self)
             
    def pump(self):
        """
        Performs time-sensitive actions over a tic.
        - Accelerates or decelerates
        - Rotates self by ever so much
        - Detects collisions against robots and other walls, stops and hits self
          if necessary.
        - Reduces heat
        """
        if self.dead or self.heat > 350:
            return
        # change angles
        bearing = vector.angle_normalize(self.steer - self.rotation)
        angle_diff = self.engine/5
        print self.rotation, bearing
        if abs(bearing) < angle_diff:
            self.rotation += bearing
        else:
            self.rotation += angle_diff if bearing>0 else -angle_diff

    def hit(self, damage):
        """
        We were hit!
{'fraction_non_alphanumeric': 0.11954992967651196, 'fraction_numerical': 0.040787623066104076, 'mean_word_length': 1.8163366336633664, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2591210', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1761, 'n_words': 513}