<commit_before>package com.murphysean.bzrflag.commanders;

import com.murphysean.bzrflag.agents.GoToAgent;
import com.murphysean.bzrflag.events.BZRFlagEvent;
import com.murphysean.bzrflag.models.Game;
import com.murphysean.bzrflag.models.Point;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by erikdonohoo on 12/11/13.
 */
public class PidgeonCommander extends AbstractCommander {

    private Point smartPidgeonPoint;
    private GoToAgent dumbPidgeon, flyingPidgeon, smartPidgeon;
    private List<Point> flyingPoints, smartPoints;
    private Point dumbPidgeonSpot;
    private static final long DUMB_PIDGEON_WAIT = 30000; // 30 sec
    private static final long SMART_PIDGEON_THRESHOLD = 40;
    private static final long BUFFER = 20;

    public PidgeonCommander() {
        super();
    }

    @Override
    public void setGame(Game game){
        super.setGame(game);

        // Create three goToAgents, one for each thing
        // Ensure team has at least 3
        float range = game.getShotRange() * 2/3;
        dumbPidgeonSpot = new Point(range*-1, range);
        if (playerCount < 3)
            throw new RuntimeException("Must have 3 tanks for a Pidgeon Commander");
        dumbPidgeon = new GoToAgent();
        dumbPidgeon.setGame(game);
        dumbPidgeon.setId(0);
        dumbPidgeon.setCallsign(game.getTeam().getColor() + 0);
        dumbPidgeon.setTeamColor(game.getTeam().getColor());
        tanks.add(dumbPidgeon);

        flyingPidgeon = new GoToAgent();
        flyingPidgeon.setGame(game);
        flyingPidgeon.setId(1);
        flyingPidgeon.setCallsign(game.getTeam().getColor() + 1);
        flyingPidgeon.setTeamColor(game.getTeam().getColor());
        tanks.add(flyingPidgeon);

        smartPidgeon = new GoToAgent();
        smartPidgeon.setGame(game);
        smartPidgeon.setId(2);
        smartPidgeon.setCallsign(game.getTeam().getColor() + 2);
        smartPidgeon.setTeamColor(game.getTeam().getColor());
        tanks.add(smartPidgeon);

        // Points for flying pidgeon
        flyingPoints = new ArrayList<Point>();
        flyingPoints.add(new Point(BUFFER*-1, BUFFER*-1));
        flyingPoints.add(new Point(range*-1,range*-1));
        flyingPoints.add(new Point(BUFFER*-1, range*-1));
        flyingPoints.add(new Point(range*-1, BUFFER*-1));

        smartPoints = new ArrayList<Point>();
        smartPoints.add(new Point(BUFFER, BUFFER*-1));
        smartPoints.add(new Point(range, range*-1));
        smartPoints.add(new Point(BUFFER, range*-1));
        smartPoints.add(new Point(range, BUFFER*-1));

        // Gentlemen, start your pidgeons
        dumbPidgeon.setDestination(dumbPidgeonSpot);
        flyingPidgeon.setDestination(choosePoint(flyingPoints));
        smartPidgeonPoint = choosePoint(smartPoints);

        // Figure out where to tell him to go
        smartPidgeon.setDestination(smartPidgeonPoint);

    }

    private Point choosePoint(List<Point> points) {
        int index = (int)Math.floor(Math.random() * 3.9999);
        return points.get(index);
    }

    private double distanceBetweenPoints(Point x, Point y) {
        return Math.sqrt(Math.pow(y.getX() - x.getX(), 2) + Math.pow(y.getY() - x.getY(), 2));
    }

    private Point figureOutSmartPoint(Point location) {
        // Based on smartPidgeonPoint, select a point that is slightly closer to that point but not too far from us currently
        float xPos = location.getX() + 400;
        float yPos = location.getY() + 400;
        float xGoal = smartPidgeonPoint.getX() + 400;
        float yGoal = smartPidgeonPoint.getY() + 400;

        float addX = (xPos <= xGoal) ? xPos : xGoal;
        int nextX = (int)(Math.random() * (Math.abs(xPos - xGoal))) + (int)addX - 400;
        float addY = (yPos <= yGoal) ? yPos : yGoal;
        int nextY = (int)(Math.random() * (Math.abs(yPos - yGoal))) + (int)addY - 400;
        return new Point(nextX, nextY);
    }

    @Override
    public void bzrFlagEventHandler(BZRFlagEvent event) {
        if (event instanceof GoToAgent.GoToAlmostThereEvent) {
            GoToAgent agent = ((GoToAgent.GoToAlmostThereEvent)event).getGoToAgent();

            // Determine which pidgeon we are on
            if (agent.getId() == 1) { // Straight line pidgeon
                flyingPidgeon.setDestination(choosePoint(flyingPoints));

            } else if (agent.getId() == 2) { // Smart Pidgeon
                if (((GoToAgent.GoToAlmostThereEvent)event).getDestination().equals(smartPidgeonPoint)) {
                    // Figure out where to tell him to go<commit_msg>Updated code<commit_after>package com.murphysean.bzrflag.commanders;

import com.murphysean.bzrflag.agents.GoToAgent;
import com.murphysean.bzrflag.events.BZRFlagEvent;
import com.murphysean.bzrflag.models.Game;
import com.murphysean.bzrflag.models.Point;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by erikdonohoo on 12/11/13.
 */
public class PidgeonCommander extends AbstractCommander {

    private Point smartPidgeonPoint;
    private GoToAgent dumbPidgeon, flyingPidgeon, smartPidgeon;
    private List<Point> flyingPoints, smartPoints;
    private Point dumbPidgeonSpot;
    private static final long DUMB_PIDGEON_WAIT = 30000; // 30 sec
    private static final long SMART_PIDGEON_THRESHOLD = 40;
    private static final long BUFFER = 20;

    public PidgeonCommander() {
        super();
    }

    @Override
    public void setGame(Game game){
        super.setGame(game);

        // Create three goToAgents, one for each thing
        // Ensure team has at least 3
        float range = game.getShotRange() * 2/3;
        dumbPidgeonSpot = new Point(range*-1, range);
        if (playerCount < 3)
            throw new RuntimeException("Must have 3 tanks for a Pidgeon Commander");
        dumbPidgeon = new GoToAgent();
        dumbPidgeon.setGame(game);
        dumbPidgeon.setId(0);
        dumbPidgeon.setCallsign(game.getTeam().getColor() + 0);
        dumbPidgeon.setTeamColor(game.getTeam().getColor());
        tanks.add(dumbPidgeon);

        flyingPidgeon = new GoToAgent();
        flyingPidgeon.setGame(game);
        flyingPidgeon.setId(1);
        flyingPidgeon.setCallsign(game.getTeam().getColor() + 1);
        flyingPidgeon.setTeamColor(game.getTeam().getColor());
        tanks.add(flyingPidgeon);

        smartPidgeon = new GoToAgent();
        smartPidgeon.setGame(game);
        smartPidgeon.setId(2);
        smartPidgeon.setCallsign(game.getTeam().getColor() + 2);
        smartPidgeon.setTeamColor(game.getTeam().getColor());
        tanks.add(smartPidgeon);

        // Points for flying pidgeon
        flyingPoints = new ArrayList<Point>();
        flyingPoints.add(new Point(range*-1,range*-1));
        flyingPoints.add(new Point(BUFFER*-1, range*-1));
        flyingPoints.add(new Point(range*-1, BUFFER*-1));

        smartPoints = new ArrayList<Point>();
        smartPoints.add(new Point(range, range*-1));
        smartPoints.add(new Point(BUFFER, range*-1));
        smartPoints.add(new Point(range, BUFFER*-1));

        // Gentlemen, start your pidgeons
        dumbPidgeon.setDestination(dumbPidgeonSpot);
        flyingPidgeon.setDestination(choosePoint(flyingPoints));
        smartPidgeonPoint = choosePoint(smartPoints);

        // Figure out where to tell him to go
        smartPidgeon.setDestination(smartPidgeonPoint);

    }

    private Point choosePoint(List<Point> points) {
        int index = (int)Math.floor(Math.random() * 2.9999);
        return points.get(index);
    }

    private double distanceBetweenPoints(Point x, Point y) {
        return Math.sqrt(Math.pow(y.getX() - x.getX(), 2) + Math.pow(y.getY() - x.getY(), 2));
    }

    private Point figureOutSmartPoint(Point location) {
        // Based on smartPidgeonPoint, select a point that is slightly closer to that point but not too far from us currently
        // Based on smartPidgeonPoint, select a point that is slightly closer to that point but not too far from us currently
        float ang = (float)Math.atan2(smartPidgeonPoint.getY() - location.getY(),smartPidgeonPoint.getX() - location.getX());
        ang += (Math.random() * 0.767944871) - 0.383972435;
        int x = (int)(location.getX() + SMART_PIDGEON_THRESHOLD * Math.cos(ang));
        int y = (int)(location.getY() + SMART_PIDGEON_THRESHOLD * Math.sin(ang));
        return new Point(x,y);
    }

    @Override
    public void bzrFlagEventHandler(BZRFlagEvent event) {
        if (event instanceof GoToAgent.GoToAlmostThereEvent) {
            GoToAgent agent = ((GoToAgent.GoToAlmostThereEvent)event).getGoToAgent();

            // Determine which pidgeon we are on
            if (agent.getId() == 1) { // Straight line pidgeon
                flyingPidgeon.setDestination(choosePoint(flyingPoints));

            } else if (agent.getId() == 2) { // Smart Pidgeon
                if (((GoToAgent.GoToAlmostThereEvent)event).getDestination().equals(smartPidgeonPoint)) {
                    // Figure out where to tell him to go
{'fraction_non_alphanumeric': 0.11533783036602897, 'fraction_numerical': 0.015039256883777507, 'mean_word_length': 2.891566265060241, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '2279951', 'n_tokens_mistral': 2957, 'n_tokens_neox': 2834, 'n_words': 616}