<commit_before>#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>

struct Team {
        std::string name;
        sf::Color color;
        float score;
};

struct Cell {
        Team* team;
        bool undead;
};

enum class Stuff {
        DeadCell
};

struct sfVector2i_less {
        bool operator()(const sf::Vector2i& v1, const sf::Vector2i& v2) {
                return v1.y < v2.y or (v1.y == v2.y and v1.x < v2.x);
        }
};

struct Grid {
        std::map<sf::Vector2i, Cell, sfVector2i_less> cells;
        std::map<sf::Vector2i, Stuff, sfVector2i_less> stuff;
        void update();
};

void Grid::update() {

        std::map<sf::Vector2i, std::vector<Team*>, sfVector2i_less> adjacency;

        std::for_each(cells.begin(), cells.end(), [&](const std::pair<sf::Vector2i, Cell>& cellInfo) {

                auto& cellPos(cellInfo.first);
                auto& cell(cellInfo.second);

                sf::Vector2i neighbourPos;
                for (neighbourPos.y = cellPos.y - 1; neighbourPos.y <= cellPos.y + 1; ++neighbourPos.y)
                        for (neighbourPos.x = cellPos.x - 1; neighbourPos.x <= cellPos.x + 1; ++neighbourPos.x)
                                adjacency[neighbourPos].push_back(cell.team);

        });

        decltype(cells) nextCells;

        std::for_each(adjacency.begin(), adjacency.end(), [&](const std::pair<sf::Vector2i, std::vector<Team*>>& adjacencyInfo) {

                auto& cellPos(adjacencyInfo.first);
                auto& neighbours(adjacencyInfo.second);
                int neighbourCount = neighbours.size();

                Team* winningTeam;

                {

                        std::map<Team*, int> teamMembers;
                        std::for_each(neighbours.begin(), neighbours.end(), [&](Team* team) {
                                ++teamMembers[team];
                        });

                        std::map<int, Team*> sortedTeams;
                        std::for_each(teamMembers.begin(), teamMembers.end(), [&](std::pair<Team*, int> teamInfo) {
                                sortedTeams.insert(std::make_pair(teamInfo.second, teamInfo.first));
                        });

                        winningTeam = sortedTeams.rbegin()->second;

                }

                auto cellIt = cells.find(cellPos);

                if (cellIt != cells.end()) {

                        --neighbourCount; // The tile is counted as its own neighbour for team counting purposes.

                        Cell cell = cellIt->second;
                        cell.team = winningTeam;

                        if (neighbourCount == 2 or neighbourCount == 3 or cell.undead)
                                nextCells.insert(std::make_pair(cellPos, cell));
                        else
                                stuff.insert(std::make_pair(cellPos, Stuff::DeadCell));

                } else if (neighbourCount == 3) { // Cells can only appear with three neighbours

                        Cell cell;
                        cell.team = winningTeam;

                        auto stuffIt = stuff.find(cellPos);

                        if (stuffIt != stuff.end()) {

                                if (stuffIt->second == Stuff::DeadCell)
                                        cell.team->score *= 1.05f;

                                stuff.erase(stuffIt);

                        }

                        nextCells.insert(std::make_pair(cellPos, cell));

                }

        });

        cells.swap(nextCells);

}

struct Pattern {
        Pattern(const char* filename) { load(filename); }
        void load(const char* filename);
        void make(Grid* grid, Team* team, const sf::Vector2i& pos);
        std::vector<sf::Vector2i> positions;
};

void Pattern::load(const char* filename) {

        std::ifstream file(filename);

        int w;
        file >> w;

        bool isCell;
        for (int i = 0; file >> isCell; ++i)
                if (isCell)
                        positions.push_back(sf::Vector2i(i % w, i / w));

}

void Pattern::make(Grid* grid, Team* team, const sf::Vector2i& pos) {
        Cell cell = { team, false };
        std::for_each(positions.begin(), positions.end(), [&](const sf::Vector2i& offset) {
                grid->cells.insert(std::make_pair(pos + offset, cell));
        });
}

int main() {

        Pattern glider("glider.txt"), spaceship("ship.txt");

        Team playerTeam = { "Player", sf::Color(200, 50, 50), 1.f };
        Team enemyTeam = { "Enemy", sf::Color(50, 200, 50), 1.f };

        Grid grid;
        spaceship.make(&grid, &playerTeam, sf::Vector2i(3, 1));
        glider.make(&grid, &enemyTeam, sf::Vector2i(-5, -3));

        sf::RenderWindow win(sf::VideoMode::getFullscreenModes().front(), "Convolution");
        win.setVerticalSyncEnabled(true);
        win.setKeyRepeatEnabled(false);

        const float scaleStep = 1.5f;
        float scaling = 100.f;
        sf::Vector2f gridAim;

        while (win.isOpen()) {

                const float moveStep = .05f * win.getSize().x / scaling;

                sf::Event event;
                while (win.pollEvent(event)) {

                        if (event.type == sf::Event::Closed)
                                win.close();

#                       define BIND(keyname, action) else if (event.type == sf::Event::KeyPressed and event.key.code == sf::Keyboard::keyname) action
                        BIND(Escape, win.close());
                        BIND(Space, { grid.update(); std::cout << playerTeam.score << std::endl; })
                        BIND(Add, scaling *= scaleStep);
                        BIND(Subtract, scaling /= scaleStep);
                        BIND(Up, gridAim.y -= moveStep);
                        BIND(Down, gridAim.y += moveStep);
                        BIND(Left, gridAim.x -= moveStep);
                        BIND(Right, gridAim.x += moveStep);
#                       undef BIND

                }

                win.clear();

                std::for_each(grid.cells.begin(), grid.cells.end(), [&](const std::pair<sf::Vector2i, Cell> pair) {

                        sf::Vector2f cellPos(pair.first.x, pair.first.y);
                        cellPos -= gridAim;
                        cellPos *= scaling;
                        cellPos += .5f * sf::Vector2f(win.getSize().x, win.getSize().y);

                        sf::RectangleShape cellShape(sf::Vector2f(scaling, scaling));
                        cellShape.setPosition(cellPos);
                        cellShape.setFillColor(pair.second.team->color);
                        win.draw(cellShape);

                });

                win.display();

        }

}<commit_msg>Made the bonuses visible on screen<commit_after>#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>

struct Team {
        std::string name;
        sf::Color color;
        float score;
};

struct Cell {
        Team* team;
        bool undead;
};

enum class Stuff {
        DeadCell
};

struct sfVector2i_less {
        bool operator()(const sf::Vector2i& v1, const sf::Vector2i& v2) {
                return v1.y < v2.y or (v1.y == v2.y and v1.x < v2.x);
        }
};

struct Grid {
        std::map<sf::Vector2i, Cell, sfVector2i_less> cells;
        std::map<sf::Vector2i, Stuff, sfVector2i_less> stuff;
        void update();
};

void Grid::update() {

        std::map<sf::Vector2i, std::vector<Team*>, sfVector2i_less> adjacency;

        std::for_each(cells.begin(), cells.end(), [&](const std::pair<sf::Vector2i, Cell>& cellInfo) {

                auto& cellPos(cellInfo.first);
                auto& cell(cellInfo.second);

                sf::Vector2i neighbourPos;
                for (neighbourPos.y = cellPos.y - 1; neighbourPos.y <= cellPos.y + 1; ++neighbourPos.y)
                        for (neighbourPos.x = cellPos.x - 1; neighbourPos.x <= cellPos.x + 1; ++neighbourPos.x)
                                adjacency[neighbourPos].push_back(cell.team);

        });

        decltype(cells) nextCells;

        std::for_each(adjacency.begin(), adjacency.end(), [&](const std::pair<sf::Vector2i, std::vector<Team*>>& adjacencyInfo) {

                auto& cellPos(adjacencyInfo.first);
                auto& neighbours(adjacencyInfo.second);
                int neighbourCount = neighbours.size();

                Team* winningTeam;

                {

                        std::map<Team*, int> teamMembers;
                        std::for_each(neighbours.begin(), neighbours.end(), [&](Team* team) {
                                ++teamMembers[team];
                        });

                        std::map<int, Team*> sortedTeams;
                        std::for_each(teamMembers.begin(), teamMembers.end(), [&](std::pair<Team*, int> teamInfo) {
                                sortedTeams.insert(std::make_pair(teamInfo.second, teamInfo.first));
                        });

                        winningTeam = sortedTeams.rbegin()->second;

                }

                auto cellIt = cells.find(cellPos);

                if (cellIt != cells.end()) {

                        --neighbourCount; // The tile is counted as its own neighbour for team counting purposes.

                        Cell cell = cellIt->second;
                        cell.team = winningTeam;

                        if (neighbourCount == 2 or neighbourCount == 3 or cell.undead)
                                nextCells.insert(std::make_pair(cellPos, cell));
                        else
                                stuff.insert(std::make_pair(cellPos, Stuff::DeadCell));

                } else if (neighbourCount == 3) { // Cells can only appear with three neighbours

                        Cell cell;
                        cell.team = winningTeam;

                        auto stuffIt = stuff.find(cellPos);

                        if (stuffIt != stuff.end()) {

                                if (stuffIt->second == Stuff::DeadCell)
                                        cell.team->score *= 1.05f;

                                stuff.erase(stuffIt);

                        }

                        nextCells.insert(std::make_pair(cellPos, cell));

                }

        });

        cells.swap(nextCells);

}

struct Pattern {
        Pattern(const char* filename) { load(filename); }
        void load(const char* filename);
        void make(Grid* grid, Team* team, const sf::Vector2i& pos);
        std::vector<sf::Vector2i> positions;
};

void Pattern::load(const char* filename) {

        std::ifstream file(filename);

        int w;
        file >> w;

        bool isCell;
        for (int i = 0; file >> isCell; ++i)
                if (isCell)
                        positions.push_back(sf::Vector2i(i % w, i / w));

}

void Pattern::make(Grid* grid, Team* team, const sf::Vector2i& pos) {
        Cell cell = { team, false };
        std::for_each(positions.begin(), positions.end(), [&](const sf::Vector2i& offset) {
                grid->cells.insert(std::make_pair(pos + offset, cell));
        });
}

int main() {

        Pattern glider("glider.txt"), spaceship("ship.txt");

        Team playerTeam = { "Player", sf::Color(200, 50, 50), 1.f };
        Team enemyTeam = { "Enemy", sf::Color(50, 50, 200), 1.f };

        Grid grid;
        spaceship.make(&grid, &playerTeam, sf::Vector2i(3, 1));
        glider.make(&grid, &enemyTeam, sf::Vector2i(-5, -3));

        sf::RenderWindow win(sf::VideoMode::getFullscreenModes().front(), "Convolution");
        win.setVerticalSyncEnabled(true);
        win.setKeyRepeatEnabled(false);

        const float scaleStep = 1.5f;
        float scaling = 100.f;
        sf::Vector2f gridAim;

        while (win.isOpen()) {

                const float moveStep = .05f * win.getSize().x / scaling;

                sf::Event event;
                while (win.pollEvent(event)) {

                        if (event.type == sf::Event::Closed)
                                win.close();

#                       define BIND(keyname, action) else if (event.type == sf::Event::KeyPressed and event.key.code == sf::Keyboard::keyname) action
                        BIND(Escape, win.close());
                        BIND(Space, { grid.update(); std::cout << playerTeam.score << std::endl; })
                        BIND(Add, scaling *= scaleStep);
                        BIND(Subtract, scaling /= scaleStep);
                        BIND(Up, gridAim.y -= moveStep);
                        BIND(Down, gridAim.y += moveStep);
                        BIND(Left, gridAim.x -= moveStep);
                        BIND(Right, gridAim.x += moveStep);
#                       undef BIND

                }

                win.clear();

                auto grid_to_screen = [&](const sf::Vector2i& gridPos) {
                        return (sf::Vector2f(gridPos.x, gridPos.y) - gridAim) * scaling + .5f * sf::Vector2f(win.getSize().x, win.getSize().y);
                };

                std::for_each(grid.cells.begin(), grid.cells.end(), [&](const std::pair<sf::Vector2i, Cell> pair) {

                        sf::RectangleShape cellShape(sf::Vector2f(scaling, scaling));
                        cellShape.setPosition(grid_to_screen(pair.first));
                        cellShape.setFillColor(pair.second.team->color);
                        win.draw(cellShape);

                });

                std::for_each(grid.stuff.begin(), grid.stuff.end(), [&](const std::pair<sf::Vector2i, Stuff> pair) {

                        sf::CircleShape stuffShape(scaling / 5.f);
                        stuffShape.setPosition(grid_to_screen(pair.first));
                        stuffShape.move(scaling / 4.f, scaling / 4.f);
                        stuffShape.setFillColor(sf::Color(50, 200, 50));
                        win.draw(stuffShape);

                });

                win.display();

        }

}
{'fraction_non_alphanumeric': 0.13351010462949692, 'fraction_numerical': 0.01103626200372653, 'mean_word_length': 1.5423574421570414, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1574781', 'n_tokens_mistral': 4187, 'n_tokens_neox': 3808, 'n_words': 785}