├── .gitignore ├── README.md ├── bots ├── a-code-of-ice-and-fire │ └── a-code-of-ice-and-fire.cpp ├── botters-of-the-galaxy │ └── botters-of-the-galaxy.cpp ├── code-of-kutulu │ └── code-of-kutulu.cpp ├── codebusters │ └── codebusters.cpp ├── coders-of-the-caribbean │ └── coders-of-the-caribbean.cpp ├── coders-strike-back │ └── coders-strike-back.cpp ├── crystal-rush │ ├── Command.cpp │ ├── Command.h │ ├── Common.h │ ├── Position.cpp │ ├── Position.h │ ├── Robot.cpp │ ├── Robot.h │ ├── Tile.cpp │ ├── Tile.h │ └── main.cpp ├── cultist-wars │ ├── Common.h │ ├── Game.cpp │ ├── Game.h │ ├── Move.cpp │ ├── Move.h │ ├── Unit.cpp │ ├── Unit.h │ └── main.cpp ├── fall-challenge-2020 │ ├── Action.cpp │ ├── Action.h │ ├── Common.h │ ├── Game.cpp │ ├── Game.h │ ├── Player.cpp │ ├── Player.h │ ├── Quad.cpp │ ├── Quad.h │ └── main.cpp ├── fantastic-bits │ └── fantastic-bits.cpp ├── game-of-drones │ └── game-of-drones.cpp ├── ghost-in-the-cell │ └── ghost-in-the-cell.vb ├── keep-off-the-grass │ ├── Common.h │ ├── Map.cpp │ ├── Map.h │ ├── Player.cpp │ ├── Player.h │ ├── Tile.cpp │ ├── Tile.h │ └── main.cpp ├── lava-runners │ ├── Bomb.cpp │ ├── Bomb.h │ ├── Common.h │ ├── Move.cpp │ ├── Move.h │ ├── Player.cpp │ ├── Player.h │ ├── Tile.cpp │ ├── Tile.h │ └── main.cpp ├── mean-max │ └── mean-max.cpp ├── ocean-of-code │ ├── Common.cpp │ ├── Common.h │ ├── DamagePattern.cpp │ ├── DamagePattern.h │ ├── Enemy.cpp │ ├── Enemy.h │ ├── Explosion.cpp │ ├── Explosion.h │ ├── Game.cpp │ ├── Game.h │ ├── Map.cpp │ ├── Map.h │ ├── Position.cpp │ ├── Position.h │ ├── Tile.cpp │ ├── Tile.h │ └── main.cpp ├── olymbits │ ├── Archery.cpp │ ├── Archery.h │ ├── Common.h │ ├── Diving.cpp │ ├── Diving.h │ ├── Hurdles.cpp │ ├── Hurdles.h │ ├── Player.cpp │ ├── Player.h │ ├── Score.cpp │ ├── Score.h │ ├── Skating.cpp │ ├── Skating.h │ ├── main.cpp │ └── wood2bronze │ │ └── bronzeCode.cpp.backup ├── poker-chip-race │ └── poker-chip-race.cpp ├── seabed-security │ ├── Common.h │ ├── Drone.cpp │ ├── Drone.h │ ├── Fish.cpp │ ├── Fish.h │ ├── Game.cpp │ ├── Game.h │ ├── Position.cpp │ ├── Position.h │ └── main.cpp ├── space-shooter │ ├── Common.h │ ├── Game.cpp │ ├── Game.h │ ├── Unit.cpp │ ├── Unit.h │ ├── Vector2D.cpp │ ├── Vector2D.h │ └── main.cpp ├── spring-challenge-2020 │ ├── Common.h │ ├── Map.cpp │ ├── Map.h │ ├── Move.cpp │ ├── Move.h │ ├── Pacman.cpp │ ├── Pacman.h │ ├── Pellet.cpp │ ├── Pellet.h │ ├── Player.cpp │ ├── Player.h │ ├── Position.cpp │ ├── Position.h │ ├── Tile.cpp │ ├── Tile.h │ ├── Tree.cpp │ ├── Tree.h │ └── main.cpp ├── spring-challenge-2021 │ ├── Cell.cpp │ ├── Cell.h │ ├── Common.h │ ├── Player.cpp │ ├── Player.h │ ├── Tree.cpp │ ├── Tree.h │ └── main.cpp ├── spring-challenge-2022 │ ├── Common.h │ ├── Hero.cpp │ ├── Hero.h │ ├── Monster.cpp │ ├── Monster.h │ ├── Vector2D.cpp │ ├── Vector2D.h │ └── main.cpp ├── spring-challenge-2023 │ ├── Common.h │ ├── Map.cpp │ ├── Map.h │ ├── Tile.cpp │ ├── Tile.h │ └── main.cpp ├── tulips-and-daisies │ ├── Common.h │ ├── Game.cpp │ ├── Game.h │ ├── Makefile │ ├── Map.cpp │ ├── Map.h │ ├── Player.cpp │ ├── Player.h │ ├── Position.cpp │ ├── Position.h │ ├── Strategy.h │ ├── TestPlayer.cpp │ ├── TestPlayer.h │ ├── Utils.cpp │ ├── Utils.h │ ├── main.cpp │ └── tind-1.0 ├── ultimate-tic-tac-toe │ ├── Board.cpp │ ├── Board.h │ ├── Branch.cpp │ ├── Branch.h │ ├── Common.cpp │ ├── Common.h │ ├── Game.cpp │ ├── Game.h │ ├── Gametree.cpp │ ├── Gametree.h │ ├── Makefile │ ├── Move.cpp │ ├── Move.h │ ├── MoveList.cpp │ ├── MoveList.h │ ├── Strategy.cpp │ ├── Strategy.h │ └── uTTT.cpp ├── vindinium │ └── vindinium.cpp ├── winter-challange-2024 │ ├── Ai.cpp │ ├── Ai.h │ ├── Common.h │ ├── Makefile │ ├── Map.cpp │ ├── Map.h │ ├── Move.cpp │ ├── Move.h │ ├── Player.cpp │ ├── Player.h │ ├── Posdir.cpp │ ├── Posdir.h │ ├── TileType.cpp │ ├── TileType.h │ └── main.cpp └── xmas-rush │ └── xmas-rush.cpp ├── code-golf ├── chuck-norris-codesize.cpp ├── dont-panic.cpp ├── power-of-thor.cpp └── temperature-code-golf.cpp ├── easy ├── 1d-spreadsheet.cpp ├── ascii-art.vb ├── asteroids.cpp ├── brackets-extreme-edition.cpp ├── chuck-norris.vb ├── dead-mens-shot.cpp ├── defibrillators.cpp ├── defibrillators.vb ├── detective-pikaptcha-ep1.cpp ├── detective-pikaptcha-ep2.cpp ├── horse-racing-duals.cpp ├── lumen.cpp ├── mars-lander-episode-1.cpp ├── mars-lander-episode-1.vb ├── mime-type.vb ├── nature-of-quadrilaterals.cpp ├── onboarding.cpp ├── onboarding.vb ├── power-of-thor-episode-1.cpp ├── power-of-thor-episode-1.py ├── power-of-thor-episode-1.vb ├── sum-of-spirals-diagonals.cpp ├── temperatures.vb ├── the-descent.cpp └── the-river-i.cpp ├── hard ├── google-interview---the-two-egg-problem.cpp ├── power-of-thor-episode-2.vb ├── roller-coaster.cpp ├── skynet-revolution-episode-2.vb ├── surface.cpp ├── the-bridge-episode-2.cpp ├── the-hungry-duck---part-1.cpp ├── the-hungry-duck---part-2.cpp ├── the-labyrinth.vb └── vox-codei-episode-1.cpp ├── medium ├── aneo.cpp ├── bender-episode-1.vb ├── bulls-and-cows.cpp ├── conway-sequence.vb ├── detective-pikaptcha-ep3.cpp ├── dont-panic-episode-1.cpp ├── dont-panic-episode-1.vb ├── dwarfs-standing-on-the-shoulders-of-giants.vb ├── elementary-cellular-automaton.cpp ├── game-of-life.cpp ├── gravity.cpp ├── langtons-ant.cpp ├── mars-lander-episode-2.cpp ├── mars-lander-episode-2.vb ├── mayan-calculation.vb ├── minesweeper.cpp ├── network-cabling.vb ├── particle-detection-with-cloud-chamber.cpp ├── robbery-optimization.cpp ├── rubik.cpp ├── rush-hour.cpp ├── scrabble.vb ├── shadows-of-the-knight-episode-1.vb ├── skynet-revolution-episode-1.vb ├── stock-exchange-losses.vb ├── target-firing.cpp ├── telephone-numbers.vb ├── the-experience-for-creating-puzzles.cpp ├── the-fastest.cpp ├── the-gift.vb ├── the-last-crusade-episode-1.vb ├── there-is-no-spoon-episode-1.vb └── winamax-battle.vb ├── merging-cpp-files-readme.txt ├── optimization ├── a-star-craft │ └── a-star-craft.cpp ├── code-of-the-rings │ └── code-of-the-rings.cpp ├── code-vs-zombies │ └── code-vs-zombies.cpp ├── codingame-sponsored-contest │ └── codingame-sponsored-contest.vb ├── mars-lander │ └── mars-lander.cpp └── search-race │ ├── fig │ ├── dofig │ ├── fig.aux │ ├── fig.fdb_latexmk │ ├── fig.fls │ ├── fig.pdf │ ├── fig.tex │ ├── figure.pdf │ ├── gpfigure-eps-converted-to.pdf │ ├── gpfigure.eps │ ├── gpfigure.gp │ └── gpfigure.tex │ └── src │ ├── Action.cpp │ ├── Action.h │ ├── ActionList.cpp │ ├── ActionList.h │ ├── Car.cpp │ ├── Car.h │ ├── Checkpoint.cpp │ ├── Checkpoint.h │ ├── Common.h │ ├── Goal.cpp │ ├── Goal.h │ ├── Makefile │ ├── Position.cpp │ ├── Position.h │ ├── circles.dat │ ├── doTests │ ├── main.cpp │ ├── results │ ├── test1 │ ├── test16 │ ├── test19 │ ├── test2 │ ├── test3 │ ├── test4 │ ├── test5 │ ├── test6 │ ├── test7 │ └── track.dat └── very-hard └── music-scores.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Paraview files 35 | *.vtu 36 | *.pvd 37 | 38 | # Andromeda restart files 39 | *.rst 40 | *.log 41 | *.txt 42 | *.bin 43 | navodila-git 44 | .vscode 45 | -------------------------------------------------------------------------------- /bots/crystal-rush/Command.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC optimize("O3,inline,omit-frame-pointer,unroll-loops") 2 | #include "Command.h" 3 | #include "Position.h" 4 | #include "Common.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | Command::Command() { type = WAIT; msg = "wait"; score = 0; item = NONE; quest = "wait"; } // default constructor 20 | Command::Command(CommandType _type, Position _target, ItemType _item, string _msg, int _score, string _quest) { 21 | type = _type; target = _target; item = _item; msg = _msg; score = _score; quest = _quest; 22 | } 23 | void Command::move(Position _target, int _score, string _quest) { type = MOVE; target = _target; item = NONE; msg = "move"; score = _score; quest = _quest; } 24 | void Command::dig(Position _target, int _score, string _quest) { type = DIG; target = _target; item = NONE; msg = "dig"; score = _score; quest = _quest; } 25 | void Command::request(ItemType _item, int _score, string _quest) { type = REQUEST; item = _item; msg = "request"; score = _score; target.row = -1; target.col = -1; quest = _quest; } 26 | void Command::wait(string _quest) { type = WAIT; msg = "wait"; score = 0; item = NONE; quest = _quest; } 27 | 28 | bool Command::cmdEq(Command c) { 29 | return type == c.type && target.posEq(c.target) && item == c.item; 30 | } 31 | 32 | std::ostream& operator<<(std::ostream& ioOut, const Command& obj) { 33 | ioOut << obj.type; 34 | if (obj.type == REQUEST) { ioOut << " " << obj.item; } 35 | if (obj.type == MOVE || obj.type == DIG) { ioOut << " " << obj.target; } 36 | // if (msg != "") { ioOut << " " << msg; } 37 | ioOut << " " << obj.quest << " sc=" << obj.score; 38 | return ioOut; 39 | } 40 | -------------------------------------------------------------------------------- /bots/crystal-rush/Command.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMAND_H 2 | #define COMMAND_H 3 | #include "Position.h" 4 | #include "Common.h" 5 | 6 | 7 | 8 | class Command { 9 | public: 10 | 11 | CommandType type; 12 | Position target; 13 | ItemType item; 14 | std::string quest; 15 | std::string msg; 16 | int score; // how good is a command for me 17 | 18 | Command(CommandType _type, Position _target, ItemType _item, std::string _msg, int _score, std::string _quest); 19 | Command(); // default constructor 20 | 21 | void move(Position _target, int _score, std::string _quest); 22 | void dig(Position _target, int _score, std::string _quest); 23 | void request(ItemType _item, int _score, std::string _quest); 24 | void wait(std::string _quest); 25 | 26 | 27 | bool cmdEq(Command c); 28 | 29 | friend std::ostream& operator<<(std::ostream& ioOut, const Command& obj); 30 | 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /bots/crystal-rush/Position.cpp: -------------------------------------------------------------------------------- 1 | #include "Position.h" 2 | 3 | 4 | 5 | 6 | Position::Position(int r, int c) { row = r; col = c; } // constructor 7 | Position::Position() { row = -1; col = -1; } // default constructor 8 | 9 | int Position::dist(int r, int c) { 10 | return abs(row - r) + abs(col - c); 11 | } 12 | 13 | int Position::dist(Position p) { 14 | return abs(row - p.row) + abs(col - p.col); 15 | } 16 | 17 | int Position::distTurns(Position p) { 18 | return 1 + (dist(p) - 1) / 4; 19 | } 20 | int Position::distTurns(int r, int c) { 21 | return 1 + (dist(r, c) - 1) / 4; 22 | } 23 | 24 | bool Position::posEq(Position p) { 25 | return row == p.row && col == p.col; 26 | } 27 | 28 | bool Position::posEq(int r, int c) { 29 | return row == r && col == c; 30 | } 31 | 32 | Position Position::addPos(Position delta) { 33 | return Position(row + delta.row, col + delta.col); 34 | } 35 | 36 | bool Position::onMap() { 37 | return row >= 0 && col >= 0 && row <= 14 && col <= 29; 38 | } 39 | 40 | bool Position::onLand() { 41 | return row >= 0 && col >= 1 && row <= 14 && col <= 29; 42 | } 43 | 44 | bool Position::atHQ() { 45 | return col == 0; 46 | } 47 | 48 | std::ostream& operator<<(std::ostream& ioOut, const Position& obj) { 49 | ioOut << obj.col << " " << obj.row; 50 | return ioOut; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /bots/crystal-rush/Position.h: -------------------------------------------------------------------------------- 1 | #ifndef POSITION_H 2 | #define POSITION_H 3 | 4 | 5 | #include 6 | 7 | class Position { 8 | 9 | public: 10 | 11 | int row, col; 12 | 13 | Position(int r, int c); // constructor 14 | Position(); // default constructor 15 | 16 | int dist(int r, int c); 17 | 18 | int dist(Position p); 19 | 20 | int distTurns(Position p); 21 | int distTurns(int r, int c); 22 | 23 | bool posEq(Position p); 24 | bool posEq(int r, int c); 25 | 26 | Position addPos(Position delta); 27 | 28 | bool onMap(); 29 | bool onLand(); 30 | bool atHQ(); 31 | 32 | 33 | friend std::ostream& operator<<(std::ostream& ioOut, const Position& obj); 34 | }; 35 | 36 | 37 | #endif -------------------------------------------------------------------------------- /bots/crystal-rush/Robot.cpp: -------------------------------------------------------------------------------- 1 | #include "Robot.h" 2 | #include "Position.h" 3 | #include "Command.h" 4 | 5 | 6 | bool Robot::isDead() { return row == -1 && col == -1; } 7 | bool Robot::isAlive() { return !isDead(); } 8 | 9 | void Robot::update(int r, int c, int _item, int _id) { 10 | row = r; 11 | col = c; 12 | id = _id; 13 | switch (_item) { // 14 | case -1: item = NONE; break; 15 | case 2: item = RADAR; break; 16 | case 3: item = TRAP; break; 17 | case 4: item = ORE; break; 18 | } 19 | } 20 | 21 | Position Robot::pos() { 22 | Position p(row, col); 23 | return p; 24 | } 25 | 26 | void Robot::updateS(int r, int c, int _id) { 27 | row = r; 28 | col = c; 29 | id = _id; 30 | } 31 | 32 | void Robot::print() { 33 | std::cerr << "robot " << id << " (" << row << "," << col << ")" << " item=" << item << std::endl; 34 | } 35 | void Robot::printCmd() { 36 | std::cout << commands.at(0) << std::endl; 37 | } 38 | void Robot::printAllCmds() { 39 | for (Command c : commands) { 40 | std::cerr << " - " << c << std::endl; 41 | } 42 | 43 | } 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /bots/crystal-rush/Robot.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBOT_H 2 | #define ROBOT_H 3 | 4 | #include 5 | #include "Position.h" 6 | #include "Command.h" 7 | 8 | class Robot : public Position { 9 | public: 10 | ItemType item; 11 | int id; 12 | std::vector commands; 13 | 14 | bool isDead(); 15 | bool isAlive(); 16 | 17 | void update(int r, int c, int _item, int _id); 18 | Position pos(); 19 | void updateS(int r, int c, int _id); 20 | 21 | void print(); 22 | void printCmd(); 23 | void printAllCmds(); 24 | }; 25 | 26 | #endif 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /bots/crystal-rush/Tile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Tile.h" 4 | #include "Position.h" 5 | 6 | 7 | 8 | void Tile::update(Position p, std::string _ore, bool _hole) { 9 | row = p.row; 10 | col = p.col; 11 | if (_hole == 1) { hole = true; } 12 | // else { hole = false; } 13 | int iore = 0; 14 | if (_ore == "?") { 15 | visible = false; 16 | } 17 | else { 18 | ore = stoi(_ore); 19 | visible = true; 20 | } 21 | } 22 | 23 | int Tile::getState() { 24 | int s = 0; 25 | 26 | if (!visible) { s = s + 4; } 27 | if (!hole) { s = s + 2; } 28 | if (!possibleTrap) { s = s + 1; } 29 | 30 | s = 5 * s + (ore + 1); 31 | 32 | return s; 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /bots/crystal-rush/Tile.h: -------------------------------------------------------------------------------- 1 | #ifndef TILE_H 2 | #define TILE_H 3 | #include "Position.h" 4 | 5 | class Tile : public Position { 6 | public: 7 | int ore; 8 | bool visible; 9 | bool radar; 10 | bool trap; 11 | bool hole; 12 | bool possibleTrap; 13 | void update(Position p, std::string _ore, bool _hole); 14 | int getState(); 15 | }; 16 | 17 | 18 | #endif -------------------------------------------------------------------------------- /bots/cultist-wars/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | 5 | 6 | static constexpr int EMPTY = 0; 7 | static constexpr int WALL = 1; 8 | static constexpr int MYCULTIST = 2; 9 | static constexpr int HISCULTIST = 3; 10 | static constexpr int ME = 4; 11 | static constexpr int HE = 5; 12 | static constexpr int NEUTRALCULTIST = 6; 13 | static constexpr char* MAPTILES[7] = {" ","#","C","E","M","H","N"}; 14 | 15 | static constexpr int CULTIST = 0; 16 | static constexpr int LEADER = 1; 17 | static constexpr int NEUTRAL = 2; 18 | 19 | static constexpr int dRow[4] = {1,-1,0,0}; 20 | static constexpr int dCol[4] = {0,0,1,-1}; 21 | 22 | 23 | static constexpr int nRow = 7; 24 | static constexpr int nCol = 13; 25 | static constexpr char* OWNERS[2][3] = {{"me","him","neutral"},{"him","me","neutral"}}; 26 | static constexpr char* TYPES[2] = {"cultist","leader"}; 27 | static int myId = -1; // 0 - you are the first player, 1 - you are the second player 28 | 29 | int RandomNumber(int N) { 30 | /* generate secret number between 0 and N-1: */ 31 | return rand() % N; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /bots/cultist-wars/Game.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Common.h" 10 | #include "Unit.h" 11 | #include "Move.h" 12 | 13 | class Game { 14 | public: 15 | 16 | int num_of_units; // The total number of units on the board 17 | int battleField[nRow][nCol]; // map of the battle field, no units 18 | int map[nRow][nCol]; // map of the battle field with units 19 | int bfsDist[nRow][nCol]; // distance from me 20 | int damageMap[nRow][nCol]; // damage enemy can inflict 21 | int hitMap[nRow][nCol]; // damage I can inflict 22 | 23 | Unit me; 24 | Unit he; 25 | std::vector myCultists; 26 | std::vector hisCultists; 27 | std::vector neutralCultists; 28 | std::vector moves; 29 | 30 | bool iDieIfIStayPut; 31 | 32 | Game(); 33 | bool amIwinning(); 34 | Move staySafe(Unit u); 35 | Move Charge(Unit u); 36 | void BFS(int row, int col); 37 | void initRead(); 38 | void printMap(); 39 | void readUnits(); 40 | void printUnits(); 41 | bool is(int row, int col, int unitType); 42 | int getId(int row, int col); 43 | void printMoves(); 44 | void listValidMoves(); 45 | bool compareMoves(Move m1, Move m2); 46 | Move getBestMove(); 47 | int getClosestNeutral(int row, int col); 48 | void considerMeMoving(int row, int col); 49 | void considerConverting(int row, int col, int who); 50 | void considerCultistMoving(int row, int col, Unit u); 51 | void considerCultist(Unit c); 52 | int considerShooting(int Srow, int Scol, int Trow, int Tcol); 53 | bool bresenham(int x0, int y0, int x1, int y1); 54 | void considerCultistShooting(Unit u); 55 | void considerMe(); 56 | void createDamageMap(); 57 | void printDamageMap(); 58 | void printHitMap(); 59 | void printMaps(); 60 | Move escapeToSafety(Unit u); 61 | void getDistances(Unit u, int row, int col, int &minDistToNeutralCultist, int &minDistToHisCultist, int &distToHim, int &minDistToSafety); 62 | int getDistFromBFS(int row, int col); 63 | 64 | }; -------------------------------------------------------------------------------- /bots/cultist-wars/Move.cpp: -------------------------------------------------------------------------------- 1 | #include "Move.h" 2 | 3 | Move::Move() { 4 | priority = 0; 5 | order = "WAIT"; 6 | } 7 | 8 | Move::Move(std::string _order, int _priority) { 9 | priority = _priority; 10 | order = _order; 11 | } 12 | 13 | std::ostream& operator<<(std::ostream& ioOut, const Move& obj) { 14 | 15 | ioOut << obj.priority << " " << obj.order; 16 | return ioOut; 17 | } -------------------------------------------------------------------------------- /bots/cultist-wars/Move.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Common.h" 4 | 5 | class Move { 6 | public: 7 | std::string order; // The unit's ID 8 | int priority; 9 | 10 | Move(); 11 | Move(std::string _order, int _priority); 12 | 13 | 14 | friend std::ostream& operator<<(std::ostream& ioOut, const Move& obj); 15 | }; -------------------------------------------------------------------------------- /bots/cultist-wars/Unit.cpp: -------------------------------------------------------------------------------- 1 | #include "Unit.h" 2 | 3 | Unit::Unit() {} // default constructor 4 | 5 | Unit::Unit(int _id, int _type, int _hp, int _row, int _col, int _owner) { 6 | id = _id; 7 | type = _type; 8 | hp = _hp; 9 | row = _row; 10 | col = _col; 11 | owner = _owner; 12 | } 13 | 14 | int Unit::mDistTo(Unit target) { 15 | return abs(row - target.row) + abs(col - target.col); 16 | } 17 | 18 | int Unit::mDistTo(int r, int c) { 19 | return abs(row - r) + abs(col - c); 20 | } 21 | 22 | int Unit::isHere(int _row, int _col) { 23 | if (row == _row && col == _col) { 24 | return true; 25 | } else { 26 | return false; 27 | } 28 | } 29 | 30 | 31 | bool Unit::survivesShootout(int damage, int enemyHP) { 32 | bool s = false; 33 | 34 | int nMe = hp / damage; 35 | if (hp % damage > 0) { nMe++; } 36 | 37 | int nHe = enemyHP / damage; 38 | if (enemyHP % damage > 0) { nHe++; } 39 | 40 | if (nMe < nHe ) { 41 | s = false; 42 | } else { 43 | s = true; 44 | } 45 | 46 | return s; 47 | 48 | } 49 | 50 | std::ostream& operator<<(std::ostream& ioOut, const Unit& obj) { 51 | 52 | ioOut << obj.id << " " << TYPES[obj.type] << " " << obj.hp << " (" << obj.row << "," << obj.col << ") " << OWNERS[myId][obj.owner]; 53 | return ioOut; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /bots/cultist-wars/Unit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Common.h" 4 | 5 | class Unit { 6 | public: 7 | int id; // The unit's ID 8 | int type; // The unit's type: 0 = Cultist, 1 = Cult Leader 9 | int hp; // Health points of the unit 10 | int col; // X coordinate of the unit 11 | int row; // Y coordinate of the unit 12 | int owner; // id of owner player 13 | bool alive; 14 | 15 | Unit(); 16 | Unit(int _id, int _type, int _hp, int _row, int _col, int _owner); 17 | int mDistTo(Unit target); 18 | int isHere(int _row, int _col); 19 | int mDistTo(int r, int c); 20 | bool survivesShootout(int damage, int enemyHP); 21 | 22 | friend std::ostream& operator<<(std::ostream& ioOut, const Unit& obj); 23 | }; -------------------------------------------------------------------------------- /bots/cultist-wars/main.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/ide/puzzle/cultist-wars 2 | 3 | #pragma GCC optimize("O3,inline,omit-frame-pointer,unroll-loops") 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Common.h" 10 | #include "Unit.h" 11 | #include "Game.h" 12 | 13 | using namespace std; 14 | 15 | int main() 16 | { 17 | 18 | Game game; 19 | game.initRead(); 20 | 21 | // game loop 22 | while (1) { 23 | 24 | game.readUnits(); 25 | //game.printMap(); 26 | //game.printUnits(); 27 | game.createDamageMap(); 28 | //game.printDamageMap(); 29 | game.printMaps(); 30 | 31 | game.listValidMoves(); 32 | game.printMoves(); 33 | 34 | // WAIT | unitId MOVE x y | unitId SHOOT target| unitId CONVERT target 35 | cout << game.getBestMove().order << endl; 36 | } 37 | } -------------------------------------------------------------------------------- /bots/fall-challenge-2020/Action.cpp: -------------------------------------------------------------------------------- 1 | #include "Action.h" 2 | 3 | // Position::Position(int r, int c) { row = r; col = c; active = true; } // constructor 4 | Action::Action() { 5 | score = -1000; 6 | type = "REST"; 7 | placeInTome = 0; 8 | times = 1; 9 | } // default constructor 10 | 11 | void Action::Read() { 12 | std::cin >> id >> type >> delta.val[0] >> delta.val[1] >> delta.val[2] >> delta.val[3] >> price >> tomeIndex >> taxCount >> castable >> repeatable; std::cin.ignore(); 13 | } 14 | 15 | void Action::cout() { 16 | // in the first league: BREW | WAIT; later: BREW | CAST [] | LEARN | REST | WAIT 17 | if (type=="BREW" || type=="LEARN") { 18 | std::cout << type << " " << id << " " << type << " " << id << std::endl; 19 | } 20 | if (type=="REST" || type=="WAIT" ) { 21 | std::cout << type << " " << type << std::endl; 22 | } 23 | if (type=="CAST" && times == 1 ) { 24 | std::cout << type << " " << id << " " << type << " " << id << std::endl; 25 | } 26 | if (type=="CAST" && times > 1 ) { 27 | std::cout << type << " " << id << " " << times << " " << type << " " << id << " " << times << std::endl; 28 | } 29 | 30 | } 31 | 32 | bool Action::can(Quad inv) { 33 | Quad after = delta + inv; 34 | 35 | if (type=="BREW") { 36 | if (after.positive()) { 37 | return true; 38 | } else { 39 | return false; 40 | } 41 | } 42 | if (type=="CAST") { 43 | if (after.positive() && after.total() <= 10 && castable ) { 44 | return true; 45 | } else { 46 | return false; 47 | } 48 | } 49 | 50 | if (type=="LEARN") { 51 | if (inv.val[0]>=placeInTome) { 52 | return true; 53 | } else { 54 | return false; 55 | } 56 | } 57 | 58 | return false; 59 | } 60 | 61 | 62 | std::ostream& operator<<(std::ostream& ioOut, const Action& obj) { 63 | 64 | if (obj.type=="BREW") { ioOut << obj.id << " " << obj.type << " " << obj.delta << " " << obj.price;} 65 | else if (obj.type=="CAST") { ioOut << obj.id << " " << obj.type << " " << obj.delta << " " << obj.castable;} 66 | else if (obj.type=="LEARN") { ioOut << obj.id << " " << obj.type << " " << obj.delta << " " << obj.taxCount << " pIt " << obj.placeInTome;} 67 | else { ioOut << " " << obj.type;} 68 | 69 | return ioOut; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /bots/fall-challenge-2020/Action.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Quad.h" 5 | 6 | class Action { 7 | public: 8 | int id; 9 | std::string type; 10 | Quad delta; 11 | int price; // the price in rupees if this is a potion 12 | int tomeIndex; // in the first two leagues: always 0; later: the index in the tome if this is a tome spell, equal to the read-ahead tax 13 | int taxCount; // in the first two leagues: always 0; later: the amount of taxed tier-0 ingredients you gain from learning this spell 14 | bool castable; // in the first league: always 0; later: 1 if this is a castable player spell 15 | bool repeatable; // for the first two leagues: always 0; later: 1 if this is a repeatable player spell 16 | int score; 17 | int placeInTome; // how much must I pay to learn this spell 18 | int times; // how many times repeatable spell 19 | 20 | Action(); 21 | void Read(); 22 | void cout(); 23 | bool can(Quad inv); 24 | 25 | friend std::ostream& operator<<(std::ostream& ioOut, const Action& obj); 26 | }; -------------------------------------------------------------------------------- /bots/fall-challenge-2020/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | 5 | static constexpr int SIMPLE = 0; 6 | static constexpr int ADVANCED = 1; 7 | 8 | 9 | 10 | int RandomNumber(int N) { 11 | /* generate secret number between 0 and N-1: */ 12 | return rand() % N; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /bots/fall-challenge-2020/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Quad.h" 5 | #include "Action.h" 6 | #include "Player.h" 7 | #include "Common.h" 8 | 9 | class Game { 10 | public: 11 | 12 | std::vector recipes; 13 | std::vector spells; 14 | std::vector actions; 15 | std::vector tome; 16 | Player me,he; 17 | 18 | Game(); 19 | void read(); 20 | std::vector listAvailableActions(Player p); 21 | void play(Player& p, Action a); 22 | int eval(Player p, int startRupees); 23 | 24 | }; -------------------------------------------------------------------------------- /bots/fall-challenge-2020/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player() {} // default constructor 4 | 5 | void Player::Read() { 6 | std::cin >> inv.val[0] >> inv.val[1] >> inv.val[2] >> inv.val[3] >> rupees; std::cin.ignore(); 7 | } 8 | 9 | 10 | std::ostream& operator<<(std::ostream& ioOut, const Player& obj) { 11 | 12 | ioOut << obj.inv << " " << obj.rupees; 13 | return ioOut; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /bots/fall-challenge-2020/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Quad.h" 5 | 6 | 7 | class Player { 8 | public: 9 | int id; 10 | Quad inv; 11 | int rupees; 12 | 13 | Player(); 14 | void Read(); 15 | 16 | friend std::ostream& operator<<(std::ostream& ioOut, const Player& obj); 17 | }; -------------------------------------------------------------------------------- /bots/fall-challenge-2020/Quad.cpp: -------------------------------------------------------------------------------- 1 | #include "Quad.h" 2 | 3 | // Position::Position(int r, int c) { row = r; col = c; active = true; } // constructor 4 | Quad::Quad() {} // default constructor 5 | 6 | int Quad::total() { 7 | return val[0]+val[1]+val[2]+val[3]; 8 | } 9 | 10 | int Quad::negTotal() { 11 | int nt = 0; 12 | if (val[0]<0) { nt = nt + val[0]; } 13 | if (val[1]<0) { nt = nt + val[1]; } 14 | if (val[2]<0) { nt = nt + val[2]; } 15 | if (val[3]<0) { nt = nt + val[3]; } 16 | return nt; 17 | } 18 | 19 | 20 | bool Quad::positive() { 21 | return val[0] >= 0 && val[1] >= 0 && val[2] >= 0 && val[3] >= 0; 22 | } 23 | 24 | 25 | std::ostream& operator<<(std::ostream& ioOut, const Quad& obj) { 26 | 27 | ioOut << "(" << obj.val[0]<< " " << obj.val[1]<< " " << obj.val[2]<< " " << obj.val[3] << ")"; 28 | return ioOut; 29 | } 30 | 31 | 32 | // Overload + operator 33 | Quad Quad::operator+(const Quad& q) { 34 | Quad res; 35 | res.val[0] = this->val[0] + q.val[0]; 36 | res.val[1] = this->val[1] + q.val[1]; 37 | res.val[2] = this->val[2] + q.val[2]; 38 | res.val[3] = this->val[3] + q.val[3]; 39 | return res; 40 | } 41 | 42 | 43 | // Overload * operator 44 | Quad Quad::operator*(const int& i) { 45 | Quad res; 46 | res.val[0] = this->val[0] * i; 47 | res.val[1] = this->val[1] * i; 48 | res.val[2] = this->val[2] * i; 49 | res.val[3] = this->val[3] * i; 50 | return res; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /bots/fall-challenge-2020/Quad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | 5 | class Quad { 6 | public: 7 | int val[4]; 8 | 9 | Quad(); 10 | int total(); 11 | bool positive(); 12 | int negTotal(); 13 | 14 | friend std::ostream& operator<<(std::ostream& ioOut, const Quad& obj); 15 | Quad operator+(const Quad& q); 16 | Quad operator*(const int& i); 17 | }; -------------------------------------------------------------------------------- /bots/keep-off-the-grass/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | 5 | 6 | static constexpr int maxHeight = 7; 7 | static constexpr int maxWidth = 15; 8 | 9 | static constexpr int MINE = 1; // 1 if you control this cell. 10 | static constexpr int HIS = 0; // 0 if your opponent controls this cell. 11 | static constexpr int NEUTRAL = -1; // -1 otherwise. 12 | 13 | static constexpr char* OWNERS[3] = {"neutral","his","mine"}; 14 | static constexpr char* TF[2] = {"F","T"}; 15 | 16 | int RandomNumber(int N) { 17 | /* generate secret number between 0 and N-1: */ 18 | return rand() % N; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /bots/keep-off-the-grass/Map.cpp: -------------------------------------------------------------------------------- 1 | #include "Map.h" 2 | 3 | Map::Map() { } 4 | 5 | void Map::read() { 6 | for (int i = 0; i < height; i++) { 7 | for (int j = 0; j < width; j++) { 8 | tiles[i][j].read(); 9 | std::cerr << "(" << i << "," << j << ") " << tiles[i][j] << std::endl; 10 | } 11 | } 12 | } 13 | 14 | void Map::readWH() { 15 | std::cin >> width >> height; std::cin.ignore(); 16 | } -------------------------------------------------------------------------------- /bots/keep-off-the-grass/Map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Common.h" 4 | #include "Tile.h" 5 | 6 | class Map { 7 | 8 | public: 9 | 10 | int width; 11 | int height; 12 | 13 | Tile tiles[maxHeight][maxWidth]; 14 | 15 | Map(); 16 | void read(); 17 | void readWH(); 18 | 19 | }; -------------------------------------------------------------------------------- /bots/keep-off-the-grass/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player() { } -------------------------------------------------------------------------------- /bots/keep-off-the-grass/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Common.h" 4 | #include "Tile.h" 5 | 6 | class Player { 7 | 8 | public: 9 | 10 | int matter; 11 | Player(); 12 | 13 | }; -------------------------------------------------------------------------------- /bots/keep-off-the-grass/Tile.cpp: -------------------------------------------------------------------------------- 1 | #include "Tile.h" 2 | 3 | Tile::Tile() { } 4 | 5 | void Tile::read() { 6 | std::cin >> scrap_amount >> owner >> units >> recycler >> can_build >> can_spawn >> in_range_of_recycler; std::cin.ignore(); 7 | } 8 | 9 | std::ostream& operator<<(std::ostream& ioOut, const Tile& obj) { 10 | 11 | ioOut << obj.scrap_amount << " " << OWNERS[obj.owner+1] << " " << obj.units << " " << TF[obj.recycler] << " " << TF[obj.can_build] << " " << TF[obj.can_spawn] << " " << TF[obj.in_range_of_recycler]; 12 | return ioOut; 13 | } -------------------------------------------------------------------------------- /bots/keep-off-the-grass/Tile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Common.h" 4 | 5 | class Tile { 6 | 7 | public: 8 | int scrap_amount; 9 | int owner; // 1 = me, 0 = foe, -1 = neutral 10 | int units; 11 | bool recycler; 12 | bool can_build; 13 | bool can_spawn; 14 | bool in_range_of_recycler; 15 | 16 | Tile(); 17 | void read(); 18 | 19 | friend std::ostream& operator<<(std::ostream& ioOut, const Tile& obj); 20 | 21 | }; -------------------------------------------------------------------------------- /bots/keep-off-the-grass/main.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/ide/challenge/fall-challenge-2022 2 | 3 | #pragma GCC optimize("O3,inline,omit-frame-pointer,unroll-loops") 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Common.h" 10 | #include "Map.h" 11 | #include "Player.h" 12 | 13 | using namespace std; 14 | 15 | 16 | int main() 17 | { 18 | 19 | Player me; 20 | Player he; 21 | 22 | Map map; 23 | map.readWH(); 24 | 25 | // game loop 26 | while (1) { 27 | 28 | cin >> me.matter >> he.matter; cin.ignore(); 29 | cerr << me.matter << " " << he.matter << endl; 30 | 31 | map.read(); 32 | cout << "WAIT" << endl; 33 | } 34 | } -------------------------------------------------------------------------------- /bots/lava-runners/Bomb.cpp: -------------------------------------------------------------------------------- 1 | #include "Bomb.h" 2 | 3 | Bomb::Bomb() { } // default constructor 4 | 5 | Bomb::Bomb(int row_, int col_, int time_before_explosion_) { 6 | 7 | row = row_; 8 | col = col_; 9 | time_before_explosion = time_before_explosion_; 10 | } 11 | 12 | void Bomb::read() { 13 | cin >> col >> row >> time_before_explosion; cin.ignore(); 14 | } 15 | 16 | std::ostream& operator<<(std::ostream& ioOut, const Bomb& obj) { 17 | ioOut << "bomb:" << obj.time_before_explosion << " (" << obj.row << "," << obj.col << ")"; 18 | return ioOut; 19 | } -------------------------------------------------------------------------------- /bots/lava-runners/Bomb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Bomb { 5 | public: 6 | 7 | int col; // bomb x coordinate 8 | int row; // bomb y coordinate 9 | int time_before_explosion; // time in frame before the bomb explodes 10 | 11 | Bomb(); 12 | Bomb(int row_, int col_, int time_before_explosion_); 13 | void read(); 14 | 15 | friend std::ostream& operator<<(std::ostream& ioOut, const Bomb& obj); 16 | 17 | }; -------------------------------------------------------------------------------- /bots/lava-runners/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | using namespace std; 9 | 10 | static int EGGS = 1; 11 | static int EMPTY = 0; 12 | static int CRYSTAL = 2; 13 | -------------------------------------------------------------------------------- /bots/lava-runners/Move.cpp: -------------------------------------------------------------------------------- 1 | #include "Move.h" 2 | 3 | Move::Move() { } // default constructor 4 | 5 | Move::Move(string ukaz_, int score_) { 6 | ukaz = ukaz_; 7 | score = score_; 8 | } 9 | 10 | std::ostream& operator<<(std::ostream& ioOut, const Move& obj) { 11 | ioOut << obj.ukaz; 12 | return ioOut; 13 | } -------------------------------------------------------------------------------- /bots/lava-runners/Move.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Move { 5 | public: 6 | 7 | string ukaz; 8 | int score; 9 | 10 | Move(); 11 | Move(string ukaz_, int score_); 12 | 13 | friend std::ostream& operator<<(std::ostream& ioOut, const Move& obj); 14 | 15 | }; -------------------------------------------------------------------------------- /bots/lava-runners/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player() { } // default constructor 4 | 5 | Player::Player(int id_, int row_, int col_, int mana_) { 6 | id = id_; 7 | row = row_; 8 | col = col_; 9 | mana = mana_; 10 | } 11 | 12 | void Player::read() { 13 | cin >> id >> col >> row >> mana; cin.ignore(); 14 | } 15 | 16 | std::ostream& operator<<(std::ostream& ioOut, const Player& obj) { 17 | ioOut << "ID:" << obj.id << " (" << obj.row << "," << obj.col << "), mana =" << obj.mana; 18 | return ioOut; 19 | } -------------------------------------------------------------------------------- /bots/lava-runners/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Player { 5 | public: 6 | 7 | int id; // id of your player 8 | int row; // x position of your player 9 | int col; // y position of your player 10 | int mana; // amount of mana that your player has 11 | 12 | Player(); 13 | Player(int id_, int row_, int col_, int mana_); 14 | void read(); 15 | 16 | friend std::ostream& operator<<(std::ostream& ioOut, const Player& obj); 17 | 18 | }; -------------------------------------------------------------------------------- /bots/lava-runners/Tile.cpp: -------------------------------------------------------------------------------- 1 | #include "Tile.h" 2 | 3 | Tile::Tile() { } // default constructor 4 | 5 | void Tile::read( int row_, int col_) { 6 | 7 | cin >> dying >> life >> strong; cin.ignore(); 8 | row = row_; 9 | col = col_; 10 | willExplode = false; 11 | } 12 | 13 | std::ostream& operator<<(std::ostream& ioOut, const Tile& obj) { 14 | ioOut << "tile:" << obj.life << " (" << obj.row << "," << obj.col << ")"; 15 | return ioOut; 16 | } -------------------------------------------------------------------------------- /bots/lava-runners/Tile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Tile { 5 | public: 6 | 7 | int dying; // 1 if the current cell is decaying or dead, 0 otherwise 8 | int life; // the current cell life, 4 is the healthiest, 0 is dead 9 | int strong; // 1 if the cell can only be destroyed with a bomb, 0 otherwise 10 | int row; 11 | int col; 12 | bool willExplode; 13 | 14 | Tile(); 15 | void read(int row_, int col_); 16 | 17 | friend std::ostream& operator<<(std::ostream& ioOut, const Tile& obj); 18 | 19 | }; -------------------------------------------------------------------------------- /bots/ocean-of-code/Common.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /bots/ocean-of-code/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include /* srand, rand */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static constexpr int water = 0; 9 | static constexpr int land = 1; 10 | static constexpr int width = 15; 11 | static constexpr int height = 15; 12 | 13 | 14 | 15 | int RandomNumber(int N) { 16 | /* generate secret number between 0 and N-1: */ 17 | return rand() % N; 18 | } 19 | 20 | 21 | std::vector split(std::string stringToBeSplitted, std::string delimeter) 22 | { 23 | std::vector splittedString; 24 | int startIndex = 0; 25 | int endIndex = 0; 26 | while( (endIndex = stringToBeSplitted.find(delimeter, startIndex)) < stringToBeSplitted.size() ) 27 | { 28 | std::string val = stringToBeSplitted.substr(startIndex, endIndex - startIndex); 29 | splittedString.push_back(val); 30 | startIndex = endIndex + delimeter.size(); 31 | } 32 | if(startIndex < stringToBeSplitted.size()) 33 | { 34 | std::string val = stringToBeSplitted.substr(startIndex); 35 | splittedString.push_back(val); 36 | } 37 | return splittedString; 38 | } 39 | 40 | std::string reverseDirection(std::string dir) { 41 | std::string reverse = ""; 42 | 43 | if (dir == "N" ) { reverse = "S"; } 44 | if (dir == "S" ) { reverse = "N"; } 45 | if (dir == "E" ) { reverse = "W"; } 46 | if (dir == "W" ) { reverse = "E"; } 47 | 48 | return reverse; 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /bots/ocean-of-code/DamagePattern.cpp: -------------------------------------------------------------------------------- 1 | #include "DamagePattern.h" 2 | 3 | DamagePattern::DamagePattern() { pattern.clear(); } // default constructor 4 | 5 | void DamagePattern::add(std::vector dp) { 6 | 7 | for (Position p : dp) { 8 | bool found = false; 9 | for (Position e : pattern) { 10 | if (e.row == p.row && e.col == p.col) { found = true;} 11 | } 12 | if (!found) { pattern.push_back(p); } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /bots/ocean-of-code/DamagePattern.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Position.h" 4 | #include "Map.h" 5 | #include "Common.h" 6 | 7 | class DamagePattern { 8 | public: 9 | 10 | DamagePattern(); // def. const. 11 | std::vector pattern; 12 | void add(std::vector dp); 13 | 14 | }; 15 | -------------------------------------------------------------------------------- /bots/ocean-of-code/Enemy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Position.h" 4 | #include "Map.h" 5 | #include "Common.h" 6 | #include "DamagePattern.h" 7 | #include "Explosion.h" 8 | 9 | class Enemy { 10 | public: 11 | 12 | std::vector enemy; 13 | int nPossiblePositions; 14 | Position position; 15 | std::string lastDir; 16 | int lastLife; 17 | int nLostLifes; 18 | 19 | void reset(Map grid); 20 | void applyOrders(std::string orders, Map grid, Position lastTorpedoExplosion, bool firedTorpedoLastMove, Position lastMineExplosion, bool firedMineLastMove); 21 | void printActive(); 22 | void activate(std::vector nodesToActivate, Map grid); 23 | std::vector getTorpedoOrigin(Map grid, Position myLoc); 24 | std::vector getHisExplosions(std::vector ukazi); 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /bots/ocean-of-code/Explosion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Position.h" 5 | #include "Tile.h" 6 | #include "Map.h" 7 | #include "Enemy.h" 8 | #include "Common.h" 9 | 10 | int torpedoBeforeMove = 0; 11 | int torpedoAfterMove = 1; 12 | int mineBeforeMove = 2; 13 | int mineAfterMove = 3; 14 | std::string exTypeDesc[] = {"before","after","mine"}; 15 | 16 | class Explosion { 17 | 18 | public: 19 | 20 | int type; 21 | Position pos; 22 | int damageToMe; 23 | int nHisPossiblePositions; // damage will be done to number of his possible positions 24 | float hitProbability; 25 | 26 | 27 | Explosion(int t, int r, int c); // constructor 28 | Explosion(int t, Position p); // constructor 29 | Explosion(); // constructor 30 | int getDamageToLoc(Position p); 31 | void printCerr(); 32 | int getEnemyHits(std::vector enemy); 33 | std::string getOrders(std::string moveOrders); 34 | 35 | }; -------------------------------------------------------------------------------- /bots/ocean-of-code/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Position.h" 5 | #include "Tile.h" 6 | #include "Map.h" 7 | #include "Enemy.h" 8 | #include "Common.h" 9 | #include "Explosion.h" 10 | 11 | 12 | class Game { 13 | 14 | public: 15 | int myId; 16 | int width; 17 | int height; 18 | Position myLoc; 19 | Map grid; 20 | Enemy enemy; 21 | 22 | bool firedTorpedoLastMove; 23 | bool firedMineLastMove; 24 | Position lastTorpedoExplosion; 25 | Position lastMineExplosion; 26 | 27 | int x; 28 | int y; 29 | int myLife; 30 | int oppLife; 31 | int torpedoCooldown; 32 | int sonarCooldown; 33 | int silenceCooldown; 34 | int mineCooldown; 35 | std::string sonarResult; 36 | std::string opponentOrders; 37 | 38 | std::vector opponentMovement; 39 | std::vector exMines; 40 | std::vector exTorpedo; 41 | 42 | void readMap(); 43 | void readInitial(); 44 | void setInitialPosition(); 45 | void readTurn(); 46 | std::vector getTorpedoTargets(); 47 | std::vector getTorpedoSafeTargets(std::vector List); 48 | void printList(std::vector list); 49 | std::vector getPaths(Position start); 50 | std::string getDirection(); 51 | void updateMyLoc(std::string dir); 52 | void setTorpedoStrikes(std::string dir); 53 | Explosion getBestTarget(std::vector targets); 54 | Position getInitialLongest(); 55 | std::vector getPathsStart(Position start); 56 | Position getInitialCenter(); 57 | 58 | }; -------------------------------------------------------------------------------- /bots/ocean-of-code/Map.cpp: -------------------------------------------------------------------------------- 1 | #include "Map.h" 2 | #include "Common.h" 3 | 4 | void Map::addTile(int row, int col, int type) { 5 | Tile t(row,col,type); 6 | tiles.push_back(t); 7 | }; 8 | 9 | void Map::init() { 10 | tiles.clear(); 11 | }; 12 | 13 | int Map::getID(int row, int col) { 14 | return row*width+col; 15 | }; 16 | 17 | Tile Map::getTile(int row, int col) { 18 | return tiles[getID(row,col)]; 19 | }; 20 | 21 | Tile Map::getTile(Position p) { 22 | return tiles[getID(p.row,p.col)]; 23 | }; 24 | 25 | 26 | Tile Map::getTile(int id) { 27 | return tiles[id]; 28 | }; 29 | 30 | void Map::setVisited(Position p) { 31 | tiles[getID(p.row,p.col)].visited = true; 32 | }; 33 | 34 | void Map::setCnt(Position p, int c) { 35 | tiles[getID(p.row,p.col)].cnt = c; 36 | }; 37 | 38 | void Map::findNeighbours() { 39 | for (Tile &t : tiles) { 40 | 41 | if (t.isWater() ) { 42 | if (t.north()) { if (tiles[getID(t.row-1,t.col)].isWater()) { t.neighbours.push_back(getID(t.row-1,t.col)); } } 43 | if (t.south()) { if (tiles[getID(t.row+1,t.col)].isWater()) { t.neighbours.push_back(getID(t.row+1,t.col)); } } 44 | if (t.east()) { if (tiles[getID(t.row,t.col+1)].isWater()) { t.neighbours.push_back(getID(t.row,t.col+1)); } } 45 | if (t.west()) { if (tiles[getID(t.row,t.col-1)].isWater()) { t.neighbours.push_back(getID(t.row,t.col-1)); } } 46 | } 47 | 48 | } 49 | }; 50 | 51 | void Map::clearVisited() { 52 | for (Tile &t : tiles) { 53 | t.visited = false; 54 | } 55 | }; 56 | 57 | 58 | Position Map::getRandomPosition() { 59 | Position l; 60 | 61 | l.row = 7; 62 | l.col = 7; 63 | 64 | while (!getTile(l.row,l.col).isFree()) { 65 | l.row = RandomNumber(height); 66 | l.col = RandomNumber(width); 67 | } 68 | 69 | return l; 70 | } -------------------------------------------------------------------------------- /bots/ocean-of-code/Map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Position.h" 4 | #include "Tile.h" 5 | 6 | 7 | class Map { 8 | public: 9 | 10 | std::vector tiles; 11 | void addTile(int row, int col, int type); 12 | void init(); 13 | void findNeighbours(); 14 | Tile getTile(int row, int col); 15 | int getID(int row, int col); 16 | Tile getTile(int id); 17 | Tile getTile(Position p); 18 | void clearVisited(); 19 | Position getRandomPosition(); 20 | void setVisited(Position p); 21 | void setCnt(Position p, int c); 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /bots/ocean-of-code/Position.h: -------------------------------------------------------------------------------- 1 | #ifndef POSITION_H 2 | #define POSITION_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | class Position { 9 | 10 | public: 11 | int row, col; 12 | bool active; 13 | 14 | Position(int r, int c); // constructor 15 | Position(); // default constructor 16 | Position(std::string dir); 17 | 18 | void add(Position p); 19 | bool east(); 20 | bool west(); 21 | bool north(); 22 | bool south(); 23 | void moveInDirection(std::string dir); 24 | bool onMap(); 25 | int getSector(); 26 | std::vector getDamagePattern(); 27 | int manhattan(Position p); 28 | 29 | friend std::ostream& operator<<(std::ostream& ioOut, const Position& obj); 30 | }; 31 | 32 | 33 | #endif -------------------------------------------------------------------------------- /bots/ocean-of-code/Tile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Tile.h" 4 | #include "Position.h" 5 | #include "Common.h" 6 | 7 | Tile::Tile(int r, int c, int t) { row = r; col = c; visited = false; type = t; neighbours.clear(); } // constructor 8 | Tile::Tile() { row = -1; col = -1; visited = false; type = water; neighbours.clear(); } // default constructor 9 | 10 | 11 | bool Tile::isFree() { 12 | return visited == false && type == water; 13 | } 14 | 15 | bool Tile::isWater() { 16 | return type == water; 17 | } 18 | 19 | int Tile::getID() { 20 | return row*width+col; 21 | }; 22 | 23 | Position Tile::getPosition() { 24 | return Position(row,col); 25 | } 26 | 27 | std::string Tile::getDirection(int r, int c) { 28 | 29 | std::string dir = ""; 30 | if (r == row-1) { dir="N"; } 31 | if (r == row+1) { dir="S"; } 32 | if (c == col-1) { dir="W"; } 33 | if (c == col+1) { dir="E"; } 34 | 35 | return dir; 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /bots/ocean-of-code/Tile.h: -------------------------------------------------------------------------------- 1 | #ifndef TILE_H 2 | #define TILE_H 3 | #include 4 | #include "Position.h" 5 | 6 | 7 | class Tile : public Position { 8 | public: 9 | 10 | int type; 11 | bool visited; 12 | int cnt; 13 | std::vector neighbours; 14 | 15 | Tile(int r, int c, int t); // constructor 16 | Tile(); // default constructor 17 | 18 | bool isFree(); 19 | bool isWater(); 20 | int getID(); 21 | std::string getDirection(int r, int c); 22 | Position getPosition(); 23 | }; 24 | 25 | 26 | #endif -------------------------------------------------------------------------------- /bots/olymbits/Archery.cpp: -------------------------------------------------------------------------------- 1 | #include "Archery.h" 2 | 3 | Archery::Archery() 4 | { 5 | Player p; 6 | players.push_back(p); 7 | players.push_back(p); 8 | players.push_back(p); 9 | } 10 | 11 | void Archery::read() 12 | { 13 | int reg_6; 14 | std::cin >> gpu >> players[0].x >> players[0].y >> players[1].x >> players[1].y >> players[2].x >> players[2].y >> reg_6; std::cin.ignore(); 15 | 16 | } 17 | 18 | void Archery::setScores(int me, Score& s) 19 | { 20 | 21 | int windSpeed = gpu[0] - '0'; 22 | // std::cerr << "ws = " << windSpeed << std::endl; 23 | 24 | 25 | // right 26 | int xx = players[me].x; 27 | int yy = players[me].y; 28 | xx = xx + windSpeed; 29 | s.a[RIGHT] = xx*xx + yy*yy; 30 | 31 | // left 32 | xx = players[me].x; 33 | yy = players[me].y; 34 | xx = xx - windSpeed; 35 | s.a[LEFT] = xx*xx + yy*yy; 36 | 37 | // up 38 | xx = players[me].x; 39 | yy = players[me].y; 40 | yy = yy - windSpeed; 41 | s.a[UP] = xx*xx + yy*yy; 42 | 43 | // down 44 | xx = players[me].x; 45 | yy = players[me].y; 46 | yy = yy + windSpeed; 47 | s.a[DOWN] = xx*xx + yy*yy; 48 | 49 | // Define a vector of pairs 50 | std::vector> vec = { 51 | {s.a[RIGHT], RIGHT}, 52 | {s.a[LEFT], LEFT}, 53 | {s.a[UP], UP}, 54 | {s.a[DOWN], DOWN} 55 | }; 56 | // Sort the vector based on the first element of the pair (the integer) 57 | std::sort(vec.begin(), vec.end()); 58 | 59 | // Output the sorted vector 60 | int i = -1; 61 | for (const auto& pair : vec) { 62 | i++; 63 | s.a[pair.second] = 4 - i; 64 | //std::cerr << pair.first << ": " << pair.second << std::endl; 65 | } 66 | } -------------------------------------------------------------------------------- /bots/olymbits/Archery.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Player.h" 4 | #include "Score.h" 5 | 6 | class Archery { 7 | public: 8 | 9 | std::vector players; 10 | std::string gpu; 11 | 12 | Archery(); 13 | void read(); 14 | void setScores(int me, Score& s); 15 | 16 | }; -------------------------------------------------------------------------------- /bots/olymbits/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | constexpr int RIGHT = 0; 11 | constexpr int LEFT = 1; 12 | constexpr int UP = 2; 13 | constexpr int DOWN = 3; 14 | 15 | 16 | -------------------------------------------------------------------------------- /bots/olymbits/Diving.cpp: -------------------------------------------------------------------------------- 1 | #include "Diving.h" 2 | 3 | Diving::Diving() 4 | { 5 | Player p; 6 | players.push_back(p); 7 | players.push_back(p); 8 | players.push_back(p); 9 | } 10 | 11 | void Diving::read() 12 | { 13 | int reg_6; 14 | std::cin >> gpu >> players[0].points >> players[1].points >> players[2].points >> players[0].combo >> players[1].combo >> players[2].combo >> reg_6; std::cin.ignore(); 15 | 16 | } 17 | 18 | void Diving::setScores(int me, Score& s) 19 | { 20 | 21 | std::string goal = gpu.substr(0, 1); 22 | 23 | s.d[LEFT] = 0; 24 | s.d[RIGHT] = 0; 25 | s.d[UP] = 0; 26 | s.d[DOWN] = 0; 27 | 28 | if ( goal == "R" ) 29 | { 30 | s.d[RIGHT] = 3; 31 | } 32 | 33 | if ( goal == "L" ) 34 | { 35 | s.d[LEFT] = 3; 36 | } 37 | 38 | if ( goal == "U" ) 39 | { 40 | s.d[UP] = 3; 41 | } 42 | 43 | if ( goal == "D" ) 44 | { 45 | s.d[DOWN] = 3; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /bots/olymbits/Diving.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Player.h" 4 | #include "Score.h" 5 | 6 | 7 | class Diving { 8 | public: 9 | 10 | std::vector players; 11 | std::string gpu; 12 | int turnsLeft; 13 | 14 | Diving(); 15 | void read(); 16 | void setScores(int me, Score& s); 17 | }; -------------------------------------------------------------------------------- /bots/olymbits/Hurdles.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Player.h" 4 | #include "Score.h" 5 | 6 | class Hurdles { 7 | public: 8 | 9 | std::vector players; 10 | std::string gpu; 11 | std::string cmd; 12 | int length; 13 | 14 | 15 | Hurdles(); 16 | void read(); 17 | void setCommand(int me); 18 | bool stunIfLeft(int me); 19 | bool stunIfUp(int me); 20 | bool stunIfDown(int me); 21 | bool stunIfRight(int me); 22 | void setScores(int me, Score& s); 23 | 24 | }; -------------------------------------------------------------------------------- /bots/olymbits/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player() 4 | { 5 | stunTimer = -1; 6 | position = -1; 7 | x = -1; 8 | y = -1; 9 | spaces = -1; 10 | risk = -1; 11 | points = -1; 12 | combo = -1; 13 | } 14 | 15 | void Player::print() 16 | { 17 | std::cerr << "p = " << position << ", st = " << stunTimer << "x = " << x << ", y = " << y << "sp = " << spaces << ", r = " << risk << "p = " << points << ", c = " << combo << std::endl; 18 | } 19 | 20 | void Player::setScore() 21 | { 22 | score = silver + gold * 3; 23 | } 24 | 25 | bool Player::stunned() 26 | { 27 | if (stunTimer > 0 ) 28 | { 29 | return true; 30 | } 31 | else 32 | { 33 | return false; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /bots/olymbits/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Player 5 | { 6 | public: 7 | int position; // Hrudles 8 | int x; // Archery 9 | int y; // Archery 10 | int stunTimer; 11 | int gold; 12 | int silver; 13 | int bronze; 14 | int score; 15 | int spaces; 16 | int risk; 17 | int points; 18 | int combo; 19 | 20 | Player(); 21 | void print(); 22 | void setScore(); 23 | bool stunned(); 24 | 25 | }; -------------------------------------------------------------------------------- /bots/olymbits/Score.cpp: -------------------------------------------------------------------------------- 1 | #include "Score.h" 2 | 3 | Score::Score() 4 | { 5 | cmdNames[0] = "RIGHT"; 6 | cmdNames[1] = "LEFT"; 7 | cmdNames[2] = "UP"; 8 | cmdNames[3] = "DOWN"; 9 | for (int i = 0; i<4; i++) 10 | { 11 | h[i] = 0; 12 | a[i] = 0; 13 | s[i] = 0; 14 | d[i] = 0; 15 | } 16 | } 17 | 18 | std::string Score::getCmd() 19 | { 20 | int total[4]; 21 | std::string cmd = ""; 22 | for (int i = 0; i<4; i++) 23 | { 24 | total[i] = h[i] + a[i] + s[i] + d[i]; 25 | std::cerr << h[i]<< " " << a[i]<< " " << s[i]<< " " << d[i]<< " " << total[i]<< " " << cmdNames[i] << std::endl; 26 | } 27 | int topScore = - 1000; 28 | for (int i = 0; i<4; i++) 29 | { 30 | if (total[i] > topScore) 31 | { 32 | topScore = total[i]; 33 | cmd = cmdNames[i]; 34 | } 35 | } 36 | 37 | return cmd; 38 | 39 | } -------------------------------------------------------------------------------- /bots/olymbits/Score.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Score 5 | { 6 | public: 7 | std::string cmdNames[4]; 8 | int h[4]; 9 | int a[4]; 10 | int s[4]; 11 | int d[4]; 12 | 13 | 14 | Score(); 15 | std::string getCmd(); 16 | 17 | }; -------------------------------------------------------------------------------- /bots/olymbits/Skating.cpp: -------------------------------------------------------------------------------- 1 | #include "Skating.h" 2 | 3 | Skating::Skating() 4 | { 5 | Player p; 6 | players.push_back(p); 7 | players.push_back(p); 8 | players.push_back(p); 9 | } 10 | 11 | void Skating::read() 12 | { 13 | int reg_6; 14 | std::cin >> gpu >> players[0].spaces >> players[1].spaces >> players[2].spaces >> players[0].risk >> players[1].risk >> players[2].risk >> turnsLeft; std::cin.ignore(); 15 | 16 | } 17 | 18 | int Skating::getDir(std::string s) 19 | { 20 | if ( s == "R" ) 21 | { 22 | return RIGHT; 23 | } 24 | if ( s == "L" ) 25 | { 26 | return LEFT; 27 | } 28 | if ( s == "U" ) 29 | { 30 | return UP; 31 | } 32 | if ( s == "D" ) 33 | { 34 | return DOWN; 35 | } 36 | return -1; 37 | } 38 | 39 | 40 | void Skating::setScores(int me, Score& s) 41 | { 42 | 43 | std::string goal = gpu.substr(0, 1); 44 | 45 | s.s[LEFT] = 0; 46 | s.s[RIGHT] = 0; 47 | s.s[UP] = 0; 48 | s.s[DOWN] = 0; 49 | 50 | s.s[getDir(gpu.substr(0, 1))] = 3; 51 | s.s[getDir(gpu.substr(1, 1))] = 4; 52 | s.s[getDir(gpu.substr(2, 1))] = 2; 53 | s.s[getDir(gpu.substr(3, 1))] = 1; 54 | 55 | 56 | } -------------------------------------------------------------------------------- /bots/olymbits/Skating.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Player.h" 4 | #include "Score.h" 5 | 6 | 7 | class Skating { 8 | public: 9 | 10 | std::vector players; 11 | std::string gpu; 12 | int turnsLeft; 13 | 14 | Skating(); 15 | void read(); 16 | void setScores(int me, Score& s); 17 | int getDir(std::string s); 18 | 19 | }; -------------------------------------------------------------------------------- /bots/seabed-security/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | static int LIGHT = 2000*2000; 11 | static int SCANNER = 800*800; 12 | static int CRYSTAL = 2; 13 | static int WIDTH = 10000; 14 | static int HEIGHT = 10000; -------------------------------------------------------------------------------- /bots/seabed-security/Drone.cpp: -------------------------------------------------------------------------------- 1 | #include "Drone.h" 2 | 3 | Drone::Drone() { } // default constructor 4 | 5 | 6 | void Drone::read() { 7 | cin >> id >> col >> row >> emergency >> battery; cin.ignore(); 8 | 9 | centerTL.row = row / 2; 10 | centerTL.col = col / 2; 11 | 12 | centerTR.row = row / 2; 13 | centerTR.col = col + (WIDTH - col) / 2; 14 | 15 | centerBL.row = row + (HEIGHT - row) / 2; 16 | centerBL.col = col / 2; 17 | 18 | centerBR.row = row + (HEIGHT - row) / 2; 19 | centerBR.col = col + (WIDTH - col) / 2; 20 | 21 | } 22 | 23 | int Drone::dist2(int r, int c) 24 | { 25 | return (r - row)*(r - row) + (c - col)*(c - col); 26 | } 27 | 28 | std::ostream& operator<<(std::ostream& ioOut, const Drone& obj) { 29 | ioOut << "ID:" << obj.id << " (" << obj.row << "," << obj.col << "), e=" << obj.emergency << ", b=" << obj.battery << ", ns=" << obj.scannedFish.size(); 30 | return ioOut; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /bots/seabed-security/Drone.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | 5 | class Drone { 6 | public: 7 | 8 | int id; 9 | int row; 10 | int col; 11 | int emergency; 12 | int battery; 13 | vector radarTL; 14 | vector radarTR; 15 | vector radarBL; 16 | vector radarBR; 17 | vector scannedFish; 18 | 19 | Position centerTL; 20 | Position centerTR; 21 | Position centerBL; 22 | Position centerBR; 23 | 24 | 25 | Drone(); 26 | void read(); 27 | int dist2(int r, int c); 28 | 29 | friend std::ostream& operator<<(std::ostream& ioOut, const Drone& obj); 30 | 31 | }; -------------------------------------------------------------------------------- /bots/seabed-security/Fish.cpp: -------------------------------------------------------------------------------- 1 | #include "Fish.h" 2 | 3 | Fish::Fish() { } // default constructor 4 | 5 | 6 | void Fish::readInit() { 7 | cin >> id >> color >> type; cin.ignore(); 8 | scannedByFoe = false; 9 | scannedByMe = false; 10 | row = -1; 11 | col = -1; 12 | } 13 | 14 | std::ostream& operator<<(std::ostream& ioOut, const Fish& obj) { 15 | ioOut << "ID:" << obj.id << " (" << obj.row << "," << obj.col << "), color =" << obj.color << ", type =" << obj.type << " v = (" << obj.vRow << "," << obj.vCol << ")" << obj.isVisible; 16 | return ioOut; 17 | } -------------------------------------------------------------------------------- /bots/seabed-security/Fish.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Fish { 5 | public: 6 | 7 | int id; 8 | int color; 9 | int type; 10 | int row; 11 | int col; 12 | bool scannedByMe; 13 | bool scannedByFoe; 14 | bool isVisible; 15 | int vCol; 16 | int vRow; 17 | 18 | Fish(); 19 | void readInit(); 20 | 21 | friend std::ostream& operator<<(std::ostream& ioOut, const Fish& obj); 22 | 23 | }; -------------------------------------------------------------------------------- /bots/seabed-security/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Fish.h" 4 | #include "Drone.h" 5 | 6 | class Game { 7 | public: 8 | 9 | vector fish; 10 | vector myDrones; 11 | vector hisDrones; 12 | 13 | int creature_count; 14 | int my_score; 15 | int foe_score; 16 | int my_scan_count; 17 | int foe_scan_count; 18 | int my_drone_count; 19 | int foe_drone_count; 20 | int drone_scan_count; 21 | int visible_creature_count; 22 | int radar_blip_count; 23 | 24 | Game(); 25 | 26 | void readInit(); 27 | void readTurn(); 28 | void printTurn(); 29 | 30 | int getFishI(int id); 31 | int getmyDroneI(int id); 32 | int getfoeDroneI(int id); 33 | 34 | }; -------------------------------------------------------------------------------- /bots/seabed-security/Position.cpp: -------------------------------------------------------------------------------- 1 | #include "Position.h" 2 | 3 | Position::Position() 4 | { 5 | row = 0; 6 | col = 0; 7 | } 8 | 9 | Position::Position(int r, int c) 10 | { 11 | row = r; 12 | col = c; 13 | } 14 | 15 | std::ostream &operator<<(std::ostream &ioOut, const Position &obj) 16 | { 17 | ioOut << " (" << obj.row << "," << obj.col << ") "; 18 | return ioOut; 19 | } 20 | -------------------------------------------------------------------------------- /bots/seabed-security/Position.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Position { 5 | public: 6 | 7 | int row; 8 | int col; 9 | 10 | Position(); 11 | Position(int r, int c); 12 | 13 | friend std::ostream& operator<<(std::ostream& ioOut, const Position& obj); 14 | 15 | }; -------------------------------------------------------------------------------- /bots/seabed-security/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Common.h" 2 | #include "Game.h" 3 | #include "Position.h" 4 | 5 | /** 6 | * Score points by scanning valuable fish faster than your opponent. 7 | **/ 8 | 9 | int main() 10 | { 11 | 12 | Game game; 13 | game.readInit(); 14 | 15 | 16 | // game loop 17 | while (1) { 18 | 19 | game.readTurn(); 20 | game.printTurn(); 21 | 22 | for (Drone d : game.myDrones) { 23 | int light = 0; 24 | if (d.battery > 4) { light = 1; } 25 | if (d.scannedFish.size() > 1) { 26 | cout << "MOVE " << d.col << " 499 0" << endl; 27 | } else { 28 | Position target(5000,5000); 29 | int m = -1; 30 | int s = d.radarBL.size(); 31 | cerr << "eee " << s << " " << m << endl; 32 | if (s > m ) { m =d.radarBL.size(); target.row = d.centerBL.row; target.col = d.centerBL.col;} 33 | s = d.radarBR.size(); 34 | if (s > m ) { m =d.radarBR.size(); target.row = d.centerBR.row; target.col = d.centerBR.col; } 35 | s = d.radarTL.size(); 36 | if (s > m ) { m =d.radarTL.size(); target.row = d.centerTL.row; target.col = d.centerTL.col; } 37 | s = d.radarTR.size(); 38 | if (s > m ) { m =d.radarTR.size(); target.row = d.centerTR.row; target.col = d.centerTR.col; } 39 | 40 | cout << "MOVE " << target.col << " " << target.row << " " << light << endl; 41 | } 42 | } 43 | 44 | } 45 | } -------------------------------------------------------------------------------- /bots/space-shooter/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | static constexpr double SHIP_MAX_ACCELERATION = 10; 5 | static constexpr double MISSILE_MAX_ACCELERATION = 30; 6 | static constexpr double BULLET_VELOCITY = 100; 7 | static constexpr double SHIP_MAX_HEALTH = 10; 8 | static constexpr int MISSILES_COUNT = 8; 9 | static constexpr double MISSILE_MAX_HEALTH = 7; 10 | static constexpr double BULLET_MAX_HEALTH = 10; 11 | static constexpr double TIME_DELTA = 0.2; 12 | static constexpr double GUN_COOLDOWN = 2.0; 13 | static constexpr double MISSILE_COOLDOWN = 0.9; 14 | static constexpr double GUN_BLAST_RADIUS = 120; 15 | static constexpr double GUN_DAMAGE = 10; 16 | static constexpr double BULLET_LIFETIME = 7; 17 | static constexpr double MISSILE_BLAST_RADIUS = 200; 18 | static constexpr double MISSILE_DAMAGE = 15; 19 | static constexpr int MAP_X = 1700; 20 | static constexpr int MAP_Y = 1080; -------------------------------------------------------------------------------- /bots/space-shooter/Game.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | 3 | Game::Game() {} // default constructor 4 | 5 | void Game::read() { 6 | 7 | bullets.clear(); 8 | missiles.clear(); 9 | 10 | std::cin >> nUnits; std::cin.ignore(); 11 | for (int i = 0; i < nUnits; i++) { 12 | Unit u; 13 | u.read(); 14 | if (u.isBullet()) { bullets.push_back(u); } 15 | if (u.isMissile()) { missiles.push_back(u); } 16 | if (u.isShip()) { 17 | if (u.isMine()) { me = u; } else { he = u; } 18 | } 19 | } 20 | } 21 | 22 | Vector2D Game::circling(Vector2D center) { 23 | 24 | float angle = center.angleTo(me.position); 25 | float dist = me.position.dist(center); 26 | Vector2D newPos(-1000,-1000); 27 | float dTheta = 30.0; 28 | me.getAccelToPosition(newPos); 29 | while (me.acceleration.magnitude()>10.0 & dTheta > 0.0) { 30 | dTheta = dTheta - 1.0; 31 | float newAngle = angle - dTheta/180; 32 | newPos.x = center.x + dist * sin(newAngle); 33 | newPos.y = center.y + dist * cos(newAngle); 34 | me.getAccelToPosition(newPos); 35 | // std::cerr << newAngle*180/3.141592 << " " << dist << std::endl; 36 | } 37 | return newPos; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /bots/space-shooter/Game.h: -------------------------------------------------------------------------------- 1 | #ifndef GAME_H 2 | #define GAME_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Vector2D.h" 8 | #include "Common.h" 9 | #include "Unit.h" 10 | 11 | class Game { 12 | 13 | public: 14 | 15 | int nUnits; // number of units on the map 16 | std::vector bullets; 17 | std::vector missiles; 18 | Unit me; 19 | Unit he; 20 | 21 | Game(); // default constructor 22 | void read(); 23 | Vector2D circling(Vector2D center); 24 | 25 | }; 26 | 27 | 28 | #endif 29 | 30 | 31 | -------------------------------------------------------------------------------- /bots/space-shooter/Unit.cpp: -------------------------------------------------------------------------------- 1 | #include "Unit.h" 2 | 3 | 4 | Unit::Unit() { // default constructor 5 | position.x = 0.0; 6 | position.y = 0.0; 7 | velocity.x = 0.0; 8 | velocity.y = 0.0; 9 | acceleration.x = 0.0; 10 | acceleration.y = 0.0; 11 | bulletVelocity.x = 0.0; 12 | bulletVelocity.y = 0.0; 13 | 14 | unit_id = -1; // unit's unique ID 15 | fraction = 0; // 1 if the unit belongs to the player, -1 if to opponent 16 | unit_type = "none"; // 'S' for ship, 'B' for bullet, 'M' for missile 17 | health = -1; // remaining unit's health points 18 | gun_cooldown = -1; // number of rounds till the next bullet can be fired if this is a ship, -1 otherwise 19 | } 20 | 21 | void Unit::read() { 22 | std::cin >> unit_id >> fraction >> unit_type >> health >> position.x >> position.y >> velocity.x >> velocity.y >> gun_cooldown; std::cin.ignore(); 23 | } 24 | 25 | 26 | bool Unit::isBullet() { 27 | return unit_type == "B"; 28 | } 29 | 30 | bool Unit::isMissile() { 31 | return unit_type == "M"; 32 | } 33 | 34 | bool Unit::isMine() { 35 | return fraction == 1; 36 | } 37 | 38 | bool Unit::isShip() { 39 | return unit_type == "S"; 40 | } 41 | 42 | void Unit::move() { 43 | 44 | for (int i = 0; i<5; i++) { 45 | velocity.x = velocity.x + TIME_DELTA * acceleration.x; 46 | velocity.y = velocity.y + TIME_DELTA * acceleration.y; 47 | 48 | position.x = position.x + TIME_DELTA * velocity.x; 49 | position.y = position.y + TIME_DELTA * velocity.y; 50 | } 51 | 52 | } 53 | 54 | void Unit::getAccelToPosition(Vector2D p) { 55 | acceleration.x = ( p.x - position.x - velocity.x ) * 5.0/3.0 ; 56 | acceleration.y = ( p.y - position.y - velocity.y ) * 5.0/3.0 ; 57 | } 58 | 59 | std::ostream& operator<<(std::ostream& ioOut, const Unit& obj) { 60 | ioOut << obj.unit_id << " " << obj.fraction <<" " << obj.unit_type << " " << obj.health << " " << obj.gun_cooldown << " " << obj.position << " " << obj.velocity; 61 | return ioOut; 62 | } 63 | 64 | 65 | void Unit::setBulletVelocity(Vector2D target) { 66 | 67 | Vector2D r(target.x - position.x, target.y - position.y); 68 | r.normalise(); 69 | r.x = r.x * 100.0; 70 | r.y = r.y * 100.0; 71 | 72 | // std::cerr << "r=" << r << " v= " << velocity << std::endl; 73 | 74 | bulletVelocity.x = -velocity.x + r.x; 75 | bulletVelocity.y = -velocity.y + r.y; 76 | 77 | } 78 | -------------------------------------------------------------------------------- /bots/space-shooter/Unit.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIT_H 2 | #define UNIT_H 3 | 4 | #include 5 | 6 | #include "Vector2D.h" 7 | #include "Common.h" 8 | 9 | class Unit { 10 | 11 | public: 12 | 13 | int unit_id; // unit's unique ID 14 | int fraction; // 1 if the unit belongs to the player, -1 if to opponent 15 | std::string unit_type; // 'S' for ship, 'B' for bullet, 'M' for missile 16 | float health; // remaining unit's health points 17 | Vector2D position; 18 | Vector2D velocity; 19 | Vector2D acceleration; 20 | Vector2D bulletVelocity; 21 | float gun_cooldown; // number of rounds till the next bullet can be fired if this is a ship, -1 otherwise 22 | 23 | Unit(); // default constructor 24 | void read(); 25 | bool isBullet(); 26 | bool isMissile(); 27 | bool isMine(); 28 | bool isShip(); 29 | 30 | void move(); 31 | void getAccelToPosition(Vector2D p); 32 | void setBulletVelocity(Vector2D target); 33 | 34 | friend std::ostream& operator<<(std::ostream& ioOut, const Unit& obj); 35 | }; 36 | 37 | 38 | #endif 39 | 40 | 41 | -------------------------------------------------------------------------------- /bots/space-shooter/Vector2D.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector2D.h" 2 | 3 | 4 | Vector2D::Vector2D(float x_, float y_) { x = x_; y = y_; } // constructor 5 | Vector2D::Vector2D() { x = -1.0; y = -1.0; } // default constructor 6 | 7 | float Vector2D::dist(float x_, float y_) { 8 | return sqrt( (x - x_)*(x - x_) + (y - y_)*(y - y_) ); 9 | } 10 | 11 | float Vector2D::dist(Vector2D v) { 12 | return sqrt( (x - v.x)*(x - v.x) + (y - v.y)*(y - v.y) ); 13 | } 14 | 15 | bool Vector2D::onMap() { 16 | return x >= 0 && y >= 0 && x <= MAP_X && y <= MAP_Y; 17 | } 18 | 19 | std::ostream& operator<<(std::ostream& ioOut, const Vector2D& obj) { 20 | ioOut << obj.x << " " << obj.y; 21 | return ioOut; 22 | } 23 | 24 | float Vector2D::magnitude() { 25 | return dist(0.0,0.0); 26 | } 27 | 28 | float Vector2D::angleTo(Vector2D v) { 29 | return atan2(v.x - x,v.y - y); 30 | } 31 | 32 | void Vector2D::normalise() { 33 | float m = magnitude(); 34 | if (m>0.0) { 35 | x = x / m; 36 | y = y / m; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /bots/space-shooter/Vector2D.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR2D_H 2 | #define VECTOR2D_H 3 | 4 | #include 5 | #include 6 | #include "Common.h" 7 | 8 | class Vector2D { 9 | 10 | public: 11 | 12 | float x,y; 13 | Vector2D(float x_, float y_); // constructor 14 | Vector2D(); // default constructor 15 | 16 | bool onMap(); 17 | 18 | float dist(float x_, float y_); 19 | float dist(Vector2D v); 20 | 21 | float angleTo(Vector2D v); 22 | 23 | float magnitude(); 24 | 25 | void normalise(); 26 | 27 | friend std::ostream& operator<<(std::ostream& ioOut, const Vector2D& obj); 28 | }; 29 | 30 | 31 | #endif -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static constexpr int ME = 1; 13 | static constexpr int HE = 0; 14 | static constexpr int MAP_MIN_WIDTH = 28; 15 | static constexpr int MAP_MAX_WIDTH = 35; 16 | static constexpr int MAP_MIN_HEIGHT = 10; 17 | static constexpr int MAP_MAX_HEIGHT = 17; 18 | static constexpr int SPACE = 1; 19 | static constexpr int WALL = 0; 20 | 21 | static constexpr int SCcrash = 10000; 22 | static constexpr int SCeat = 100000; 23 | static constexpr int SCten = 5000; 24 | static constexpr int SCten2 = 7500; 25 | 26 | static constexpr int SCone = 650; 27 | static constexpr int SCone2 = 750; 28 | 29 | static constexpr int SCnvis = 150; 30 | static constexpr int SCnvis2 = 250; 31 | 32 | static constexpr int SCnearby = 1500; 33 | static constexpr int SCnearby2 = 2000; -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Position.h" 3 | #include "Common.h" 4 | #include "Tile.h" 5 | #include "Tree.h" 6 | #include "Pacman.h" 7 | 8 | class Map { 9 | 10 | public: 11 | std::vector tiles; 12 | int width; // The width of the playing field 13 | int height; // The height of the playing field 14 | Tree tree; 15 | 16 | Map(); 17 | void read(); 18 | 19 | void getPath(Tile target); 20 | void getPath(Position target); 21 | 22 | void getPathTree(Tile target); 23 | void getPathTree(Position target); 24 | void getPacmanPaths(Pacman target, std::vector myPacmen, std::vector hisPacmen); 25 | Tile getStep(Position target, Position me, int speedTurnsLeft); 26 | 27 | int getDistance(Position p); 28 | int getDistance(Tile t); 29 | int getDistance(int treeID); 30 | 31 | void setVisited(Position p); 32 | void setPellet(Position p); 33 | void setTaken(Position p); 34 | void generateMoves(Pacman& pac); 35 | std::vector getPathToMe(Position target, Position me); 36 | 37 | 38 | Tile getTile(int row, int col) const; 39 | Tile getTile(Position pos) const; 40 | 41 | Tile getEastTile(int row, int col) const; 42 | Tile getWestTile(int row, int col) const; 43 | Tile getNorthTile(int row, int col) const; 44 | Tile getSouthTile(int row, int col) const; 45 | 46 | Tile getEastTile(Position pos) const; 47 | Tile getWestTile(Position pos) const; 48 | Tile getNorthTile(Position pos) const; 49 | Tile getSouthTile(Position pos) const; 50 | 51 | friend std::ostream& operator<<(std::ostream& ioOut, const Map& obj); 52 | }; 53 | -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Move.cpp: -------------------------------------------------------------------------------- 1 | #include "Move.h" 2 | 3 | Move::Move() { score = -1; } // default constructor 4 | Move::Move(Position p, int s) { this->pos = p; this->score = s; }; 5 | 6 | 7 | 8 | std::ostream& operator<<(std::ostream& ioOut, const Move& obj) { 9 | ioOut << obj.pos.col << " " << obj.pos.row << " score " << obj.score; 10 | return ioOut; 11 | } 12 | -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Move.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | 5 | class Move { 6 | public: 7 | Position pos; 8 | int score; 9 | Move(); 10 | Move(Position p, int s); 11 | 12 | 13 | friend std::ostream& operator<<(std::ostream& ioOut, const Move& obj); 14 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Pacman.cpp: -------------------------------------------------------------------------------- 1 | #include "Pacman.h" 2 | 3 | Pacman::Pacman() { pos.row = -1; pos.col = -1; } //moves.clear(); } // default constructor 4 | 5 | 6 | void Pacman::addToScore(Position p, int dScore) { 7 | for (Move& m : moves) { 8 | if (m.pos == p) { 9 | m.score = m.score + dScore; 10 | } 11 | } 12 | } 13 | 14 | Position Pacman::getBestMove() { 15 | Position best; 16 | int maxScore = -111111111; 17 | for (Move m : moves) { 18 | if (m.score > maxScore) { 19 | maxScore = m.score; 20 | best = m.pos; 21 | } 22 | } 23 | return best; 24 | } 25 | 26 | bool Pacman::getsEaten(std::string hisType) { 27 | bool yesno = false; 28 | 29 | if (typeId == "ROCK" && hisType == "PAPER") { yesno = true; } 30 | if (typeId == "PAPER" && hisType == "SCISSORS") { yesno = true; } 31 | if (typeId == "SCISSORS" && hisType == "ROCK") { yesno = true; } 32 | 33 | return yesno; 34 | } 35 | 36 | std::ostream& operator<<(std::ostream& ioOut, const Pacman& obj) { 37 | ioOut << "pacID:" << obj.id << " (" << obj.pos.col << "," << obj.pos.row << ") " << obj.typeId << " " << obj.speedTurnsLeft << " ab: " << obj.abilityCooldown << " nPel " << obj.pellets.size(); 38 | for (Move m : obj.moves) { 39 | ioOut << std::endl << " move " << m; 40 | } 41 | return ioOut; 42 | } 43 | -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Pacman.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | #include "Pellet.h" 5 | #include "Move.h" 6 | 7 | class Pacman { 8 | public: 9 | int id; 10 | Position pos; 11 | Position target; 12 | bool targetFound; 13 | std::string typeId; 14 | int speedTurnsLeft; 15 | int abilityCooldown; 16 | std::vector pellets; 17 | std::vector moves; 18 | void addToScore(Position p, int dScore); 19 | Position getBestMove(); 20 | bool getsEaten(std::string hisType); 21 | 22 | Pacman(); 23 | 24 | 25 | 26 | friend std::ostream& operator<<(std::ostream& ioOut, const Pacman& obj); 27 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Pellet.cpp: -------------------------------------------------------------------------------- 1 | #include "Pellet.h" 2 | 3 | std::ostream& operator<<(std::ostream& ioOut, const Pellet& obj) { 4 | ioOut << obj.pos.col << " " << obj.pos.row << " " << obj.value; 5 | return ioOut; 6 | } 7 | -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Pellet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | 5 | class Pellet { 6 | public: 7 | Position pos; 8 | int value; 9 | 10 | friend std::ostream& operator<<(std::ostream& ioOut, const Pellet& obj); 11 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player() { score = 0; } // default constructor 4 | 5 | std::ostream& operator<<(std::ostream& ioOut, const Player& obj) { 6 | ioOut << "score= " << obj.score << " nPacs " << obj.pacmen.size(); 7 | return ioOut; 8 | } 9 | -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Pacman.h" 4 | 5 | class Player { 6 | public: 7 | int score; 8 | std::vector pacmen; 9 | 10 | Player(); 11 | 12 | friend std::ostream& operator<<(std::ostream& ioOut, const Player& obj); 13 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Position.cpp: -------------------------------------------------------------------------------- 1 | #include "Position.h" 2 | 3 | Position::Position(int r, int c) { row = r; col = c; } // constructor 4 | Position::Position(int r, int c, int p) { row = r; col = c; } // constructor 5 | Position::Position() { row = -1; col = -1; } // default constructor 6 | 7 | 8 | std::ostream& operator<<(std::ostream& ioOut, const Position& obj) { 9 | ioOut << obj.col << " " << obj.row; 10 | return ioOut; 11 | } 12 | 13 | int Position::manhattan(Position p) { 14 | return abs( p.row - row)+abs( p.col - col); 15 | } 16 | 17 | 18 | // Overload + operator to add two Box objects. 19 | Position Position::operator+(const Position& p) { 20 | Position pos; 21 | pos.row = this->row + p.row; 22 | pos.row = this->col + p.col; 23 | return pos; 24 | } 25 | 26 | 27 | // Overload == operator 28 | bool Position::operator==(const Position p) { 29 | return this->row == p.row && this->col == p.col; 30 | } 31 | 32 | bool Position::operator!=(const Position p) { 33 | return !(this->row == p.row && this->col == p.col); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Position.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Position { 5 | public: 6 | int row; 7 | int col; 8 | 9 | Position(int r, int c); 10 | Position(int r, int c, int p); 11 | Position(); 12 | 13 | friend std::ostream& operator<<(std::ostream& ioOut, const Position& obj); 14 | bool operator==(const Position p); 15 | bool operator!=(const Position p); 16 | Position operator+(const Position& p); 17 | int manhattan(Position p); 18 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Tile.cpp: -------------------------------------------------------------------------------- 1 | #include "Tile.h" 2 | 3 | Tile::Tile() { type = -1; id = -1; counter = 100; visited=false; } // default constructor 4 | 5 | std::ostream& operator<<(std::ostream& ioOut, const Tile& obj) { 6 | if (obj.pellet) { 7 | ioOut << "."; 8 | } else if (obj.visited) { 9 | ioOut << "v"; 10 | } else { 11 | ioOut << obj.tileLetter[obj.type]; 12 | } 13 | 14 | return ioOut; 15 | } 16 | -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Tile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | 5 | class Tile { 6 | public: 7 | int id; 8 | int type; 9 | int treeID; 10 | Position pos; 11 | std::vector neib; 12 | int counter; 13 | bool visited; 14 | bool pellet; 15 | bool taken; 16 | 17 | Tile(); 18 | 19 | friend std::ostream& operator<<(std::ostream& ioOut, const Tile& obj); 20 | std::vector tileLetter = {"#"," "}; 21 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Tree.cpp: -------------------------------------------------------------------------------- 1 | #include "Tree.h" 2 | 3 | Tree::Tree() { } // default constructor 4 | 5 | void Tree::clearBlocked() { 6 | for (int i = 0; i < n; i++ ){ 7 | blocked[i] = false; 8 | } 9 | } 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /bots/spring-challenge-2020/Tree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Position.h" 3 | 4 | class Tree { 5 | public: 6 | int n; 7 | int neib[595][4]; 8 | int counter[595]; 9 | int nNeib[595]; 10 | bool blocked[595]; 11 | int queue[595]; 12 | Position pos[595]; 13 | 14 | Tree(); 15 | void clearBlocked(); 16 | 17 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2021/Cell.cpp: -------------------------------------------------------------------------------- 1 | #include "Cell.h" 2 | 3 | Cell::Cell() {} // default constructor 4 | 5 | void Cell::read() { 6 | std::cin >> id >> richness >> neib[0] >> neib[1] >> neib[2] >> neib[3] >> neib[4] >> neib[5]; std::cin.ignore(); 7 | } 8 | 9 | std::ostream& operator<<(std::ostream& ioOut, const Cell& obj) { 10 | 11 | ioOut << obj.id << " " << obj.richness; 12 | return ioOut; 13 | } -------------------------------------------------------------------------------- /bots/spring-challenge-2021/Cell.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Cell { 5 | public: 6 | int id; // 0 is the center cell, the next cells spiral outwards 7 | int neib[6]; // 0 if the cell is unusable, 1-3 for usable cells 8 | int richness; // the index of the neighbouring cell for each direction 9 | 10 | Cell(); 11 | void read(); 12 | 13 | friend std::ostream& operator<<(std::ostream& ioOut, const Cell& obj); 14 | 15 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2021/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | 5 | static constexpr int ME = 1; 6 | static constexpr int HIM = 2; 7 | 8 | 9 | 10 | int RandomNumber(int N) { 11 | /* generate secret number between 0 and N-1: */ 12 | return rand() % N; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /bots/spring-challenge-2021/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player() {} // default constructor 4 | 5 | void Player::meRead() { 6 | std::cin >> sunPoints >> score; std::cin.ignore(); 7 | isWaiting = false; 8 | } 9 | 10 | void Player::heRead() { 11 | std::cin >> sunPoints >> score >> isWaiting ; std::cin.ignore(); 12 | } 13 | 14 | 15 | std::ostream& operator<<(std::ostream& ioOut, const Player& obj) { 16 | 17 | ioOut << "Player: " << obj.sunPoints << " " << obj.score << " " << obj.isWaiting; 18 | return ioOut; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /bots/spring-challenge-2021/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Tree.h" 5 | 6 | class Player { 7 | public: 8 | int sunPoints; // your sun points 9 | int score; // your current score 10 | bool isWaiting; 11 | std::vector trees; 12 | 13 | 14 | Player(); 15 | void meRead(); 16 | void heRead(); 17 | 18 | friend std::ostream& operator<<(std::ostream& ioOut, const Player& obj); 19 | }; 20 | 21 | 22 | -------------------------------------------------------------------------------- /bots/spring-challenge-2021/Tree.cpp: -------------------------------------------------------------------------------- 1 | #include "Tree.h" 2 | 3 | Tree::Tree() { cellId = -1; value = -1;} // default constructor 4 | 5 | void Tree::read() { 6 | bool isMine; // 1 if this is your tree 7 | std::cin >> cellId >> size >> isMine >> isDormant; std::cin.ignore(); 8 | if (isMine == ME) { 9 | owner = ME; 10 | } else { 11 | owner = HIM; 12 | } 13 | } 14 | 15 | std::ostream& operator<<(std::ostream& ioOut, const Tree& obj) { 16 | 17 | ioOut << obj.cellId << " " << obj.size << " " << obj.owner << " " << obj.value; 18 | return ioOut; 19 | } -------------------------------------------------------------------------------- /bots/spring-challenge-2021/Tree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Common.h" 4 | 5 | class Tree { 6 | public: 7 | int cellId; // location of this tree 8 | int size; // size of this tree: 0-3 9 | bool isDormant; // 1 if this tree is dormant 10 | int owner; 11 | int value; 12 | 13 | Tree(); 14 | void read(); 15 | 16 | 17 | friend std::ostream& operator<<(std::ostream& ioOut, const Tree& obj); 18 | 19 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2022/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | 5 | static constexpr int ME = 1; 6 | static constexpr int HIM = 2; 7 | static constexpr int MAP_X = 17630; 8 | static constexpr int MAP_Y = 9000; 9 | static constexpr int R_BASE = 300; 10 | static constexpr int R_MAGNET = 5000; 11 | static constexpr int R_FOG = 6000; 12 | static constexpr int R_FOG_HERO = 2200; 13 | static constexpr int R_WIND = 1280; 14 | static constexpr int R_SHIELD = 2200; 15 | static constexpr int R_CONTROL = 2200; 16 | 17 | 18 | 19 | int RandomNumber(int N) { 20 | /* generate secret number between 0 and N-1: */ 21 | return rand() % N; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /bots/spring-challenge-2022/Hero.cpp: -------------------------------------------------------------------------------- 1 | #include "Hero.h" 2 | 3 | Hero::Hero() {} // default constructor 4 | 5 | Hero::Hero(int _id, int _type, int _x, int _y, int _shield_life, int _is_controlled) { 6 | id = _id; 7 | type = _type; 8 | x = _x; 9 | y = _y; 10 | shield_life = _shield_life; 11 | is_controlled = _is_controlled; 12 | pos.x = x; 13 | pos.y = y; 14 | } 15 | 16 | 17 | 18 | std::ostream& operator<<(std::ostream& ioOut, const Hero& obj) { 19 | 20 | ioOut << obj.id << " " << obj.type << " " << obj.pos << " " << obj.shield_life << " " << obj.is_controlled; 21 | return ioOut; 22 | } -------------------------------------------------------------------------------- /bots/spring-challenge-2022/Hero.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Common.h" 4 | #include "Vector2D.h" 5 | 6 | class Hero { 7 | public: 8 | int id; // Unique identifier 9 | int type; // 0=monster, 1=your hero, 2=opponent hero 10 | int x; // Position of this entity 11 | int y; 12 | int shield_life; // Ignore for this league; Count down until shield spell fades 13 | int is_controlled; // Ignore for this league; Equals 1 when this entity is under a control spell 14 | Vector2D pos; 15 | Vector2D staticTarget; 16 | 17 | Hero(); 18 | Hero(int _id, int _type, int _x, int _y, int _shield_life, int _is_controlled); 19 | 20 | 21 | friend std::ostream& operator<<(std::ostream& ioOut, const Hero& obj); 22 | 23 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2022/Monster.cpp: -------------------------------------------------------------------------------- 1 | #include "Monster.h" 2 | 3 | Monster::Monster() { 4 | x = -1; 5 | y = -1; 6 | } // default constructor 7 | 8 | Monster::Monster(int _id, int _type, int _x, int _y, int _shield_life, int _is_controlled, int _health, int _vx, int _vy, int _near_base, int _threat_for) { 9 | id = _id; 10 | type = _type; 11 | x = _x; 12 | y = _y; 13 | shield_life = _shield_life; 14 | is_controlled = _is_controlled; 15 | health = _health; 16 | vx = _vx; 17 | vy = _vy; 18 | near_base = _near_base; 19 | threat_for = _threat_for; 20 | pos.x = x; 21 | pos.y = y; 22 | score = 0; 23 | } 24 | 25 | bool Monster::operator<(const Monster& x) const { return score > x.score; } 26 | bool Monster::operator>(const Monster& x) const { return score > x.score; } 27 | 28 | bool Monster::sortScore(const Monster& x, const Monster& y) const { return x.score > y.score; } 29 | 30 | std::ostream& operator<<(std::ostream& ioOut, const Monster& obj) { 31 | 32 | ioOut << obj.id << " " << obj.type << " " << obj.pos << " " << obj.shield_life << " " << obj.is_controlled << " " << obj.health << " " << obj.vx << " " << obj.vy << " " << obj.near_base << " " << obj.threat_for; 33 | return ioOut; 34 | } -------------------------------------------------------------------------------- /bots/spring-challenge-2022/Monster.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Common.h" 4 | #include "Vector2D.h" 5 | 6 | class Monster { 7 | public: 8 | int id; // Unique identifier 9 | int type; // 0=monster, 1=your hero, 2=opponent hero 10 | int x; // Position of this entity 11 | int y; 12 | int shield_life; // Ignore for this league; Count down until shield spell fades 13 | int is_controlled; // Ignore for this league; Equals 1 when this entity is under a control spell 14 | 15 | int health; // Remaining health of this monster 16 | int vx; // Trajectory of this monster 17 | int vy; 18 | int near_base; // 0=monster with no target yet, 1=monster targeting a base 19 | int threat_for; // Given this monster's trajectory, is it a threat to 1=your base, 2=your opponent's base, 0=neither 20 | Vector2D pos; 21 | int score; 22 | 23 | bool operator<(const Monster& x) const; 24 | bool operator>(const Monster& x) const; 25 | bool sortScore(const Monster& x, const Monster& y) const; 26 | 27 | Monster(); 28 | Monster(int _id, int _type, int _x, int _y, int _shield_life, int _is_controlled, int _health, int _vx, int _vy, int _near_base, int _threat_for); 29 | 30 | friend std::ostream& operator<<(std::ostream& ioOut, const Monster& obj); 31 | 32 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2022/Vector2D.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector2D.h" 2 | 3 | 4 | Vector2D::Vector2D(float x_, float y_) { x = x_; y = y_; } // constructor 5 | Vector2D::Vector2D() { x = -1.0; y = -1.0; } // default constructor 6 | 7 | float Vector2D::dist(float x_, float y_) { 8 | return sqrt( (x - x_)*(x - x_) + (y - y_)*(y - y_) ); 9 | } 10 | 11 | float Vector2D::dist(Vector2D v) { 12 | return sqrt( (x - v.x)*(x - v.x) + (y - v.y)*(y - v.y) ); 13 | } 14 | 15 | bool Vector2D::onMap() { 16 | return x >= 0 && y >= 0 && x <= MAP_X && y <= MAP_Y; 17 | } 18 | 19 | std::ostream& operator<<(std::ostream& ioOut, const Vector2D& obj) { 20 | ioOut << (int)obj.x << " " << (int)obj.y; 21 | return ioOut; 22 | } 23 | 24 | float Vector2D::magnitude() { 25 | return dist(0.0,0.0); 26 | } 27 | 28 | float Vector2D::angleTo(Vector2D v) { 29 | return atan2(v.x - x,v.y - y); 30 | } 31 | 32 | void Vector2D::normalise() { 33 | float m = magnitude(); 34 | if (m>0.0) { 35 | x = x / m; 36 | y = y / m; 37 | } 38 | } 39 | 40 | void Vector2D::rotate(float angle) { 41 | float xx = x * cos(angle/180.0*pi) - y * sin(angle/180.0*pi); 42 | float yy = x * sin(angle/180.0*pi) + y * cos(angle/180.0*pi); 43 | x = xx; 44 | y = yy; 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /bots/spring-challenge-2022/Vector2D.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR2D_H 2 | #define VECTOR2D_H 3 | 4 | #include 5 | #include 6 | #include "Common.h" 7 | 8 | class Vector2D { 9 | private: 10 | 11 | float pi = 3.141592654; 12 | 13 | public: 14 | 15 | float x,y; 16 | Vector2D(float x_, float y_); // constructor 17 | Vector2D(); // default constructor 18 | 19 | bool onMap(); 20 | 21 | float dist(float x_, float y_); 22 | float dist(Vector2D v); 23 | 24 | float angleTo(Vector2D v); 25 | 26 | float magnitude(); 27 | 28 | void normalise(); 29 | void rotate(float angle); 30 | 31 | friend std::ostream& operator<<(std::ostream& ioOut, const Vector2D& obj); 32 | }; 33 | 34 | 35 | #endif -------------------------------------------------------------------------------- /bots/spring-challenge-2023/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static int EGGS = 1; 13 | static int EMPTY = 0; 14 | static int CRYSTAL = 2; 15 | -------------------------------------------------------------------------------- /bots/spring-challenge-2023/Map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Tile.h" 4 | 5 | class Map { 6 | public: 7 | std::vector tiles; 8 | std::vector myBases; 9 | std::vector hisBases; 10 | int number_of_tiles; // amount of hexagonal cells in this map 11 | int number_of_bases; 12 | 13 | Map(); 14 | void readInit(); 15 | void readTurn(); 16 | 17 | friend std::ostream& operator<<(std::ostream& ioOut, const Map& obj); 18 | 19 | std::vector getPath(int start, int end); 20 | 21 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2023/Tile.cpp: -------------------------------------------------------------------------------- 1 | #include "Tile.h" 2 | 3 | Tile::Tile() { } // default constructor 4 | 5 | Tile::Tile(int id_, int type_, int resources_, int neigh_0, int neigh_1, int neigh_2, int neigh_3, int neigh_4, int neigh_5) { 6 | id = id_; 7 | type = type_; 8 | resources = resources_; 9 | neib.clear(); 10 | if (neigh_0 > -1) { neib.push_back(neigh_0); } 11 | if (neigh_1 > -1) { neib.push_back(neigh_1); } 12 | if (neigh_2 > -1) { neib.push_back(neigh_2); } 13 | if (neigh_3 > -1) { neib.push_back(neigh_3); } 14 | if (neigh_4 > -1) { neib.push_back(neigh_4); } 15 | if (neigh_5 > -1) { neib.push_back(neigh_5); } 16 | } 17 | 18 | std::ostream& operator<<(std::ostream& ioOut, const Tile& obj) { 19 | ioOut << "ID:" << obj.id << " res:" << obj.resources; 20 | 21 | return ioOut; 22 | } -------------------------------------------------------------------------------- /bots/spring-challenge-2023/Tile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Tile { 5 | public: 6 | int id; 7 | int type; 8 | std::vector neib; 9 | int resources; // the current amount of eggs/crystals on this tile 10 | int my_ants; // the amount of your ants on this tile 11 | int opp_ants; // the amount of opponent ants on this tile 12 | int distance; 13 | 14 | Tile(); 15 | Tile(int id_, int type_, int resources_, int neigh_0, int neigh_1, int neigh_2, int neigh_3, int neigh_4, int neigh_5); 16 | 17 | friend std::ostream& operator<<(std::ostream& ioOut, const Tile& obj); 18 | 19 | }; -------------------------------------------------------------------------------- /bots/spring-challenge-2023/main.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/multiplayer/bot-programming/spring-challenge-2023 2 | 3 | #pragma GCC optimize("O3,inline,omit-frame-pointer,unroll-loops") 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "Map.h" 11 | #include "Tile.h" 12 | 13 | using namespace std; 14 | 15 | /** 16 | * Auto-generated code below aims at helping you parse 17 | * the standard input according to the problem statement. 18 | **/ 19 | 20 | int main() 21 | { 22 | 23 | Map map; 24 | map.readInit(); 25 | 26 | // game loop 27 | while (1) { 28 | 29 | map.readTurn(); 30 | 31 | int minDistEggs = 10000; 32 | int minDistEggsIndex = -1; 33 | int minDistCrystal = 10000; 34 | int minDistCrystalIndex = -1; 35 | 36 | for (Tile t : map.tiles) { 37 | 38 | if (t.resources > 0) { 39 | 40 | std::vector path = map.getPath(map.myBases[0], t.id); 41 | 42 | int speed = path.size(); 43 | for (int id : path) { 44 | if (map.tiles[id].my_ants > 0) { speed--; } 45 | } 46 | 47 | if (t.type == EGGS && path.size() < minDistEggs) { 48 | minDistEggs = path.size(); 49 | minDistEggsIndex = t.id; 50 | } 51 | 52 | if (t.type == CRYSTAL && path.size() < minDistCrystal) { 53 | minDistCrystal = path.size(); 54 | minDistCrystalIndex = t.id; 55 | } 56 | 57 | 58 | } 59 | } 60 | 61 | //std::vector path = map.getPath(map.myBases[0], maxRindex); 62 | //std::cerr << minDistCrystalIndex << " mmm " << minDistEggsIndex << std::endl; 63 | // Write an action using cout. DON'T FORGET THE "<< endl" 64 | // To debug: cerr << "Debug messages..." << endl; 65 | 66 | if (minDistCrystalIndex > -1) { 67 | cout << " LINE " << map.myBases[0] << " " << minDistCrystalIndex << " 1 ;"; 68 | } 69 | 70 | if (minDistEggsIndex > -1) { 71 | cout << " LINE " << map.myBases[0] << " " << minDistEggsIndex << " 1 ; "; 72 | } 73 | 74 | // WAIT | LINE | BEACON | MESSAGE 75 | cout << " WAIT" << endl; 76 | } 77 | } -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static constexpr int daisy = 0; 13 | static constexpr int tulip = 1; 14 | static constexpr int soil = 2; 15 | static constexpr int rocks = 3; 16 | static constexpr int grass = 4; 17 | static constexpr int me = 0; 18 | static constexpr int he = 1; 19 | 20 | static constexpr int strRandom = 0; 21 | static constexpr int strCodingame = 1; 22 | static constexpr int strNew = 2; 23 | static constexpr int strNew2 = 3; 24 | static constexpr int strMinimax = 4; 25 | static constexpr int strNew3 = 5; 26 | 27 | 28 | static constexpr int tyCodingame = 0; 29 | static constexpr int ty1vs1 = 1; 30 | -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | #include "Player.h" 5 | #include "Map.h" 6 | 7 | 8 | class Game { 9 | public: 10 | Map map; 11 | std::vector players; 12 | 13 | int profit; 14 | bool gameOver; 15 | bool firstTime; 16 | 17 | void readInit(); 18 | void readTurn(); 19 | void play(int playerID, Position p); 20 | void playPrint(int playerID, Position p); 21 | bool isFinished(); 22 | int getProfit(); 23 | friend std::ostream& operator<<(std::ostream& ioOut, const Game& obj); 24 | void setupNew(); 25 | void initNew(); 26 | int heuristicValue(int playerID, int opponentID); 27 | }; 28 | -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = tind 2 | VERSION = 1.0 3 | SOURCES = main.o Game.o Map.o Player.o Position.o Utils.o TestPlayer.o 4 | 5 | ARCH = `uname` 6 | INST = $(HOME)/bin 7 | 8 | HOST = $(shell hostname) 9 | 10 | # 11 | # *************** HOBBIT **************** 12 | # 13 | #ifneq (,$(findstring hobbit,$(HOST))) 14 | 15 | FC = g++ 16 | OBJECTS = $(SOURCES) 17 | KON = 18 | 19 | # Debug version 20 | # OPT = -Wall 21 | # OPDE= d 22 | # Optimized version 23 | OPT = -O3 24 | OPDE= o 25 | 26 | FCOPTS = -std=gnu++11 27 | LDOPTO = 28 | 29 | #endif 30 | 31 | 32 | all: $(OBJECTS) 33 | $(FC) -o $(PROGRAM)-$(VERSION)$(KON) $(FCOPTS) $(OPT) $(OBJECTS) $(LDOPTO) 34 | 35 | clean: 36 | rm -f *.o *.mod .#* 37 | 38 | $(OBJECTS): %.o: %.cpp 39 | $(FC) $(FCOPTS) $(OPT) -c $< 40 | 41 | install: 42 | cp $(PROGRAM)-$(VERSION)$(KON) $(INST)/$(PROGRAM)-$(VERSION)-$(OPDE)$(KON) 43 | 44 | 45 | -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Position.h" 3 | #include "Utils.h" 4 | #include "Common.h" 5 | 6 | class Map { 7 | 8 | public: 9 | int tile[16][16]; 10 | int costs[5]; 11 | int width; // The width of the playing field 12 | int height; // The height of the playing field 13 | 14 | Map(); 15 | int earnedGold(int row, int col); 16 | int trojke(int row, int col); 17 | int dvojke(int row, int col); 18 | int plantFlower(Position a, int flower); 19 | Map createCopy(); 20 | int harvestFlowers(Position p); 21 | std::vector tileLetter = {"D","T",".","#",","}; 22 | std::string getTileLetter(int row, int col); 23 | friend std::ostream& operator<<(std::ostream& ioOut, const Map& obj); 24 | void randomize(); 25 | std::vector setUpPattern(Position center); 26 | int getPatternCost(std::vector pattern, int myFlower); 27 | std::vector setUpDeltaPattern(); 28 | Position getPatternCenter(int myFlower); 29 | 30 | }; 31 | -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player(int g, int f, int tl) { gold = g; flower=f; turnsLeft = tl; nFlowers=0; } // constructor 4 | Player::Player() { gold = -1; flower = -1; } // default constructor 5 | 6 | int Player::getOpponentID(int playerID) { 7 | if (playerID == 0) { return 1; } else { return 0; } 8 | } 9 | 10 | void Player::print() { 11 | std::cerr << name << " gold " << gold << " nFL " << nFlowers << " meTL " << turnsLeft << std::endl; 12 | } -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Player { 5 | public: 6 | int gold; 7 | int flower; 8 | int turnsLeft; 9 | int nFlowers; 10 | int ID; 11 | std::string name; 12 | 13 | Player(int g, int f, int tl); 14 | Player(); 15 | int getOpponentID(int playerID); 16 | void print(); 17 | }; -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Position.cpp: -------------------------------------------------------------------------------- 1 | #include "Position.h" 2 | #include "Utils.h" 3 | 4 | Position::Position(int r, int c) { row = r; col = c; priority = 0; } // constructor 5 | Position::Position(int r, int c, int p) { row = r; col = c; priority = p; } // constructor 6 | Position::Position() { row = -1; col = -1; priority = 0; } // default constructor 7 | 8 | void Position::printCout() { 9 | std::cout << row << " " << col << std::endl; 10 | } 11 | 12 | int Position::manhattan(int r, int c) { 13 | return abs(r-row)+abs(c-col); 14 | } 15 | 16 | void Position::setRandom(int width, int height) { 17 | row = RandomNumber(height); 18 | col = RandomNumber(width); 19 | priority = 0; 20 | } 21 | 22 | std::ostream& operator<<(std::ostream& ioOut, const Position& obj) { 23 | ioOut << obj.row << " " << obj.col; 24 | return ioOut; 25 | } 26 | 27 | // Overload + operator to add two Box objects. 28 | Position Position::operator+(const Position& p) { 29 | Position pos; 30 | pos.row = this->row + p.row; 31 | pos.row = this->col + p.col; 32 | return pos; 33 | } -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Position.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Position { 5 | public: 6 | int row; 7 | int col; 8 | int priority; 9 | 10 | Position(int r, int c); 11 | Position(int r, int c, int p); 12 | Position(); 13 | 14 | void printCout(); 15 | 16 | int manhattan(int r, int c); 17 | 18 | void setRandom(int width, int height); 19 | 20 | friend std::ostream& operator<<(std::ostream& ioOut, const Position& obj); 21 | Position operator+(const Position& p); 22 | }; -------------------------------------------------------------------------------- /bots/tulips-and-daisies/TestPlayer.cpp: -------------------------------------------------------------------------------- 1 | #include "TestPlayer.h" 2 | 3 | 4 | TestPlayer::TestPlayer(int p, int s) { 5 | 6 | player = p; 7 | strategy = s; 8 | nWins = 0; 9 | time = 0.0; 10 | nMoves = 0; 11 | 12 | } 13 | 14 | std::ostream& operator<<(std::ostream& ioOut, const TestPlayer& obj) { 15 | 16 | ioOut << obj.strategyName[obj.strategy] << " " << obj.nWins; 17 | 18 | return ioOut; 19 | } -------------------------------------------------------------------------------- /bots/tulips-and-daisies/TestPlayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class TestPlayer { 5 | public: 6 | 7 | int player; 8 | int strategy; 9 | int nWins; 10 | int nMoves; 11 | 12 | float time; 13 | std::clock_t c_start; 14 | std::clock_t c_end; 15 | 16 | std::vector strategyName = {"strRandom","strCodingame","strNew","strNew2","strMinimax","strNew3"}; 17 | 18 | TestPlayer(int p, int s); 19 | 20 | friend std::ostream& operator<<(std::ostream& ioOut, const TestPlayer& obj); 21 | }; -------------------------------------------------------------------------------- /bots/tulips-and-daisies/Utils.cpp: -------------------------------------------------------------------------------- 1 | #include "Utils.h" 2 | 3 | 4 | int RandomNumber(int N) { 5 | /* generate secret number between 0 and N-1: */ 6 | return rand() % N; 7 | } 8 | 9 | int fibonacci(int n) { 10 | 11 | if (n<=0) { 12 | return 0; 13 | } else { 14 | int a = 0; 15 | int b = 1; 16 | int f = 0; 17 | int s = 1; 18 | for (int i = 0; i < n - 1; i++) { 19 | f = a + b; 20 | a = b; 21 | b = f; 22 | s = s + f; 23 | } 24 | 25 | return s; 26 | } 27 | 28 | } 29 | 30 | int smaller(int a, int b) { 31 | if (a>b) { 32 | return b; 33 | } else { 34 | return a; 35 | } 36 | } 37 | 38 | int larger(int a, int b) { 39 | if (a> validActionCount; std::cin.ignore(); 37 | for (int i = 0; i < validActionCount; i++) { 38 | int row; 39 | int col; 40 | std::cin >> row >> col; std::cin.ignore(); 41 | } 42 | } 43 | 44 | bool GetMyHis(int grow, int &my, int &his, int &lp) { 45 | if (grow == -1) { 46 | // I go first 47 | my = KRIZEC; 48 | his = KROZEC; 49 | lp = his; 50 | } 51 | else 52 | { 53 | // He goes first 54 | his = KRIZEC; 55 | my = KROZEC; 56 | lp = my; 57 | } 58 | return false; 59 | } 60 | 61 | 62 | 63 | std::ostream &operator<<(std::ostream &os, StrategyType st) { 64 | switch (st) { 65 | case RNDSTR: 66 | return os << "RNDSTR"; 67 | case FIRSTSTR: 68 | return os << "FIRSTSTR"; 69 | case SCORESTR: 70 | return os << "SCORESTR"; 71 | case MINIMAXSTR: 72 | return os << "MINIMAXSTR"; 73 | case MONTECARLO: 74 | return os << "MONTE CARLO"; 75 | case ALLTHREE: 76 | return os << "ALLTHREE"; 77 | case MMTREE: 78 | return os << "MMTREE"; 79 | } 80 | return os; 81 | } -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | enum StrategyType { RNDSTR, FIRSTSTR, SCORESTR, MINIMAXSTR, MONTECARLO, ALLTHREE, MMTREE}; 7 | enum runType { CODINGAME, ONEONONE }; 8 | 9 | 10 | constexpr int mmDEPTH = 4; 11 | constexpr int TREETIMELIMIT = 185; 12 | 13 | constexpr int mcDEPTH = 5; 14 | constexpr double mcTIME = 9.0; 15 | 16 | constexpr int EMPTY = 0; 17 | constexpr int KRIZEC = 1; 18 | constexpr int KROZEC = 2; 19 | constexpr int DRAW = 3; 20 | constexpr int TL = 2; 21 | constexpr int TC = 4; 22 | constexpr int TR = 6; 23 | constexpr int CL = 8; 24 | constexpr int CC = 10; 25 | constexpr int CR = 12; 26 | constexpr int BL = 14; 27 | constexpr int BC = 16; 28 | constexpr int BR = 18; 29 | constexpr int HUGENUM = 1000000000; 30 | 31 | const int sbn[3][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } }; 32 | const int posl[3][3] = { { TL,TC,TR },{ CL,CC,CR },{ BL,BC,BR } }; 33 | const int bnCols[10] = { -1,0,3,6,0,3,6,0,3,6 }; 34 | const int bnRows[10] = { -1,0,0,0,3,3,3,6,6,6 }; 35 | 36 | const int poRows[10] = { -1,0,0,0,1,1,1,2,2,2 }; 37 | const int poCols[10] = { -1,0,1,2,0,1,2,0,1,2 }; 38 | 39 | int Other(int player); 40 | 41 | std::string prn(int state); 42 | 43 | int RandomNumber(int N); 44 | 45 | void FakeRead(); 46 | 47 | bool GetMyHis(int grow, int &my, int &his, int &lp); 48 | 49 | std::ostream &operator<<(std::ostream &os, StrategyType st); -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Move.h" 3 | #include "Common.h" 4 | #include "Board.h" 5 | 6 | class Game { 7 | public: 8 | Board ttt[10]; 9 | int my, his; 10 | int LastPlayer; 11 | Move LastMove; 12 | 13 | int NextPlayer(int player); 14 | void playMove(Move m); 15 | 16 | void playMoveFast(int board, int pos); 17 | 18 | void init(); 19 | 20 | void print(); 21 | int score(); 22 | 23 | void copy(int r[]); 24 | void paste(int r[]); 25 | 26 | }; 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/Gametree.cpp: -------------------------------------------------------------------------------- 1 | #include "Gametree.h" 2 | #include "MoveList.h" 3 | #include "Branch.h" 4 | #include 5 | #include /* time */ 6 | #include 7 | #include 8 | 9 | Gametree::Gametree(Game g) 10 | { 11 | using namespace std::chrono; 12 | std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); 13 | 14 | // Do Breath first search 15 | int nTotal = 0; 16 | int jCurrent = 0; 17 | branches.clear(); 18 | 19 | Branch branch(g); 20 | branch.nChildren = 0; 21 | branches.push_back(branch); 22 | 23 | while ((TIME < TREETIMELIMIT) & (jCurrent <= nTotal) ) { 24 | 25 | MoveList moves(branches[jCurrent].game); 26 | branches[jCurrent].nChildren = moves.nmoves; 27 | for (int i = 0; i < branches[jCurrent].nChildren; i++) { 28 | nTotal++; 29 | Branch branch(branches[jCurrent].game); 30 | branch.game.playMoveFast(moves.m[i][0], moves.m[i][1]); 31 | branch.score = branch.game.score(); // score rabim samo na leaves - popravi 32 | branch.nChildren = 0; 33 | branches.push_back(branch); 34 | branches[jCurrent].children[i] = nTotal; 35 | } 36 | jCurrent++; 37 | } 38 | // std::cerr << TIME << " " << " " << branches[jCurrent-1].nChildren << " " << nTotal << std::endl; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/Gametree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Game.h" 3 | #include "Common.h" 4 | #include "Branch.h" 5 | #include 6 | #include 7 | 8 | class Gametree 9 | { 10 | public: 11 | std::vector branches; 12 | 13 | Gametree(Game g); 14 | 15 | 16 | 17 | #define TIME duration_cast>(std::chrono::high_resolution_clock::now() - now).count()*1000 18 | 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = uTTT 2 | VERSION = 1.0 3 | SOURCES = uTTT.o Board.o Game.o Move.o MoveList.o Common.o Strategy.o Gametree.o Branch.o 4 | 5 | ARCH = `uname` 6 | INST = $(HOME)/bin 7 | 8 | HOST = $(shell hostname) 9 | 10 | # 11 | # *************** HOBBIT **************** 12 | # 13 | ifneq (,$(findstring HOGAR,$(HOST))) 14 | 15 | FC = g++ 16 | OBJECTS = $(SOURCES) 17 | KON = 18 | 19 | # Debug version 20 | # OPT = -Wall 21 | # OPDE= d 22 | # Optimized version 23 | OPT = -O3 24 | OPDE= o 25 | 26 | FCOPTS = -std=gnu++11 27 | LDOPTO = 28 | 29 | endif 30 | 31 | 32 | all: $(OBJECTS) 33 | $(FC) -o $(PROGRAM)-$(VERSION)$(KON) $(FCOPTS) $(OPT) $(OBJECTS) $(LDOPTO) 34 | 35 | clean: 36 | rm -f *.o *.mod .#* 37 | 38 | $(OBJECTS): %.o: %.cpp 39 | $(FC) $(FCOPTS) $(OPT) -c $< 40 | 41 | install: 42 | cp $(PROGRAM)-$(VERSION)$(KON) $(INST)/$(PROGRAM)-$(VERSION)-$(OPDE)$(KON) 43 | 44 | 45 | -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/Move.cpp: -------------------------------------------------------------------------------- 1 | #include "Move.h" 2 | #include "Common.h" 3 | #include 4 | 5 | 6 | Move::Move(int grow, int gcol) { 7 | GetBoardNo(grow, gcol); 8 | GetPos(grow, gcol); 9 | }; 10 | 11 | Move::Move() { board = 0; pos = 0; } 12 | 13 | void Move::GetMove(int grow, int gcol) { 14 | GetBoardNo(grow, gcol); 15 | GetPos(grow, gcol); 16 | } 17 | 18 | void Move::GetBoardNo(int grow, int gcol) { 19 | int r = grow / 3; 20 | int c = gcol / 3; 21 | board = sbn[r][c]; 22 | } 23 | 24 | void Move::GetPos(int grow, int gcol) { 25 | int r = grow % 3; 26 | int c = gcol % 3; 27 | pos = posl[r][c]; 28 | } 29 | 30 | void Move::SetRandom() { 31 | int grow = RandomNumber(9); 32 | int gcol = RandomNumber(9); 33 | GetBoardNo(grow, gcol); 34 | GetPos(grow, gcol); 35 | } 36 | 37 | void Move::SetRandomCenter() { 38 | int b = RandomNumber(5) + 1; 39 | if (b == 1) { board = 2; pos = TC; } 40 | if (b == 2) { board = 4; pos = CL; } 41 | if (b == 3) { board = 5; pos = CC; } 42 | if (b == 4) { board = 6; pos = CR; } 43 | if (b == 5) { board = 8; pos = BC; } 44 | } 45 | 46 | std::string Move::print() { 47 | return " (" + std::to_string(bnRows[board] + poRows[pos / 2]) + "," + std::to_string(bnCols[board] + poCols[pos / 2]) + ")"; 48 | } 49 | 50 | std::ostream& operator<<(std::ostream& ioOut, const Move& obj) { 51 | ioOut << bnRows[obj.board] + poRows[obj.pos / 2] << " " << bnCols[obj.board] + poCols[obj.pos / 2]; 52 | return ioOut; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/Move.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | 5 | class Move { 6 | public: 7 | int board; // na katero ttt board 8 | int pos; // pozicija TL,TC, .. 9 | 10 | Move(int grow, int gcol); // constructor 11 | Move(); // default constructor 12 | 13 | void GetMove(int grow, int gcol); 14 | void GetBoardNo(int grow, int gcol); 15 | void GetPos(int grow, int gcol); 16 | void SetRandom(); 17 | void SetRandomCenter(); 18 | std::string print(); 19 | 20 | friend std::ostream& operator<<(std::ostream& ioOut, const Move& obj); 21 | }; 22 | -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/MoveList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Game.h" 3 | 4 | class MoveList 5 | { 6 | public: 7 | 8 | int nmoves; 9 | int m[81][2]; 10 | 11 | MoveList(Game g); 12 | 13 | 14 | MoveList(); 15 | ~MoveList(); 16 | Move rndMove(); 17 | Move getMove(int id); 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /bots/ultimate-tic-tac-toe/Strategy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Game.h" 4 | #include "Common.h" 5 | #include 6 | 7 | Move StrategyRandom(Game g, bool firstTurn); 8 | Move StrategyFirst(Game g, bool firstTurn); 9 | Move StrategyScore(Game game, bool firstTurn); 10 | Move StrategyMiniMax(Game game, bool firstTurn); 11 | Move MiniMax(Game game); 12 | Move DoMagic(StrategyType strategy, Game g, bool firstTurn); 13 | void testTIME(Game game); 14 | 15 | #define TIME duration_cast>(std::chrono::high_resolution_clock::now() - now).count()*1000 16 | -------------------------------------------------------------------------------- /bots/winter-challange-2024/Ai.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "Map.h" 8 | #include "Player.h" 9 | #include "Move.h" 10 | 11 | class Ai { 12 | public: 13 | 14 | Ai(); 15 | 16 | std::vector wait(const Map& map, Player& player, Player& opponent, int round); 17 | std::vector simple(const Map& map, Player& player, Player& opponent, int round); 18 | 19 | 20 | }; -------------------------------------------------------------------------------- /bots/winter-challange-2024/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | // Offsets for cardinal directions 5 | static constexpr int offsets[4][2] = { 6 | {-1, 0}, // West 7 | {0, 1}, // South 8 | {1, 0}, // East 9 | {0, -1} // North 10 | }; 11 | 12 | static std::string DIR[4] = {"W", "S", "E", "N"}; 13 | static std::string REVERSEDIR[4] = {"E", "N", "W", "S"}; -------------------------------------------------------------------------------- /bots/winter-challange-2024/Makefile: -------------------------------------------------------------------------------- 1 | # Default rule 2 | all: merge 3 | 4 | # Merge command 5 | merge: 6 | codingame-merge -o ../cg.cpp -w . -m main.cpp 7 | 8 | # Phony targets 9 | .PHONY: all merge -------------------------------------------------------------------------------- /bots/winter-challange-2024/Map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include // For std::pair 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "TileType.h" 11 | #include "Posdir.h" 12 | #include "Common.h" 13 | 14 | class Map { 15 | public: 16 | // Constructor 17 | Map(int width, int height); 18 | void readMap(); 19 | 20 | // Methods to manipulate tiles 21 | bool setTile(int x, int y, const TileType& tile); 22 | std::vector> getAdjacentToMyTiles() const; 23 | std::vector> getBASICcandidates(int organism) const; 24 | std::vector> getVitaminList(int organism) const; 25 | std::vector> getEmptyTilesBorderingABCOrD() const; 26 | std::vector getHarvesterPositions(std::vector> candidates, int owner) const; 27 | // Method to get cardinal directions of neighboring vitamin tiles 28 | std::vector getNeighboringVitaminDirections(int x, int y) const; 29 | int getAdjacentOrganIdOwnedByMe(int x, int y) const; 30 | TileType getTile(int x, int y) const; 31 | std::pair getLongestDir(int x, int y) const; 32 | std::pair getSporeTarget(Posdir ps) const; 33 | std::vector getSporeList(int organism) const; 34 | std::string getEnemyDirection(int x, int y) const; 35 | int countHarvesters(const int organism, const std::string& vitaminType) const; 36 | std::vector> countAndSortHarvesters(std::vector organisms) const; 37 | 38 | 39 | // Getters for width and height 40 | int getWidth() const; 41 | int getHeight() const; 42 | 43 | // Method to print debug information for all tiles 44 | void debugPrint() const; 45 | 46 | int findPathToTileType(int startX, int startY, const std::string& targetTileType) const; 47 | 48 | 49 | private: 50 | int width, height; 51 | std::vector> tiles; 52 | 53 | // Helper method to validate coordinates 54 | bool isValidPosition(int x, int y) const; 55 | bool isHarvested(int x, int y, int owner) const; 56 | }; 57 | -------------------------------------------------------------------------------- /bots/winter-challange-2024/Move.cpp: -------------------------------------------------------------------------------- 1 | #include "Move.h" 2 | 3 | // Constructor 4 | Move::Move(int score, const std::string& cmd) : score(score), cmd(cmd) {} 5 | 6 | // Getters 7 | int Move::getScore() const { 8 | return score; 9 | } 10 | 11 | std::string Move::getCMD() const { 12 | return cmd; 13 | } 14 | 15 | // Setters 16 | void Move::setScore(int newScore) { 17 | score = newScore; 18 | } 19 | 20 | void Move::setCMD(const std::string& newCMD) { 21 | cmd = newCMD; 22 | } 23 | 24 | void Move::print() { 25 | std::cout << cmd << std::endl; 26 | } -------------------------------------------------------------------------------- /bots/winter-challange-2024/Move.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class Move { 7 | public: 8 | // Constructor 9 | Move(int score, const std::string& cmd); 10 | 11 | // Getters 12 | int getScore() const; 13 | std::string getCMD() const; 14 | 15 | // Setters 16 | void setScore(int newScore); 17 | void setCMD(const std::string& newCMD); 18 | 19 | void print(); 20 | 21 | private: 22 | int score; 23 | std::string cmd; 24 | }; -------------------------------------------------------------------------------- /bots/winter-challange-2024/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player() : id(-1), a(0), b(0), c(0), d(0) {} 4 | 5 | void Player::readProteins() { 6 | std::cin >> a >> b >> c >> d; std::cin.ignore(); 7 | } 8 | 9 | void Player::countOrganisms(const Map& map) { 10 | std::set organismSet; 11 | for (int x = 0; x < map.getWidth(); ++x) { 12 | for (int y = 0; y < map.getHeight(); ++y) { 13 | TileType tile = map.getTile(x, y); 14 | if (tile.getOwner() == id) { 15 | organismSet.emplace(tile.getOrganRootId()); 16 | } 17 | } 18 | } 19 | organisms = std::vector(organismSet.begin(), organismSet.end()); 20 | } 21 | 22 | bool Player::isBasicPossible() { 23 | return a > 0; 24 | } 25 | 26 | bool Player::isSporerPossible() { 27 | return b > 0 && d > 0; 28 | } 29 | 30 | bool Player::isHarvesterPossible() { 31 | return c > 0 && d > 0; 32 | } 33 | 34 | bool Player::isTentaclePossible() { 35 | return b >0 && c > 0; 36 | } 37 | 38 | bool Player::isNewRootPossible() { 39 | return a > 0 && b > 0 && c > 0 && d > 0; 40 | } -------------------------------------------------------------------------------- /bots/winter-challange-2024/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "Map.h" 6 | 7 | class Player { 8 | public: 9 | int id; 10 | int a, b, c, d; // Protein stocks 11 | std::vector organisms; // List of player's organisms 12 | 13 | Player(); 14 | 15 | void readProteins(); 16 | void countOrganisms(const Map& map); 17 | bool isBasicPossible(); 18 | bool isSporerPossible(); 19 | bool isHarvesterPossible(); 20 | bool isTentaclePossible(); 21 | bool isNewRootPossible(); 22 | 23 | }; -------------------------------------------------------------------------------- /bots/winter-challange-2024/Posdir.cpp: -------------------------------------------------------------------------------- 1 | #include "Posdir.h" 2 | 3 | // Constructor 4 | Posdir::Posdir(int x, int y, const std::string& dir) : x(x), y(y), dir(dir) {} 5 | 6 | // Getters 7 | int Posdir::getX() const { 8 | return x; 9 | } 10 | 11 | int Posdir::getY() const { 12 | return y; 13 | } 14 | 15 | std::string Posdir::getDir() const { 16 | return dir; 17 | } 18 | 19 | // Setters 20 | void Posdir::setX(int newX) { 21 | x = newX; 22 | } 23 | 24 | void Posdir::setY(int newY) { 25 | y = newY; 26 | } 27 | 28 | void Posdir::setDir(const std::string& newDir) { 29 | dir = newDir; 30 | } 31 | 32 | // Comparison operator 33 | bool Posdir::operator<(const Posdir& other) const { 34 | // Define the comparison logic 35 | if (x != other.x) { 36 | return x < other.x; 37 | } 38 | if (y != other.y) { 39 | return y < other.y; 40 | } 41 | return dir < other.dir; 42 | } -------------------------------------------------------------------------------- /bots/winter-challange-2024/Posdir.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Posdir { 6 | public: 7 | // Constructor 8 | Posdir(int x, int y, const std::string& dir); 9 | 10 | // Getters 11 | int getX() const; 12 | int getY() const; 13 | std::string getDir() const; 14 | 15 | // Setters 16 | void setX(int newX); 17 | void setY(int newY); 18 | void setDir(const std::string& newDir); 19 | 20 | // Comparison operator 21 | bool operator<(const Posdir& other) const; 22 | 23 | 24 | private: 25 | int x, y; 26 | std::string dir; 27 | }; -------------------------------------------------------------------------------- /bots/winter-challange-2024/TileType.cpp: -------------------------------------------------------------------------------- 1 | #include "TileType.h" 2 | 3 | // Constructor 4 | TileType::TileType(int x, int y, const std::string& type, int owner, 5 | int organ_id, const std::string& organ_dir, 6 | int organ_parent_id, int organ_root_id) 7 | : x(x), y(y), type(type), owner(owner), organ_id(organ_id), 8 | organ_dir(organ_dir), organ_parent_id(organ_parent_id), organ_root_id(organ_root_id) {} 9 | 10 | // Getters 11 | int TileType::getX() const { return x; } 12 | int TileType::getY() const { return y; } 13 | const std::string& TileType::getType() const { return type; } 14 | int TileType::getOwner() const { return owner; } 15 | int TileType::getOrganId() const { return organ_id; } 16 | const std::string& TileType::getOrganDir() const { return organ_dir; } 17 | int TileType::getOrganParentId() const { return organ_parent_id; } 18 | int TileType::getOrganRootId() const { return organ_root_id; } 19 | bool TileType::isVitamin() const { return type == "A" || type == "B" || type == "C" || type == "D"; } 20 | 21 | // Setters 22 | void TileType::setType(const std::string& type) { this->type = type; } 23 | void TileType::setOwner(int owner) { this->owner = owner; } 24 | void TileType::setOrganId(int organ_id) { this->organ_id = organ_id; } 25 | void TileType::setOrganDir(const std::string& organ_dir) { this->organ_dir = organ_dir; } 26 | void TileType::setOrganParentId(int parent_id) { this->organ_parent_id = parent_id; } 27 | void TileType::setOrganRootId(int root_id) { this->organ_root_id = root_id; } -------------------------------------------------------------------------------- /bots/winter-challange-2024/TileType.h: -------------------------------------------------------------------------------- 1 | #ifndef TILETYPE_H 2 | #define TILETYPE_H 3 | 4 | #include 5 | 6 | class TileType { 7 | public: 8 | // Constructor 9 | TileType(int x, int y, const std::string& type = "EMPTY", int owner = -1, 10 | int organ_id = 0, const std::string& organ_dir = "X", 11 | int organ_parent_id = 0, int organ_root_id = 0); 12 | 13 | // Getters and setters 14 | int getX() const; 15 | int getY() const; 16 | const std::string& getType() const; 17 | int getOwner() const; 18 | int getOrganId() const; 19 | const std::string& getOrganDir() const; 20 | int getOrganParentId() const; 21 | int getOrganRootId() const; 22 | bool isVitamin() const; 23 | 24 | void setType(const std::string& type); 25 | void setOwner(int owner); 26 | void setOrganId(int organ_id); 27 | void setOrganDir(const std::string& organ_dir); 28 | void setOrganParentId(int parent_id); 29 | void setOrganRootId(int root_id); 30 | 31 | private: 32 | int x, y; // Grid coordinates 33 | std::string type; // Type of the tile 34 | int owner; // Owner: 1 (you), 0 (enemy), -1 (neither) 35 | int organ_id; // Organ ID (0 if not an organ) 36 | std::string organ_dir; // Direction (N, E, S, W, or X) 37 | int organ_parent_id; // Parent organ ID 38 | int organ_root_id; // Root organ ID 39 | }; 40 | 41 | #endif // TILETYPE_H -------------------------------------------------------------------------------- /bots/winter-challange-2024/main.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC optimize("O3,inline,omit-frame-pointer,unroll-loops") 2 | 3 | #include 4 | #include 5 | #include "Map.h" 6 | #include "Move.h" 7 | #include "Posdir.h" 8 | #include "Player.h" 9 | #include "Ai.h" 10 | 11 | int main() 12 | { 13 | int width; // columns in the game grid 14 | int height; // rows in the game grid 15 | std::cin >> width >> height; std::cin.ignore(); 16 | 17 | int round = 0; // count moves 18 | 19 | Player player; 20 | Player opponent; 21 | Ai ai; 22 | 23 | player.id = 1; 24 | opponent.id = 0; 25 | 26 | // game loop 27 | while (1) { 28 | 29 | round++; 30 | Map map(width, height); 31 | map.readMap(); 32 | player.countOrganisms(map); 33 | opponent.countOrganisms(map); 34 | player.readProteins(); 35 | opponent.readProteins(); 36 | 37 | std::vector moves = ai.simple(map, player, opponent, round); 38 | 39 | for (Move& m : moves) { 40 | m.print(); 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /code-golf/chuck-norris-codesize.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/multiplayer/codegolf/chuck-norris-codesize 2 | #include 3 | #include 4 | #define L length() 5 | main(){std::string M,b,a,l;int i,j,m;getline(std::cin,M);b=""; 6 | for(i=0;i=1)?a="1"+a:a="0"+a;m<<=1;}b+=a;} 7 | a="";for(j=0;j0){a+=" ";}(M=="0")?a+="0":a;a+="0 ";}a+="0";l=M;}std::cout< 3 | using namespace std;int R,P,L[9];string H;main(){for(cin>>P>>R>>R>>R>>L[R]>>R;P--;)cin>>R>>L[R];for(;cin>>P>>R>>H;cout<L[P]?H="BLOCK":H="WAIT";} 4 | 5 | -------------------------------------------------------------------------------- /code-golf/power-of-thor.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/multiplayer/codegolf/power-of-thor 2 | #import 3 | #define P std::cout<< 4 | main(){int A,B,C,D;std::cin>>A>>B>>C>>D;for(;;){DA?P"W",C--:0;P"\n";}} 5 | -------------------------------------------------------------------------------- /code-golf/temperature-code-golf.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/multiplayer/codegolf/temperature-code-golf 2 | #include 3 | main(){int n;std::cin>>n;int m=0;if(n>0){m=999;for(int i=0;i>t;if(t*t0)){m=t;}}}std::cout< 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | 15 | int main() 16 | { 17 | int val[100]; 18 | bool done[100]; 19 | int N; 20 | int a; 21 | int b; 22 | string operation[100]; 23 | string arg1[100]; 24 | string arg2[100]; 25 | 26 | cin >> N; cin.ignore(); 27 | for (int i = 0; i < N; i++) { 28 | done[i] = false; 29 | cin >> operation[i] >> arg1[i] >> arg2[i]; cin.ignore(); 30 | // cerr << operation[i] << " " << arg1[i] << " " << arg2[i] << endl; 31 | } 32 | bool alldone = false; 33 | while (!alldone) { 34 | alldone = true; 35 | for (int i = 0; i < N; i++) { 36 | if (!done[i]) { 37 | if (operation[i] == "VALUE") { 38 | if (arg1[i].substr(0,1)=="$") { 39 | int r = stoi(arg1[i].substr(1,arg1[i].length())); 40 | if (done[r]) {val[i]=val[r]; done[i]=true; } 41 | } else { val[i] = stoi(arg1[i]); done[i]=true; } 42 | } else { 43 | 44 | bool ok1; 45 | bool ok2; 46 | if (arg1[i].substr(0,1)=="$") {int r = stoi(arg1[i].substr(1,arg1[i].length())); a = val[r]; ok1 = done[r]; } else { a=stoi(arg1[i]); ok1=true; } 47 | if (arg2[i].substr(0,1)=="$") {int t = stoi(arg2[i].substr(1,arg1[i].length())); b = val[t]; ok2 = done[t]; } else { b=stoi(arg2[i]); ok2=true;} 48 | 49 | if (ok1 && ok2) { 50 | if (operation[i] == "ADD") { val[i] = a + b;done[i]=true;} 51 | if (operation[i] == "SUB") { val[i] = a - b;done[i]=true; } 52 | if (operation[i] == "MULT") { val[i] = a * b;done[i]=true; } 53 | } else { 54 | alldone = false; 55 | } 56 | }} 57 | } 58 | 59 | 60 | } 61 | for (int i = 0; i < N; i++) { 62 | 63 | // Write an action using cout. DON'T FORGET THE "<< endl" 64 | // To debug: cerr << "Debug messages..." << endl; 65 | 66 | cout << val[i] << endl; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /easy/ascii-art.vb: -------------------------------------------------------------------------------- 1 | ' https://www.codingame.com/training/easy/ascii-art 2 | 3 | Module Solution 4 | ' Auto-generated code below aims at helping you parse 5 | ' the standard input according to the problem statement. 6 | 7 | Sub Main () 8 | 9 | Dim L as Integer 10 | L = Console.ReadLine() 11 | 12 | Dim H as Integer 13 | H = Console.ReadLine() 14 | 15 | Dim T as String 16 | T = Console.ReadLine() 17 | 18 | Dim Dolzina as Integer = T.Length 19 | dim aznak as integer 20 | dim znak as Char 21 | dim MojaCrka as String = "" 22 | 23 | 24 | 25 | For i as Integer = 0 To H-1 26 | Dim ROW as String 27 | ROW = Console.ReadLine() 28 | 29 | for j as Integer = 0 To Dolzina-1 30 | 31 | znak = T.SubString(j,1) 32 | aznak = Asc(znak) ' A=65, a=97 33 | 34 | 35 | if (aznak>64 And aznak<97) then 36 | aznak=(aznak-65)*L 37 | else if (aznak>96 And aznak<129) then 38 | aznak=(aznak-97)*L 39 | else 40 | aznak=(asc("Z")+1-65)*L 41 | end if 42 | 43 | 44 | mojacrka=mojacrka+ROW.SubString(aznak,L) 45 | 46 | next 47 | 48 | Console.WriteLine(mojacrka) 49 | mojacrka="" 50 | 51 | Next 52 | 53 | End Sub 54 | End Module 55 | -------------------------------------------------------------------------------- /easy/brackets-extreme-edition.cpp: -------------------------------------------------------------------------------- 1 | /** /https://www.codingame.com/training/easy/brackets-extreme-edition **/ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | 15 | int main() 16 | { 17 | string S; 18 | cin >> S; cin.ignore(); 19 | 20 | int o = 0; 21 | int n = 0; 22 | int z = 0; 23 | string last; 24 | string C = ""; 25 | 26 | for (int i = 0; i 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | class Point { 12 | public: 13 | float x; 14 | float y; 15 | 16 | void normalize() { 17 | float d = sqrt(x*x+y*y); 18 | x=x/d; 19 | y=y/d; 20 | } 21 | }; 22 | 23 | class Target { 24 | public: 25 | int N; 26 | vector corners; 27 | vector centers; 28 | vector normals; 29 | 30 | void CalculateCenters() { 31 | Point s; 32 | for (int i = 0; i < N-1; i++) { 33 | s.x = 0.5 * (corners.at(i).x + corners.at(i+1).x); 34 | s.y = 0.5 * (corners.at(i).y + corners.at(i+1).y); 35 | centers.push_back(s); 36 | } 37 | s.x = 0.5 * (corners.at(N-1).x + corners.at(0).x); 38 | s.y = 0.5 * (corners.at(N-1).y + corners.at(0).y); 39 | centers.push_back(s); 40 | } 41 | 42 | void CalculateNormals() { 43 | Point s; 44 | for (int i = 0; i < N-1; i++) { 45 | s.y = corners.at(i).x - corners.at(i+1).x; 46 | s.x = - ( corners.at(i).y - corners.at(i+1).y ); 47 | s.normalize(); 48 | normals.push_back(s); 49 | } 50 | s.y = corners.at(N-1).x - corners.at(0).x; 51 | s.x = - ( corners.at(N-1).y - corners.at(0).y ); 52 | s.normalize(); 53 | normals.push_back(s); 54 | } 55 | 56 | }; 57 | 58 | float DotProduct(Point p1, Point p2) { 59 | return p1.x*p2.x + p1.y*p2.y; 60 | } 61 | 62 | string HitOrMiss(Target target, Point shot) { 63 | 64 | string HorM = "hit"; 65 | for (int i = 0; i < target.N; i++) { 66 | Point p; 67 | p.x = target.centers.at(i).x - shot.x; 68 | p.y = target.centers.at(i).y - shot.y; 69 | if ( DotProduct(p,target.normals.at(i)) < 0.0 ) {HorM="miss";} 70 | } 71 | 72 | return HorM; 73 | } 74 | 75 | 76 | int main() 77 | { 78 | Target target; 79 | Point p; 80 | 81 | cin >> target.N; cin.ignore(); 82 | for (int i = 0; i < target.N; i++) { 83 | cin >> p.x >> p.y; cin.ignore(); 84 | target.corners.push_back(p); 85 | } 86 | target.CalculateCenters(); 87 | target.CalculateNormals(); 88 | 89 | int M; 90 | cin >> M; cin.ignore(); 91 | for (int i = 0; i < M; i++) { 92 | cin >> p.x >> p.y; cin.ignore(); 93 | cout << HitOrMiss(target,p) << endl; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /easy/defibrillators.vb: -------------------------------------------------------------------------------- 1 | ' https://www.codingame.com/training/easy/defibrillators 2 | 3 | Module Solution 4 | ' Auto-generated code below aims at helping you parse 5 | ' the standard input according to the problem statement. 6 | 7 | Sub Main () 8 | 9 | Dim LON as String 10 | LON = Console.ReadLine() 11 | 12 | ' convert lon to number 13 | Dim fLON as Double = Convert.ToDouble(REPLACE(LON,",","."))*3.141592/180.0 14 | 15 | 16 | 17 | Dim LAT as String 18 | LAT = Console.ReadLine() 19 | 20 | ' convert lon to number 21 | Dim fLAT as Double = Convert.ToDouble(REPLACE(LAT,",","."))*3.141592/180.0 22 | 23 | 24 | Dim N as Integer 25 | N = Console.ReadLine() 26 | 27 | dim num(N) as string 28 | dim name(N) as string 29 | dim addr(N) as string 30 | dim phone(N) as string 31 | dim dlon(N) as Double 32 | dim dlat(N) as Double 33 | dim x as double 34 | dim y as double 35 | dim d as double 36 | dim mind as double = 10000 37 | dim j as integer 38 | 39 | For i as Integer = 0 To N-1 40 | Dim DEFIB as String 41 | DEFIB = Console.ReadLine() 42 | Dim Array() As String = Split(DEFIB,";") 43 | num(i)=Array(0) 44 | name(i)=Array(1) 45 | addr(i)=Array(2) 46 | phone(i)=Array(3) 47 | dlon(i)=Convert.ToDouble(REPLACE(Array(4),",","."))*3.141592/180.0 48 | dlat(i)=Convert.ToDouble(REPLACE(Array(5),",","."))*3.141592/180.0 49 | 50 | x=(dlon(i)-flon)*Math.cos(0.5*(dlon(i)+flon)) 51 | y=dlat(i)-flat 52 | d=math.sqrt(x*x+y*y)*6371 53 | 54 | if d 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | int main() 15 | { 16 | int N; 17 | cin >> N; cin.ignore(); 18 | int Pi[N]; 19 | for (int i = 0; i < N; i++) { 20 | cin >> Pi[i]; cin.ignore(); 21 | } 22 | 23 | sort(Pi, Pi + N); 24 | int dmin = 100000; 25 | 26 | for (int i = 0; i < N-1; i++) { 27 | int d = abs(Pi[i]-Pi[i+1]); 28 | if (d 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | 15 | class pos { 16 | public: 17 | int row; 18 | int col; 19 | 20 | 21 | bool manh(int r, int c, int L) { 22 | 23 | int minR = row - (L - 1); 24 | int maxR = row + (L - 1); 25 | int minC = col - (L - 1); 26 | int maxC = col + (L - 1); 27 | 28 | if (r >= minR & r <= maxR & c <= maxC & c >= minC) { return true; } 29 | else { return false; } 30 | } 31 | }; 32 | 33 | int main() 34 | { 35 | vectorcandles; 36 | 37 | int N; 38 | cin >> N; cin.ignore(); 39 | int L; 40 | cin >> L; cin.ignore(); 41 | for (int i = 0; i < N; i++) { 42 | string LINE; 43 | getline(cin, LINE); 44 | int col=0; 45 | for (int j = 0; j 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | 15 | int main() 16 | { 17 | int surfaceN; // the number of points used to draw the surface of Mars. 18 | cin >> surfaceN; cin.ignore(); 19 | for (int i = 0; i < surfaceN; i++) { 20 | int landX; // X coordinate of a surface point. (0 to 6999) 21 | int landY; // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. 22 | cin >> landX >> landY; cin.ignore(); 23 | } 24 | 25 | // game loop 26 | while (1) { 27 | int X; 28 | int Y; 29 | int hSpeed; // the horizontal speed (in m/s), can be negative. 30 | int vSpeed; // the vertical speed (in m/s), can be negative. 31 | int fuel; // the quantity of remaining fuel in liters. 32 | int rotate; // the rotation angle in degrees (-90 to 90). 33 | int power; // the thrust power (0 to 4). 34 | cin >> X >> Y >> hSpeed >> vSpeed >> fuel >> rotate >> power; cin.ignore(); 35 | 36 | // Write an action using cout. DON'T FORGET THE "<< endl" 37 | // To debug: cerr << "Debug messages..." << endl; 38 | if (vSpeed < -35 & power < 4) { 39 | power = power + 1; 40 | } 41 | if (vSpeed > -30 & power > 0) { 42 | power = power - 1; 43 | } 44 | 45 | // 2 integers: rotate power. rotate is the desired rotation angle (should be 0 for level 1), power is the desired thrust power (0 to 4). 46 | cout << "0 " << power << endl; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /easy/mars-lander-episode-1.vb: -------------------------------------------------------------------------------- 1 | ' /https://www.codingame.com/training/easy/mars-lander-episode-1 2 | 3 | Module Player 4 | ' Auto-generated code below aims at helping you parse 5 | ' the standard input according to the problem statement. 6 | 7 | Sub Main () 8 | Dim inputs as String() 9 | Dim surfaceN as Integer 10 | surfaceN = Console.ReadLine() ' the number of points used to draw the surface of Mars. 11 | 12 | For i as Integer = 0 To surfaceN-1 13 | 14 | Dim landX as Integer ' X coordinate of a surface point. (0 to 6999) 15 | Dim landY as Integer ' Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. 16 | inputs = Console.ReadLine().Split(" ") 17 | landX = inputs(0) 18 | landY = inputs(1) 19 | 20 | Next 21 | 22 | ' game loop 23 | While True 24 | Dim X as Integer 25 | Dim Y as Integer 26 | Dim hSpeed as Integer ' the horizontal speed (in m/s), can be negative. 27 | Dim vSpeed as Integer ' the vertical speed (in m/s), can be negative. 28 | Dim fuel as Integer ' the quantity of remaining fuel in liters. 29 | Dim rotate as Integer ' the rotation angle in degrees (-90 to 90). 30 | Dim power as Integer ' the thrust power (0 to 4). 31 | inputs = Console.ReadLine().Split(" ") 32 | X = inputs(0) 33 | Y = inputs(1) 34 | hSpeed = inputs(2) 35 | vSpeed = inputs(3) 36 | fuel = inputs(4) 37 | rotate = inputs(5) 38 | power = inputs(6) 39 | 40 | ' Write an action using Console.WriteLine() 41 | ' To debug: Console.Error.WriteLine("Debug messages...") 42 | if vspeed<-35 then 43 | power=4 44 | else 45 | power=3 46 | end if 47 | Console.WriteLine("0 "& power) 48 | ' 2 integers: rotate power. rotate is the desired rotation angle (should be 0 for level 1), power is the desired thrust power (0 to 4). 49 | ' Console.WriteLine("0 3") 50 | End While 51 | End Sub 52 | End Module 53 | -------------------------------------------------------------------------------- /easy/mime-type.vb: -------------------------------------------------------------------------------- 1 | ' https://www.codingame.com/training/easy/mime-type 2 | 3 | Module Solution 4 | ' Auto-generated code below aims at helping you parse 5 | ' the standard input according to the problem statement. 6 | 7 | Sub Main () 8 | 9 | Dim N as Integer 10 | N = Console.ReadLine() ' Number of elements which make up the association table. 11 | 12 | Dim Q as Integer 13 | Q = Console.ReadLine() ' Number Q of file names to be analyzed. 14 | 15 | Dim jEXT(N) as String 16 | Dim jMT(N) as String 17 | 18 | For i as Integer = 0 To N-1 19 | Dim inputs as String() 20 | Dim EXT as String ' file extension 21 | Dim MT as String ' MIME type. 22 | inputs = Console.ReadLine().Split(" ") 23 | EXT = inputs(0) 24 | MT = inputs(1) 25 | jEXT(i)=LCASE(EXT) 26 | jMT(i)=MT 27 | 28 | 29 | Next 30 | 31 | Console.Error.WriteLine(N & " " & Q) 32 | 33 | Dim j as integer 34 | Dim kon as String 35 | For i as Integer = 0 To Q-1 36 | Dim FNAME as String 37 | FNAME = Console.ReadLine() ' One file name per line. 38 | 39 | j = FNAME.LastIndexOf(".") 40 | If (j=-1) THEN 41 | kon="" 42 | ELSE 43 | kon = LCASE(FNAME.SubString(j+1,FNAME.Length-j-1)) 44 | END IF 45 | 46 | Dim a as Integer =0 47 | For k as Integer = 0 To N-1 48 | IF kon=jEXT(k) THEN 49 | Console.WriteLine(jMT(k)) 50 | a=1 51 | EXIT FOR 52 | END IF 53 | NEXT 54 | IF a=0 THEN 55 | Console.WriteLine("UNKNOWN") 56 | END IF 57 | 58 | Next 59 | 60 | 61 | End Sub 62 | End Module 63 | -------------------------------------------------------------------------------- /easy/nature-of-quadrilaterals.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/easy/nature-of-quadrilaterals 2 | 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | /** 12 | * Auto-generated code below aims at helping you parse 13 | * the standard input according to the problem statement. 14 | **/ 15 | int main() 16 | { 17 | int n; 18 | cin >> n; cin.ignore(); 19 | for (int i = 0; i < n; i++) { 20 | string A; 21 | int xA; 22 | int yA; 23 | string B; 24 | int xB; 25 | int yB; 26 | string C; 27 | int xC; 28 | int yC; 29 | string D; 30 | int xD; 31 | int yD; 32 | cin >> A >> xA >> yA >> B >> xB >> yB >> C >> xC >> yC >> D >> xD >> yD; cin.ignore(); 33 | 34 | int lenAB = (xA-xB)*(xA-xB)+(yA-yB)*(yA-yB); 35 | int lenBC = (xC-xB)*(xC-xB)+(yC-yB)*(yC-yB); 36 | int lenCD = (xC-xD)*(xC-xD)+(yC-yD)*(yC-yD); 37 | int lenDA = (xA-xD)*(xA-xD)+(yA-yD)*(yA-yD); 38 | 39 | int square=0; 40 | int rhombus=0; 41 | int rectangle=0; 42 | int parallelogram=0; 43 | 44 | int alfa = (xB-xA)*(xD-xA)+(yB-yA)*(yD-yA); 45 | int beta = (xC-xB)*(xA-xB)+(yC-yB)*(yA-yB); 46 | int gamma =(xD-xC)*(xB-xC)+(yD-yC)*(yB-yC); 47 | int delta =(xA-xD)*(xC-xD)+(yA-yD)*(yC-yD); 48 | 49 | if (lenAB==lenBC & lenBC==lenCD & lenCD==lenDA & lenDA==lenAB) { 50 | rhombus=1; 51 | } 52 | 53 | if (alfa-gamma==0 & beta-delta==0) { 54 | parallelogram=1; 55 | } 56 | 57 | if (alfa==0 & beta==0 & gamma==0 & delta==0) { 58 | rectangle=1; 59 | } 60 | 61 | if (rhombus==1 & rectangle==1) { 62 | cout << A << B << C << D << " is a " << "square." << endl; 63 | } else if (rectangle==1) { 64 | cout << A << B << C << D << " is a " << "rectangle." << endl; 65 | } else if (rhombus==1) { 66 | cout << A << B << C << D << " is a " << "rhombus." << endl; 67 | } else if (parallelogram==1) { 68 | cout << A << B << C << D << " is a " << "parallelogram." << endl; 69 | } else { 70 | cout << A << B << C << D << " is a " << "quadrilateral." << endl; 71 | 72 | } 73 | 74 | } 75 | 76 | // Write an action using cout. DON'T FORGET THE "<< endl" 77 | // To debug: cerr << "Debug messages..." << endl; 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /easy/onboarding.cpp: -------------------------------------------------------------------------------- 1 | // /https://www.codingame.com/training/easy/onboarding 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | 10 | // game loop 11 | while (1) { 12 | string enemy1; // name of enemy 1 13 | cin >> enemy1; cin.ignore(); 14 | int dist1; // distance to enemy 1 15 | cin >> dist1; cin.ignore(); 16 | string enemy2; // name of enemy 2 17 | cin >> enemy2; cin.ignore(); 18 | int dist2; // distance to enemy 2 19 | cin >> dist2; cin.ignore(); 20 | 21 | 22 | if (dist1 < dist2) { 23 | cout << enemy1 << endl; 24 | } else { 25 | cout << enemy2 << endl; 26 | } 27 | 28 | // Write an action using cout. DON'T FORGET THE "<< endl" 29 | 30 | // Enter the code here 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /easy/onboarding.vb: -------------------------------------------------------------------------------- 1 | ' /https://www.codingame.com/training/easy/onboarding 2 | 3 | Module Player 4 | ' CodinGame planet is being attacked by slimy insectoid aliens. 5 | ' <--- 6 | ' Hint:To protect the planet, you can implement the pseudo-code provided in the statement, below the player. 7 | 8 | Sub Main () 9 | 10 | ' game loop 11 | While True 12 | Dim enemy1 as String 13 | enemy1 = Console.ReadLine() ' name of enemy 1 14 | 15 | Dim dist1 as Integer 16 | dist1 = Console.ReadLine() ' distance to enemy 1 17 | 18 | Dim enemy2 as String 19 | enemy2 = Console.ReadLine() ' name of enemy 2 20 | 21 | Dim dist2 as Integer 22 | dist2 = Console.ReadLine() ' distance to enemy 2 23 | 24 | ' Write an action using Console.WriteLine() 25 | ' To debug: Console.Error.WriteLine("Debug messages...") 26 | 27 | 28 | ' You have to output a correct ship name to shoot ("Buzz", enemy1, enemy2, ...) 29 | Console.WriteLine("name of the enemy") 30 | End While 31 | End Sub 32 | End Module 33 | -------------------------------------------------------------------------------- /easy/power-of-thor-episode-1.cpp: -------------------------------------------------------------------------------- 1 | // /https://www.codingame.com/training/easy/power-of-thor-episode-1 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | * --- 14 | * Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders. 15 | **/ 16 | 17 | int main() 18 | { 19 | int lightX; // the X position of the light of power 20 | int lightY; // the Y position of the light of power 21 | int initialTX; // Thor's starting X position 22 | int initialTY; // Thor's starting Y position 23 | cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore(); 24 | 25 | int thorX = initialTX; 26 | int thorY = initialTY; 27 | 28 | // game loop 29 | while (1) { 30 | int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line. 31 | cin >> remainingTurns; cin.ignore(); 32 | 33 | // Write an action using cout. DON'T FORGET THE "<< endl" 34 | // To debug: cerr << "Debug messages..." << endl; 35 | cerr << "(" << thorX << "," << thorY << ")" << endl; 36 | 37 | if (lightY - thorY > 0) { 38 | cout << "S" << endl; 39 | thorY = thorY + 1; 40 | } 41 | 42 | if (lightY - thorY < 0) { 43 | cout << "N" << endl; 44 | thorY = thorY - 1; 45 | } 46 | 47 | if (lightY - thorY == 0) { 48 | 49 | if (lightX - thorX > 0) { 50 | cout << "E" << endl; 51 | thorX = thorX + 1; 52 | } 53 | 54 | if (lightX - thorX < 0) { 55 | cout << "W" << endl; 56 | thorX = thorX - 1; 57 | } 58 | } 59 | 60 | // A single line providing the move to be made: N NE E SE S SW W or NW 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /easy/power-of-thor-episode-1.py: -------------------------------------------------------------------------------- 1 | # /https://www.codingame.com/training/easy/power-of-thor-episode-1 2 | 3 | import sys 4 | import math 5 | 6 | # Auto-generated code below aims at helping you parse 7 | # the standard input according to the problem statement. 8 | # --- 9 | # Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders. 10 | 11 | # light_x: the X position of the light of power 12 | # light_y: the Y position of the light of power 13 | # initial_tx: Thor's starting X position 14 | # initial_ty: Thor's starting Y position 15 | light_x, light_y, tx, ty = [int(i) for i in input().split()] 16 | 17 | # game loop 18 | while True: 19 | remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line. 20 | 21 | # Write an action using print 22 | # To debug: print("Debug messages...", file=sys.stderr) 23 | if light_y == ty: 24 | if light_x > tx: 25 | print("E") 26 | tx = tx + 1 27 | else: 28 | print("W") 29 | tx = tx - 1 30 | 31 | if light_x == tx: 32 | if light_y > ty: 33 | print("S") 34 | ty = ty + 1 35 | else: 36 | print("N") 37 | ty = ty - 1 38 | 39 | if light_x < tx and light_y > ty: 40 | print("SW") 41 | tx = tx - 1 42 | ty = ty + 1 43 | 44 | if light_x < tx and light_y < ty: 45 | print("NW") 46 | tx = tx - 1 47 | ty = ty - 1 48 | 49 | if light_x > tx and light_y > ty: 50 | print("SE") 51 | tx = tx + 1 52 | ty = ty + 1 53 | 54 | if light_x > tx and light_y < ty: 55 | print("NE") 56 | tx = tx + 1 57 | ty = ty - 1 58 | 59 | 60 | print("Thor = (", tx, ",", ty, ")", file=sys.stderr) 61 | 62 | # A single line providing the move to be made: N NE E SE S SW W or NW 63 | #print("SE") 64 | 65 | -------------------------------------------------------------------------------- /easy/sum-of-spirals-diagonals.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/easy/sum-of-spirals-diagonals 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | /** 12 | * Auto-generated code below aims at helping you parse 13 | * the standard input according to the problem statement. 14 | **/ 15 | 16 | int main() 17 | { 18 | int n; 19 | cin >> n; cin.ignore(); 20 | 21 | long s = 0; 22 | int k = 1; 23 | s = s + k; 24 | int delta = n-1; 25 | 26 | while (delta > 0) { 27 | int m = 4; 28 | if (delta ==1) {m=3;} 29 | for (int j=0; j0 then 38 | mincifra=cifra 39 | end if 40 | end if 41 | 42 | next 43 | end if 44 | Console.WriteLine(mincifra) 45 | End Sub 46 | End Module 47 | -------------------------------------------------------------------------------- /easy/the-descent.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/easy/the-descent 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * The while loop represents the game. 12 | * Each iteration represents a turn of the game 13 | * where you are given inputs (the heights of the mountains) 14 | * and where you have to print an output (the index of the mountain to fire on) 15 | * The inputs you are given are automatically updated according to your last actions. 16 | **/ 17 | int main() 18 | { 19 | 20 | // game loop 21 | while (1) { 22 | 23 | int maxi=-1; 24 | int maxH=-1; 25 | 26 | for (int i = 0; i < 8; i++) { 27 | int mountainH; // represents the height of one mountain. 28 | cin >> mountainH; cin.ignore(); 29 | 30 | if (mountainH>maxH) { 31 | maxH=mountainH; 32 | maxi=i; 33 | } 34 | } 35 | 36 | 37 | 38 | // Write an action using cout. DON'T FORGET THE "<< endl" 39 | // To debug: cerr << "Debug messages..." << endl; 40 | 41 | cout << maxi << endl; // The index of the mountain to fire on. 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /easy/the-river-i.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/easy/the-river-i- 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | int main() 15 | { 16 | long long r1; 17 | cin >> r1; cin.ignore(); 18 | long long r2; 19 | cin >> r2; cin.ignore(); 20 | 21 | // Write an action using cout. DON'T FORGET THE "<< endl" 22 | // To debug: cerr << "Debug messages..." << endl; 23 | 24 | 25 | while (r1 != r2 ) { 26 | 27 | 28 | if (r1 4 | #include 5 | #include 6 | #include 7 | #include "math.h" 8 | 9 | using namespace std; 10 | 11 | /** 12 | * Auto-generated code below aims at helping you parse 13 | * the standard input according to the problem statement. 14 | **/ 15 | int main() 16 | { 17 | int N; 18 | cin >> N; cin.ignore(); 19 | 20 | // x^2+x-2*N = 0 21 | 22 | float x = 1.0/2.0 * (-1.0 + sqrt(1.0 + 8.0 * N)); 23 | 24 | cout << ceil(x) << endl; 25 | } 26 | -------------------------------------------------------------------------------- /hard/roller-coaster.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/hard/roller-coaster 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | 15 | // Global variables 16 | int *q; 17 | int *qd; 18 | int *qpv; 19 | int L; 20 | int C; 21 | int N; 22 | 23 | 24 | 25 | int main() 26 | { 27 | 28 | cin >> L >> C >> N; cin.ignore(); 29 | cerr << L << " " << C << " " << N << endl; 30 | 31 | q = new int[N]; 32 | qd = new int[N]; 33 | qpv = new int[N]; 34 | 35 | for (int i = 0; i < N; i++) { 36 | int Pi; 37 | cin >> Pi; cin.ignore(); 38 | 39 | q[i]=Pi; 40 | qd[i]=0; 41 | qpv[i]=0; 42 | 43 | 44 | } 45 | 46 | int pVv = 0; // prvi v vrsti 47 | long dirhams = 0; 48 | 49 | // for each ride 50 | for (int i = 0; i < C; i++) { 51 | 52 | 53 | int od = dirhams; 54 | int opvv = pVv; 55 | 56 | 57 | if (qd[pVv]>0) { 58 | dirhams = dirhams + qd[pVv]; 59 | pVv=pVv+qpv[pVv]; 60 | // cerr << "eee" << endl; 61 | } 62 | 63 | else { 64 | 65 | // first group surely fits 66 | int ProstaMesta = L-q[pVv]; 67 | dirhams = dirhams + q[pVv]; 68 | // remember the first person 69 | int spVv = pVv; 70 | 71 | // find next group 72 | pVv++; 73 | if (pVv==N) { pVv=0; } 74 | 75 | while (ProstaMesta>0 & pVv != spVv) { 76 | 77 | ProstaMesta = ProstaMesta-q[pVv]; 78 | if (ProstaMesta > -1) { 79 | dirhams = dirhams + q[pVv]; 80 | // find next group 81 | pVv++; 82 | if (pVv==N) { pVv=0; } 83 | } 84 | 85 | } 86 | 87 | qd[opvv] = dirhams - od; 88 | qpv[opvv] = pVv - opvv; 89 | 90 | } 91 | // cerr << i << " " << dirhams << " pvv " << pVv << endl; 92 | } 93 | 94 | 95 | 96 | 97 | 98 | 99 | // Write an action using cout. DON'T FORGET THE "<< endl" 100 | // To debug: cerr << "Debug messages..." << endl; 101 | 102 | cout << dirhams << endl; 103 | } 104 | -------------------------------------------------------------------------------- /hard/the-hungry-duck---part-1.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/hard/the-hungry-duck---part-1 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | 15 | class nodeClass { 16 | 17 | public: 18 | int cost; 19 | int nsons; 20 | int sons[10]; 21 | 22 | }; 23 | 24 | int nodeID(int r, int c, int W) { 25 | 26 | return c+r*W; 27 | 28 | } 29 | 30 | int main() 31 | { 32 | int W; 33 | int H; 34 | cin >> W >> H; cin.ignore(); 35 | nodeClass food[W*H]; 36 | 37 | for (int r = 0; r < H; r++) { 38 | for (int c = 0; c < W; c++) { 39 | int node = nodeID(r,c,W); 40 | cin >> food[node].cost; cin.ignore(); 41 | 42 | food[node].nsons=0; 43 | if (r0) { 69 | 70 | // add sons 71 | for (int i = 0; i < food[list[0]].nsons; i++) { 72 | 73 | int son = food[list[0]].sons[i]; 74 | 75 | // add son only, if he gets more food than previous way till here 76 | if ( score[list[0]] + food[son].cost > score[son] ) { 77 | list[nlist]= son; 78 | score[son] = score[list[0]] + food[son].cost; 79 | nlist++; 80 | } 81 | } 82 | 83 | 84 | // remove first entry from list 85 | for (int i = 1; i < nlist; i++) { 86 | list[i-1]=list[i]; 87 | } 88 | nlist--; 89 | 90 | 91 | } 92 | 93 | 94 | // Write an action using cout. DON'T FORGET THE "<< endl" 95 | // To debug: cerr << "Debug messages..." << endl; 96 | 97 | cout << score[W*H-1] << endl; 98 | } 99 | -------------------------------------------------------------------------------- /hard/the-hungry-duck---part-2.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/hard/the-hungry-duck---part-2 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | 15 | class nodeClass { 16 | 17 | public: 18 | int cost; 19 | int nsons; 20 | int sons[10]; 21 | 22 | }; 23 | 24 | int nodeID(int r, int c, int W) { 25 | 26 | return c+r*W; 27 | 28 | } 29 | 30 | int main() 31 | { 32 | int W; 33 | int H; 34 | cin >> W >> H; cin.ignore(); 35 | nodeClass food[W*H]; 36 | 37 | for (int r = 0; r < H; r++) { 38 | for (int c = 0; c < W; c++) { 39 | int node = nodeID(r,c,W); 40 | cin >> food[node].cost; cin.ignore(); 41 | 42 | food[node].nsons=0; 43 | if (r0) { 69 | 70 | // add sons 71 | for (int i = 0; i < food[list[0]].nsons; i++) { 72 | 73 | int son = food[list[0]].sons[i]; 74 | 75 | // add son only, if he gets more food than previous way till here 76 | if ( score[list[0]] + food[son].cost > score[son] ) { 77 | list[nlist]= son; 78 | score[son] = score[list[0]] + food[son].cost; 79 | nlist++; 80 | } 81 | } 82 | 83 | 84 | // remove first entry from list 85 | for (int i = 1; i < nlist; i++) { 86 | list[i-1]=list[i]; 87 | } 88 | nlist--; 89 | 90 | 91 | } 92 | 93 | 94 | // Write an action using cout. DON'T FORGET THE "<< endl" 95 | // To debug: cerr << "Debug messages..." << endl; 96 | 97 | cout << score[W*H-1] << endl; 98 | } 99 | -------------------------------------------------------------------------------- /medium/aneo.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/medium/aneo 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include /* floor */ 8 | 9 | using namespace std; 10 | 11 | /** 12 | * Auto-generated code below aims at helping you parse 13 | * the standard input according to the problem statement. 14 | **/ 15 | 16 | 17 | class TrafficLight { 18 | 19 | public: 20 | int distance; 21 | int duration; 22 | 23 | bool isRed(float time) { 24 | 25 | if ( int( floor (time/duration+0.001)) % 2 == 0) { 26 | return false; 27 | } else { 28 | return true; 29 | } 30 | 31 | } 32 | }; 33 | 34 | int main() 35 | { 36 | vector TrafficLights; 37 | 38 | int speed; 39 | cin >> speed; cin.ignore(); 40 | int lightCount; 41 | cin >> lightCount; cin.ignore(); 42 | for (int i = 0; i < lightCount; i++) { 43 | TrafficLight tl; 44 | cin >> tl.distance >> tl.duration; cin.ignore(); 45 | TrafficLights.push_back(tl); 46 | } 47 | 48 | 49 | for (int mySpeed = speed; mySpeed > 0; mySpeed-- ) { 50 | int red=0; 51 | for (TrafficLight tl : TrafficLights) { 52 | float time = tl.distance / (float)mySpeed * 3.6; 53 | if (tl.isRed(time)) { red=1; } 54 | } 55 | if (red==0) { cout << mySpeed << endl; break;} 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /medium/bulls-and-cows.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/medium/bulls-and-cows 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | class Move { 15 | public: 16 | int bulls; 17 | int cows; 18 | int g[4]; 19 | }; 20 | 21 | 22 | 23 | int Verify(Move answer, Move guess) { 24 | 25 | int bulls = 0; 26 | int cows = 0; 27 | 28 | 29 | // check for bulls 30 | for (int i = 0; i<4; i++) { 31 | if (answer.g[i]==guess.g[i]) { 32 | bulls++; 33 | guess.g[i]=-i-5; 34 | answer.g[i]=-i-10; 35 | } 36 | } 37 | 38 | 39 | // check for cows 40 | for (int j = 0; j<4; j++) { // po guess 41 | for (int i = 0; i<4; i++) { 42 | if (guess.g[i]>=0 & answer.g[i]==guess.g[j]) { 43 | cows++; 44 | answer.g[i]=-100-j; 45 | } 46 | } 47 | } 48 | 49 | 50 | if (bulls==guess.bulls & cows == guess.cows) { 51 | return 1; 52 | } else { 53 | return 0; 54 | } 55 | 56 | } 57 | 58 | int main() 59 | { 60 | vector moves; 61 | 62 | int N; 63 | cin >> N; cin.ignore(); 64 | for (int i = 0; i < N; i++) { 65 | string guess; 66 | Move m; 67 | cin >> guess >> m.bulls >> m.cows; cin.ignore(); 68 | for (int j = 0; j<4; j++) { 69 | m.g[j]=stoi(guess.substr(j,1)); 70 | } 71 | moves.push_back(m); 72 | } 73 | 74 | 75 | Move m; 76 | for (int i = 0; i<10; i++) { 77 | m.g[0]=i; 78 | for (int j = 0; j<10; j++) { 79 | m.g[1]=j; 80 | for (int k = 0; k<10; k++) { 81 | m.g[2]=k; 82 | for (int l = 0; l<10; l++) { 83 | m.g[3]=l; 84 | int f = 1; 85 | for (Move x : moves) { 86 | int v = Verify(m,x); 87 | if (v == 0) { f = 0; } 88 | } 89 | if (f==1) { cout << m.g[0]<< m.g[1] << m.g[2] << m.g[3] << endl; } 90 | } 91 | } 92 | } 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /medium/conway-sequence.vb: -------------------------------------------------------------------------------- 1 | ' https://www.codingame.com/training/medium/conway-sequence 2 | 3 | Module Solution 4 | ' Auto-generated code below aims at helping you parse 5 | ' the standard input according to the problem statement. 6 | 7 | Sub Main () 8 | 9 | Dim R as Integer 10 | R = Console.ReadLine() 11 | 12 | Dim L as Integer 13 | L = Console.ReadLine() 14 | 15 | ' Write an action using Console.WriteLine() 16 | ' To debug: Console.Error.WriteLine("Debug messages...") 17 | 18 | Dim o(200*L) As Integer 19 | Dim n(200*L) As integer 20 | 21 | Dim no As Integer 22 | Dim nn As Integer 23 | Dim vold As Integer 24 | Dim c As Integer = 0 25 | 26 | no=1 27 | o(0)=R 28 | nn=1 29 | n(0)=R 30 | 31 | 32 | for k as integer = 0 to L-2 33 | c=0 34 | ' make new list 35 | nn=0 36 | vold=o(0) 37 | For i as Integer = 0 to no-1 38 | ' count same values 39 | if o(i)=vold then 40 | c=c+1 41 | else 42 | n(nn)=c 43 | nn=nn+1 44 | n(nn)=o(i-1) 45 | nn=nn+1 46 | 47 | c=1 48 | vold=o(i) 49 | end if 50 | next 51 | ' last one 52 | n(nn)=c 53 | nn=nn+1 54 | n(nn)=o(no-1) 55 | nn=nn+1 56 | ' make new line old 57 | no=nn 58 | for i as integer = 0 to nn-1 59 | o(i)=n(i) 60 | next 61 | 62 | ' Dim s As String = n(0).ToString 63 | ' for i as integer = 1 to nn-1 64 | ' s=s+" "+n(i).ToString 65 | ' next 66 | ' Console.Error.WriteLine(s) 67 | next 68 | 69 | 70 | 71 | Dim s As String = n(0).ToString 72 | for i as integer = 1 to nn-1 73 | s=s+" "+n(i).ToString 74 | next 75 | 76 | 77 | Console.WriteLine(s) 78 | End Sub 79 | End Module 80 | -------------------------------------------------------------------------------- /medium/dont-panic-episode-1.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/medium/don't-panic-episode-1 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int R,P,L[100],K,J; 6 | cin >>R>>R>>R>>R>>L[R]>>R>>R>>R; 7 | for(int i=0;i>P>>L[P];} 8 | while (1) { 9 | string H; 10 | cin>>K>>J>>H; 11 | if((H=="LEFT"&&J-L[K]<0)||(H=="RIGHT"&&J-L[K]>0)){cout<<"BLOCK"< 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | 11 | std::string toBinary(int n) 12 | { 13 | std::string r; 14 | while(n!=0) {r=(n%2==0 ?"0":"1")+r; n/=2;} 15 | return r; 16 | } 17 | /** 18 | * Auto-generated code below aims at helping you parse 19 | * the standard input according to the problem statement. 20 | **/ 21 | int main() 22 | { 23 | 24 | string rules[8]; 25 | 26 | rules[0]="@@@"; 27 | rules[1]="@@."; 28 | rules[2]="@.@"; 29 | rules[3]="@.."; 30 | rules[4]=".@@"; 31 | rules[5]=".@."; 32 | rules[6]="..@"; 33 | rules[7]="..."; 34 | 35 | 36 | int R; 37 | cin >> R; cin.ignore(); 38 | int N; 39 | cin >> N; cin.ignore(); 40 | string startPattern; 41 | cin >> startPattern; cin.ignore(); 42 | 43 | 44 | // Convert to binary, pad zeros, 1=@, 0=. 45 | string binR = toBinary(R); 46 | while (binR.length()<8) { 47 | binR = "0"+binR; 48 | } 49 | string binRR = ""; 50 | for (int j=0; j<8; j++) { 51 | if ( binR.substr(j,1)=="0") { binRR = binRR + "."; } else { binRR = binRR + "@"; } 52 | } 53 | 54 | // Loop number if ierations 55 | for (int n=0; n 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | int main() 15 | { 16 | int width; 17 | int height; 18 | int h[100]; 19 | cin >> width >> height; cin.ignore(); 20 | for (int i = 0; i < width; i++) {h[i]=height;} 21 | for (int i = 0; i < height; i++) { 22 | string line; 23 | cin >> line; cin.ignore(); 24 | for (int j = 0; j < width; j++) { 25 | if (line.substr(j,1)==".") {h[j]--;} 26 | } 27 | } 28 | 29 | for (int i = height-1; i > -1; i--) { 30 | for (int j = 0; j < width; j++) { 31 | if (h[j]<=i) { cout << "."; } 32 | else {cout << "#";} 33 | } 34 | cout << endl; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /medium/langtons-ant.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/medium/langtons-ant 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | 15 | string rotCW(string d) { 16 | 17 | if (d=="N") { return "E"; } 18 | if (d=="E") { return "S"; } 19 | if (d=="S") { return "W"; } 20 | if (d=="W") { return "N"; } 21 | 22 | } 23 | 24 | string rotCCW(string d) { 25 | 26 | if (d=="N") { return "W"; } 27 | if (d=="W") { return "S"; } 28 | if (d=="S") { return "E"; } 29 | if (d=="E") { return "N"; } 30 | 31 | } 32 | 33 | void advance(int &r, int &c, string d) { 34 | 35 | if (d=="N") { r=r-1; } 36 | if (d=="W") { c=c-1; } 37 | if (d=="S") { r=r+1; } 38 | if (d=="E") { c=c+1; } 39 | 40 | } 41 | 42 | int main() 43 | { 44 | string map[30][30]; 45 | int W; 46 | int H; 47 | cin >> W >> H; cin.ignore(); 48 | int c; 49 | int r; 50 | cin >> c >> r; cin.ignore(); 51 | string direction; 52 | cin >> direction; cin.ignore(); 53 | int T; 54 | cin >> T; cin.ignore(); 55 | for (int i = 0; i < H; i++) { 56 | string C; 57 | getline(cin, C); 58 | 59 | for (int j = 0; j < W; j++) { 60 | map[i][j]=C.substr(j,1); 61 | } 62 | } 63 | 64 | for (int i = 0; i < T; i++) { 65 | 66 | if (map[r][c]==".") { 67 | direction = rotCCW(direction); 68 | map[r][c]="#"; 69 | } else { 70 | direction = rotCW(direction); 71 | map[r][c]="."; 72 | } 73 | advance(r,c,direction); 74 | } 75 | 76 | for (int i = 0; i < H; i++) { 77 | for (int j = 0; j < W; j++) { 78 | cout << map[i][j]; 79 | } 80 | cout << endl; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /medium/network-cabling.vb: -------------------------------------------------------------------------------- 1 | ' https://www.codingame.com/training/medium/network-cabling 2 | 3 | 4 | Module Solution 5 | ' Auto-generated code below aims at helping you parse 6 | ' the standard input according to the problem statement. 7 | 8 | Sub Main () 9 | 10 | Dim N as Integer 11 | N = Console.ReadLine() 12 | 13 | Dim X(N-1) as Integer 14 | Dim Y(N-1) as Integer 15 | 16 | For i as Integer = 0 To N-1 17 | Dim inputs as String() 18 | inputs = Console.ReadLine().Split(" ") 19 | X(i) = inputs(0) 20 | Y(i) = inputs(1) 21 | Next 22 | 23 | Dim minX as Integer = 100000 24 | Dim maxX as Integer =-100000 25 | DIm sumY as Integer = 0 26 | 27 | For i as Integer = 0 To N-1 28 | if x(i)>maxX then 29 | maxX=x(i) 30 | end if 31 | if x(i) 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | long long maxTotSum = 0; 11 | long long iSum[100]; 12 | 13 | void getTotSum(long long totSum, int i, int n, vector values){ 14 | 15 | if (totSum > maxTotSum) { maxTotSum = totSum; } 16 | if (i>=0) { if (totSum > iSum[i] ) { iSum[i] = totSum; } } 17 | if ( i+2<=n & totSum + values[i+1] >= iSum[i+1] ) { getTotSum( totSum + values[i+1], i+2, n, values); } 18 | if ( i+3<=n & totSum + values[i+2] >= iSum[i+2] ) { getTotSum( totSum + values[i+2], i+3, n, values); } 19 | 20 | } 21 | 22 | int main() 23 | { 24 | 25 | vector values; 26 | int n; 27 | cin >> n; cin.ignore(); 28 | for (int i = 0; i < n; i++) { 29 | iSum[i] = 0; 30 | long long housevalue; 31 | cin >> housevalue; cin.ignore(); 32 | if (housevalue<0) {housevalue=0;} 33 | values.push_back(housevalue); 34 | } 35 | 36 | getTotSum(0,-1,n,values); 37 | cout << maxTotSum << endl; 38 | 39 | } -------------------------------------------------------------------------------- /medium/rubik.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/medium/rubik%C2%AE 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | int main() 15 | { 16 | int N; 17 | cin >> N; cin.ignore(); 18 | 19 | // Write an action using cout. DON'T FORGET THE "<< endl" 20 | // To debug: cerr << "Debug messages..." << endl; 21 | 22 | 23 | // ce je dovolj kock 24 | // spodaj + zgoraj 25 | int a; 26 | 27 | if (N==1) { 28 | a=1; 29 | } else { 30 | int s = 2*N*N; 31 | int l = 2*(N-2)*N; 32 | int z = 2*(N-2)*(N-2); 33 | 34 | a = s+l+z; 35 | } 36 | cout << a << endl; 37 | } 38 | -------------------------------------------------------------------------------- /medium/stock-exchange-losses.vb: -------------------------------------------------------------------------------- 1 | ' https://www.codingame.com/training/medium/stock-exchange-losses 2 | 3 | Module Solution 4 | ' Auto-generated code below aims at helping you parse 5 | ' the standard input according to the problem statement. 6 | 7 | Sub Main () 8 | 9 | Dim n as Integer 10 | n = Console.ReadLine() 11 | 12 | Dim inputs as String() 13 | Dim v(n) as Integer 14 | inputs = Console.ReadLine().Split(" ") 15 | For i as Integer = 0 To n-1 16 | v(i) = inputs(i) 17 | Next 18 | 19 | Console.Error.WriteLine("n=" & n) 20 | 21 | Dim mloss as integer = 0 22 | Dim mj as integer = 0 23 | Dim mi as integer = 0 24 | 25 | For i as Integer = 0 To n-1 26 | If v(i)>=v(mi) or i>mj Then 27 | For j as integer =i+1 To n-1 28 | if v(j)-v(i) < mloss then 29 | mloss = v(j)-v(i) 30 | mj=j 31 | mi=i 32 | end if 33 | next 34 | end if 35 | ' Console.Error.WriteLine(v(i) & " " & mloss) 36 | next 37 | 38 | ' Write an action using Console.WriteLine() 39 | ' To debug: Console.Error.WriteLine("Debug messages...") 40 | 41 | Console.WriteLine(mloss) 42 | End Sub 43 | End Module 44 | -------------------------------------------------------------------------------- /medium/the-experience-for-creating-puzzles.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/medium/the-experience-for-creating-puzzles 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | int main() 15 | { 16 | int Level; 17 | cin >> Level; cin.ignore(); 18 | int Xp; 19 | cin >> Xp; cin.ignore(); 20 | int N; 21 | cin >> N; cin.ignore(); 22 | 23 | // Write an action using cout. DON'T FORGET THE "<< endl" 24 | // To debug: cerr << "Debug messages..." << endl; 25 | 26 | cerr << Level << " " << Xp << " " << N << endl; 27 | 28 | for( int i = 0; i < N; i++ ) { 29 | Xp = Xp - 300; 30 | while (Xp<1) { 31 | Level++; 32 | Xp=Xp+floor(Level*10*sqrt(Level)); 33 | } 34 | } 35 | 36 | cout << Level << endl; 37 | cout << Xp << endl; 38 | } 39 | -------------------------------------------------------------------------------- /medium/the-fastest.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codingame.com/training/medium/the-fastest 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | /** 11 | * Auto-generated code below aims at helping you parse 12 | * the standard input according to the problem statement. 13 | **/ 14 | int main() 15 | { 16 | int N; 17 | int minss=1000000; 18 | string mint; 19 | cin >> N; cin.ignore(); 20 | for (int i = 0; i < N; i++) { 21 | string t; 22 | cin >> t; cin.ignore(); 23 | cerr << t << endl; 24 | 25 | int h = atoi(t.substr(0,2).c_str()); 26 | int m = atoi(t.substr(3,2).c_str()); 27 | int s = atoi(t.substr(6,2).c_str()); 28 | 29 | int ss = h*3600+m*60+s; 30 | 31 | if (ssangle = 6 * RandomInteger(-CAR_MAX_ANGLE/6,CAR_MAX_ANGLE/6); 15 | this->thrust = 50 * RandomInteger(0,CAR_MAX_THRUST/50); 16 | this->message = "rnd"; 17 | 18 | } 19 | 20 | int Action::RandomInteger(int nMin, int nMax) { 21 | return rand() % (nMax - nMin + 1) + nMin; 22 | } -------------------------------------------------------------------------------- /optimization/search-race/src/Action.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | 5 | class Action { 6 | public: 7 | Position goToTarget; 8 | int angle; // -18 .. 18 9 | int thrust; // 0 .. 200 10 | std::string message; 11 | 12 | Action(); 13 | void randomize(); 14 | 15 | friend std::ostream& operator<<(std::ostream& ioOut, const Action& obj); 16 | int RandomInteger(int nMin, int nMax); 17 | 18 | }; -------------------------------------------------------------------------------- /optimization/search-race/src/ActionList.cpp: -------------------------------------------------------------------------------- 1 | #include "ActionList.h" 2 | 3 | void ActionList::setRandom() { 4 | for (int i=0; i CPs) { 17 | 18 | int currentCPI = car.checkpointIndex; 19 | int currentITE = car.iteration; 20 | for (int i=0; i CPs); 19 | void overwrite(ActionList al); 20 | 21 | }; -------------------------------------------------------------------------------- /optimization/search-race/src/Car.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | #include "Action.h" 5 | #include "Checkpoint.h" 6 | 7 | class Car { 8 | public: 9 | Position pos; 10 | Position velocity; 11 | double speedR,speedC; 12 | int angle; 13 | int checkpointIndex; // Index of the checkpoint to lookup in the checkpoints input, initially 0 14 | int nCheckpoints; 15 | int iteration; 16 | int cpTime[30]; // time when car reched checkpoint 17 | 18 | Car(); 19 | friend std::ostream& operator<<(std::ostream& ioOut, const Car& obj); 20 | void read(); 21 | Position getGoToPos(Action a); 22 | Position moveOld(Action a); 23 | void turn(Action a); 24 | void move(Action a); 25 | void friction(Action a); 26 | void accelerate(Action a); 27 | void collision(Checkpoint cp); 28 | void go(Action a, Checkpoint target); 29 | Position gogo(Action a, Checkpoint target); 30 | int score(Checkpoint target, int startCPI, int startITE); 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /optimization/search-race/src/Checkpoint.cpp: -------------------------------------------------------------------------------- 1 | #include "Checkpoint.h" 2 | 3 | Checkpoint::Checkpoint() {}; 4 | Checkpoint::Checkpoint(int c, int r, int _id, double _radius) { // constructor 5 | 6 | pos = Position(r,c); 7 | id = _id; 8 | radius = _radius; 9 | } 10 | 11 | std::ostream& operator<<(std::ostream& ioOut, const Checkpoint& obj) { 12 | ioOut << obj.pos.col << " " << obj.pos.row << " id: " << obj.id; 13 | return ioOut; 14 | } 15 | -------------------------------------------------------------------------------- /optimization/search-race/src/Checkpoint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "Position.h" 4 | 5 | class Checkpoint { 6 | public: 7 | Position pos; 8 | double radius; 9 | int id; 10 | 11 | Checkpoint(int c, int r, int _id, double _radius); 12 | Checkpoint(); 13 | friend std::ostream& operator<<(std::ostream& ioOut, const Checkpoint& obj); 14 | }; -------------------------------------------------------------------------------- /optimization/search-race/src/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include /* srand, rand */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | static constexpr int CAR_MAX_THRUST = 200; 14 | static constexpr int CAR_MAX_ANGLE = 18; 15 | static constexpr double CheckpointRadius = 600.0; 16 | static constexpr double PI = 3.141592653589793238463; //value of pi 17 | 18 | static constexpr int POP_SIZE = 50; //100 19 | static constexpr int CHROM_LENGTH = 50; // 25 20 | static constexpr double TIME_LIMIT = 150.0; 21 | static constexpr float CORSS_OVER_RATE = 0.7; 22 | static constexpr float MUTATION_RATE = 0.05; 23 | 24 | -------------------------------------------------------------------------------- /optimization/search-race/src/Goal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | #include "ActionList.h" 4 | #include "Car.h" 5 | #include "Checkpoint.h" 6 | 7 | // Genetic optimization algorithm 8 | class Goal { 9 | public: 10 | ActionList pop[POP_SIZE]; 11 | ActionList newPop[POP_SIZE]; 12 | ActionList best; 13 | float totalFitness; 14 | 15 | Goal(); 16 | void init(); 17 | void findBest(); 18 | Action monteCarlo(Car car, std::vector CPs); 19 | Action ga(Car car, std::vector CPs); 20 | void EvaluteTotalFintess(); 21 | void EvaluteCumProb(); 22 | 23 | float RandomFloat01(); 24 | int RandomInteger(int nMin, int nMax); 25 | 26 | }; -------------------------------------------------------------------------------- /optimization/search-race/src/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = race 2 | VERSION = 1.0 3 | SOURCES = main.o ActionList.o Car.o Action.o Checkpoint.o Position.o Goal.o 4 | 5 | ARCH = `uname` 6 | INST = $(HOME)/bin 7 | 8 | HOST = $(shell hostname) 9 | 10 | # 11 | # *************** HOBBIT **************** 12 | # 13 | 14 | 15 | FC = g++ 16 | OBJECTS = $(SOURCES) 17 | KON = 18 | 19 | # Debug version 20 | # OPT = -Wall 21 | # OPDE= d 22 | # Optimized version 23 | OPT = -O3 24 | OPDE= o 25 | 26 | FCOPTS = -std=gnu++11 27 | LDOPTO = 28 | 29 | 30 | 31 | 32 | all: $(OBJECTS) 33 | $(FC) -o $(PROGRAM)-$(VERSION)$(KON) $(FCOPTS) $(OPT) $(OBJECTS) $(LDOPTO) 34 | 35 | clean: 36 | rm -f *.o *.mod .#* 37 | 38 | $(OBJECTS): %.o: %.cpp 39 | $(FC) $(FCOPTS) $(OPT) -c $< 40 | 41 | install: 42 | cp $(PROGRAM)-$(VERSION)$(KON) $(INST)/$(PROGRAM)-$(VERSION)-$(OPDE)$(KON) 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /optimization/search-race/src/Position.cpp: -------------------------------------------------------------------------------- 1 | #include "Position.h" 2 | 3 | Position::Position(int r, int c) { row = r; col = c; } // constructor 4 | Position::Position(int r, int c, int p) { row = r; col = c; } // constructor 5 | Position::Position() { row = -1; col = -1; } // default constructor 6 | 7 | 8 | std::ostream& operator<<(std::ostream& ioOut, const Position& obj) { 9 | ioOut << obj.col << " " << obj.row; 10 | return ioOut; 11 | } 12 | 13 | int Position::manhattan(Position p) { 14 | return abs( p.row - row)+abs( p.col - col); 15 | } 16 | 17 | float Position::dist(Position p) { 18 | float dr = (float)( p.row - row); 19 | float dc = (float)( p.col - col); 20 | return sqrt(dr*dr+dc*dc); 21 | } 22 | 23 | 24 | // Overload + operator to add two Box objects. 25 | Position Position::operator+(const Position& p) { 26 | Position pos; 27 | pos.row = this->row + p.row; 28 | pos.row = this->col + p.col; 29 | return pos; 30 | } 31 | 32 | 33 | // Overload == operator 34 | bool Position::operator==(const Position p) { 35 | return this->row == p.row && this->col == p.col; 36 | } 37 | 38 | bool Position::operator!=(const Position p) { 39 | return !(this->row == p.row && this->col == p.col); 40 | } 41 | 42 | double Position::getAngle(Position p){ 43 | double dx = p.col - this->col; 44 | double dy = p.row - this->row; 45 | return atan2(dy, dx); 46 | } -------------------------------------------------------------------------------- /optimization/search-race/src/Position.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.h" 3 | 4 | class Position { 5 | public: 6 | int row; 7 | int col; 8 | 9 | Position(int r, int c); 10 | Position(int r, int c, int p); 11 | Position(); 12 | 13 | friend std::ostream& operator<<(std::ostream& ioOut, const Position& obj); 14 | bool operator==(const Position p); 15 | bool operator!=(const Position p); 16 | Position operator+(const Position& p); 17 | int manhattan(Position p); 18 | float dist(Position p); 19 | double getAngle(Position p); 20 | }; -------------------------------------------------------------------------------- /optimization/search-race/src/circles.dat: -------------------------------------------------------------------------------- 1 | # x y R id 2 | 2757 4341 600 0 3 | 3358 6162 600 1 4 | 10353 7014 600 2 5 | 2757 4341 600 3 6 | 3358 6162 600 4 7 | 10353 7014 600 5 8 | 2757 4341 600 6 9 | 3358 6162 600 7 10 | 10353 7014 600 8 11 | -------------------------------------------------------------------------------- /optimization/search-race/src/doTests: -------------------------------------------------------------------------------- 1 | ./race-1.0 < test1 > results 2 | ./race-1.0 < test2 >> results 3 | ./race-1.0 < test3 >> results 4 | ./race-1.0 < test4 >> results 5 | ./race-1.0 < test5 >> results 6 | ./race-1.0 < test6 >> results 7 | ./race-1.0 < test7 >> results 8 | ./race-1.0 < test16 >> results 9 | ./race-1.0 < test19 >> results 10 | awk '{x+=$0}END{print x}' results >> results 11 | cat results 12 | -------------------------------------------------------------------------------- /optimization/search-race/src/results: -------------------------------------------------------------------------------- 1 | 109 2 | 114 3 | 328 4 | 436 5 | 404 6 | 269 7 | 453 8 | 160 9 | 504 10 | 2777 11 | -------------------------------------------------------------------------------- /optimization/search-race/src/test1: -------------------------------------------------------------------------------- 1 | 9 2 | 2757 4659 3 | 3358 2838 4 | 10353 1986 5 | 2757 4659 6 | 3358 2838 7 | 10353 1986 8 | 2757 4659 9 | 3358 2838 10 | 10353 1986 -------------------------------------------------------------------------------- /optimization/search-race/src/test16: -------------------------------------------------------------------------------- 1 | 18 2 | 12000 1000 3 | 12500 2500 4 | 13000 4000 5 | 12500 5500 6 | 12000 7000 7 | 1000 1000 8 | 12000 1000 9 | 12500 2500 10 | 13000 4000 11 | 12500 5500 12 | 12000 7000 13 | 1000 1000 14 | 12000 1000 15 | 12500 2500 16 | 13000 4000 17 | 12500 5500 18 | 12000 7000 19 | 1000 1000 -------------------------------------------------------------------------------- /optimization/search-race/src/test19: -------------------------------------------------------------------------------- 1 | 18 2 | 15000 8000 3 | 1000 8000 4 | 15000 1000 5 | 1000 4500 6 | 15000 4500 7 | 1000 1000 8 | 15000 8000 9 | 1000 8000 10 | 15000 1000 11 | 1000 4500 12 | 15000 4500 13 | 1000 1000 14 | 15000 8000 15 | 1000 8000 16 | 15000 1000 17 | 1000 4500 18 | 15000 4500 19 | 1000 1000 -------------------------------------------------------------------------------- /optimization/search-race/src/test2: -------------------------------------------------------------------------------- 1 | 9 2 | 3431 6328 3 | 4284 2801 4 | 11141 4590 5 | 3431 6328 6 | 4284 2801 7 | 11141 4590 8 | 3431 6328 9 | 4284 2801 10 | 11141 4590 -------------------------------------------------------------------------------- /optimization/search-race/src/test3: -------------------------------------------------------------------------------- 1 | 21 2 | 10892 5399 3 | 4058 1092 4 | 6112 2872 5 | 1961 6027 6 | 7148 4594 7 | 7994 1062 8 | 1711 3942 9 | 10892 5399 10 | 4058 1092 11 | 6112 2872 12 | 1961 6027 13 | 7148 4594 14 | 7994 1062 15 | 1711 3942 16 | 10892 5399 17 | 4058 1092 18 | 6112 2872 19 | 1961 6027 20 | 7148 4594 21 | 7994 1062 22 | 1711 3942 -------------------------------------------------------------------------------- /optimization/search-race/src/test4: -------------------------------------------------------------------------------- 1 | 24 2 | 1043 1446 3 | 10158 1241 4 | 13789 7502 5 | 7456 3627 6 | 6218 1993 7 | 7117 6546 8 | 5163 7350 9 | 12603 1090 10 | 1043 1446 11 | 10158 1241 12 | 13789 7502 13 | 7456 3627 14 | 6218 1993 15 | 7117 6546 16 | 5163 7350 17 | 12603 1090 18 | 1043 1446 19 | 10158 1241 20 | 13789 7502 21 | 7456 3627 22 | 6218 1993 23 | 7117 6546 24 | 5163 7350 25 | 12603 1090 -------------------------------------------------------------------------------- /optimization/search-race/src/test5: -------------------------------------------------------------------------------- 1 | 24 2 | 1271 7171 3 | 14407 3329 4 | 10949 2136 5 | 2443 4165 6 | 5665 6432 7 | 3079 1942 8 | 4019 5141 9 | 9214 6145 10 | 1271 7171 11 | 14407 3329 12 | 10949 2136 13 | 2443 4165 14 | 5665 6432 15 | 3079 1942 16 | 4019 5141 17 | 9214 6145 18 | 1271 7171 19 | 14407 3329 20 | 10949 2136 21 | 2443 4165 22 | 5665 6432 23 | 3079 1942 24 | 4019 5141 25 | 9214 6145 -------------------------------------------------------------------------------- /optimization/search-race/src/test6: -------------------------------------------------------------------------------- 1 | 24 2 | 11727 5704 3 | 11009 3026 4 | 10111 1169 5 | 5835 7503 6 | 1380 2538 7 | 4716 1269 8 | 4025 5146 9 | 8179 7909 10 | 11727 5704 11 | 11009 3026 12 | 10111 1169 13 | 5835 7503 14 | 1380 2538 15 | 4716 1269 16 | 4025 5146 17 | 8179 7909 18 | 11727 5704 19 | 11009 3026 20 | 10111 1169 21 | 5835 7503 22 | 1380 2538 23 | 4716 1269 24 | 4025 5146 25 | 8179 7909 -------------------------------------------------------------------------------- /optimization/search-race/src/test7: -------------------------------------------------------------------------------- 1 | 24 2 | 14908 1849 3 | 2485 3249 4 | 5533 6258 5 | 12561 1063 6 | 1589 6883 7 | 13542 2666 8 | 13967 6917 9 | 6910 1656 10 | 14908 1849 11 | 2485 3249 12 | 5533 6258 13 | 12561 1063 14 | 1589 6883 15 | 13542 2666 16 | 13967 6917 17 | 6910 1656 18 | 14908 1849 19 | 2485 3249 20 | 5533 6258 21 | 12561 1063 22 | 1589 6883 23 | 13542 2666 24 | 13967 6917 25 | 6910 1656 --------------------------------------------------------------------------------