<commit_before>package afk.frontend.swing.postgame;

import afk.bot.Robot;
import afk.game.GameResult;
import afk.game.TournamentGame;
import afk.game.TournamentGameResult;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseWheelEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.JComponent;

/**
 *
 * @author daniel
 */
public class TournamentTree extends JComponent
{

    public static final Color BG_COLOUR = new Color(0x444444);
    private final Font FONT = new Font("Myriad Pro", Font.PLAIN, 12);
    private TournamentGameResult result;
    private Robot[][][] robots;
    private Robot[] robotsThrough;
    private GameResult[][] results;
    private int[][] nextGroups;
    public static final int ICON_SIZE = 48;
    public static final int ICON_PADDING = 20;
    public static final int TEXT_OFFSET = 10;
    public static final int GROUP_PADDING = 20;
    public static final int ROUND_PADDING = 50;
    private int roundNumber;
    private int gameNum;
    private int mx, my;
    private float dx, dy;
    private float zoom = 1.0f;

    public TournamentTree(TournamentGameResult result)
    {
        this.result = result;
        this.robots = result.getGroups();
        this.robotsThrough = result.getRobotsThrough();
        this.roundNumber = robots.length - 1;
        this.gameNum = result.getCurrentGame();

        addMouseListener(new MouseAdapter()
        {
            @Override
            public void mousePressed(MouseEvent e)
            {
                mx = e.getX();
                my = e.getY();
            }
        });

        addMouseMotionListener(new MouseMotionAdapter()
        {
            @Override
            public void mouseDragged(MouseEvent e)
            {
                int nx = e.getX();
                int ny = e.getY();
                dx += nx - mx;
                dy += ny - my;
                mx = nx;
                my = ny;
                repaint();
            }
        });

        addMouseWheelListener(new MouseAdapter()
        {
            @Override
            public void mouseWheelMoved(MouseWheelEvent e)
            {
                double r = e.getPreciseWheelRotation();
                float x1 = (e.getX()-dx)/zoom;
                float y1 = (e.getY()-dy)/zoom;
                if (r > 0)
                {
                    zoom *= 0.9f * r;
                } else if (r < 0)
                {
                    zoom *= 1.1f * -r;
                    if (zoom > 1)
                    {
                        zoom = 1;
                    }
                }
                float x2 = (e.getX()-dx)/zoom;
                float y2 = (e.getY()-dy)/zoom;
                dx += (x2-x1)*zoom;
                dy += (y2-y1)*zoom;
                repaint();
            }
        });

    }

    @Override
    public void paint(Graphics g1)
    {
        Graphics2D g = (Graphics2D) g1;

        g.setBackground(BG_COLOUR);
        g.clearRect(0, 0, getWidth(), getHeight());

        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BICUBIC);

        ArrayList<BufferedImage[]> groupImages = new ArrayList<BufferedImage[]>();
        ArrayList<Integer> roundWidths = new ArrayList<Integer>();
        ArrayList<Integer> roundHeights = new ArrayList<Integer>();

        // generate images for existing groups
        for (int i = 0; i < robots.length; i++)
        {
            int rw = 0;
            int rh = GROUP_PADDING;
            BufferedImage[] gi = new BufferedImage[robots[i].length];
            for (int j = 0; j < robots[i].length; j++)
            {
                gi[j] = drawGroup(robots[i][j]);
                int w = gi[j].getWidth();
                if (w > rw)
                {
                    rw = w;
                }
                rh += GROUP_PADDING + gi[j].getHeight();
            }
            roundWidths.add(rw);
            roundHeights.add(rh);
            groupImages.add(gi);
        }


        int botsLeft = robots[robots.length - 1].length * 2;
        // You may THINK this if statement says
        // "If there are 2 bots and AND if there are 2 bots"<commit_msg>Using nearest neighbour interpolation for performance.<commit_after>package afk.frontend.swing.postgame;

import afk.bot.Robot;
import afk.game.GameResult;
import afk.game.TournamentGame;
import afk.game.TournamentGameResult;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseWheelEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.JComponent;

/**
 *
 * @author daniel
 */
public class TournamentTree extends JComponent
{

    public static final Color BG_COLOUR = new Color(0x444444);
    private final Font FONT = new Font("Myriad Pro", Font.PLAIN, 12);
    private TournamentGameResult result;
    private Robot[][][] robots;
    private Robot[] robotsThrough;
    private GameResult[][] results;
    private int[][] nextGroups;
    public static final int ICON_SIZE = 48;
    public static final int ICON_PADDING = 20;
    public static final int TEXT_OFFSET = 10;
    public static final int GROUP_PADDING = 20;
    public static final int ROUND_PADDING = 50;
    private int roundNumber;
    private int gameNum;
    private int mx, my;
    private float dx, dy;
    private float zoom = 1.0f;

    public TournamentTree(TournamentGameResult result)
    {
        this.result = result;
        this.robots = result.getGroups();
        this.robotsThrough = result.getRobotsThrough();
        this.roundNumber = robots.length - 1;
        this.gameNum = result.getCurrentGame();

        addMouseListener(new MouseAdapter()
        {
            @Override
            public void mousePressed(MouseEvent e)
            {
                mx = e.getX();
                my = e.getY();
            }
        });

        addMouseMotionListener(new MouseMotionAdapter()
        {
            @Override
            public void mouseDragged(MouseEvent e)
            {
                int nx = e.getX();
                int ny = e.getY();
                dx += nx - mx;
                dy += ny - my;
                mx = nx;
                my = ny;
                repaint();
            }
        });

        addMouseWheelListener(new MouseAdapter()
        {
            @Override
            public void mouseWheelMoved(MouseWheelEvent e)
            {
                double r = e.getPreciseWheelRotation();
                float x1 = (e.getX()-dx)/zoom;
                float y1 = (e.getY()-dy)/zoom;
                if (r > 0)
                {
                    zoom *= 0.9f * r;
                } else if (r < 0)
                {
                    zoom *= 1.1f * -r;
                    if (zoom > 1)
                    {
                        zoom = 1;
                    }
                }
                float x2 = (e.getX()-dx)/zoom;
                float y2 = (e.getY()-dy)/zoom;
                dx += (x2-x1)*zoom;
                dy += (y2-y1)*zoom;
                repaint();
            }
        });

    }

    @Override
    public void paint(Graphics g1)
    {
        Graphics2D g = (Graphics2D) g1;

        g.setBackground(BG_COLOUR);
        g.clearRect(0, 0, getWidth(), getHeight());

        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);

        ArrayList<BufferedImage[]> groupImages = new ArrayList<BufferedImage[]>();
        ArrayList<Integer> roundWidths = new ArrayList<Integer>();
        ArrayList<Integer> roundHeights = new ArrayList<Integer>();

        // generate images for existing groups
        for (int i = 0; i < robots.length; i++)
        {
            int rw = 0;
            int rh = GROUP_PADDING;
            BufferedImage[] gi = new BufferedImage[robots[i].length];
            for (int j = 0; j < robots[i].length; j++)
            {
                gi[j] = drawGroup(robots[i][j]);
                int w = gi[j].getWidth();
                if (w > rw)
                {
                    rw = w;
                }
                rh += GROUP_PADDING + gi[j].getHeight();
            }
            roundWidths.add(rw);
            roundHeights.add(rh);
            groupImages.add(gi);
        }


        int botsLeft = robots[robots.length - 1].length * 2;
        // You may THINK this if statement says
        // "If there are 2 bots and AND if there are 2 bots"
{'fraction_non_alphanumeric': 0.10460482621208766, 'fraction_numerical': 0.011512065530219173, 'mean_word_length': 1.641040631394329, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '4818193', 'n_tokens_mistral': 2777, 'n_tokens_neox': 2563, 'n_words': 634}