Skip to content

Commit

Permalink
Merge pull request #163 from themmj/master
Browse files Browse the repository at this point in the history
Add missing const qualifiers, unify code style
  • Loading branch information
StoneT2000 authored Nov 9, 2021
2 parents ab35d64 + a6dc81f commit f7cff3c
Show file tree
Hide file tree
Showing 25 changed files with 419 additions and 279 deletions.
46 changes: 30 additions & 16 deletions kits/cpp/simple-transpiled/lux/annotate.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
#ifndef annotate_h
#define annotate_h
#include <string>
namespace lux {

namespace lux
{
using namespace std;
class Annotate {

class Annotate
{
public:
static string circle(int x, int y) {
static string circle(int x, int y)
{
return "dc " + to_string(x) + " " + to_string(y);
};
static string x(int x, int y) {
}

static string x(int x, int y)
{
return "dx " + to_string(x) + " " + to_string(y);
};
static string line(int x1, int y1, int x2, int y2) {
}

static string line(int x1, int y1, int x2, int y2)
{
return "dl " + to_string(x1) + " " + to_string(y1) + " " + to_string(x2) + " " + to_string(y2);
};
static string text(int x1, int y1, string message) {
}

static string text(int x1, int y1, string message)
{
return "dt " + to_string(x1) + " " + to_string(y1) + " '" + message + "' 16";
};
static string text(int x1, int y1, string message, int fontsize) {
}

static string text(int x1, int y1, string message, int fontsize)
{
return "dt " + to_string(x1) + " " + to_string(y1) + " '" + message + "' " + to_string(fontsize);
};
static string sidetext(string message) {
}

static string sidetext(string message)
{
return "dst '" + message + "'";
};
}
};
};
// string lux::Annotate::circle(int x, int y)
}


#endif
57 changes: 34 additions & 23 deletions kits/cpp/simple-transpiled/lux/city.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,53 @@
#define city_h
#include <vector>
#include <string>
// #include <format>
#include "position.hpp"

namespace lux
{
using namespace std;

class CityTile
{
public:
string cityid;
int team;
lux::Position pos;
Position pos;
int cooldown;

CityTile(){};
CityTile(int teamid, const string &cityid, int x, int y, int cooldown)
{
this->cityid = cityid;
this->team = teamid;

this->pos = lux::Position(x, y);
this->cooldown = cooldown;
}
: cityid(cityid)
, team(teamid)
, pos(x, y)
, cooldown(cooldown) {}

/** Whether or not this unit can research or build */
bool canAct()
bool canAct() const
{
return this->cooldown < 1;
};
return cooldown < 1;
}

/** returns command to ask this tile to research this turn */
string research()
string research() const
{
return "r " + to_string(this->pos.x) + " " + to_string(this->pos.y);
return "r " + to_string(pos.x) + " " + to_string(pos.y);

}

};
/** returns command to ask this tile to build a worker this turn */
string buildWorker()
string buildWorker() const
{
return "bw " + to_string(this->pos.x) + " " + to_string(this->pos.y);
return "bw " + to_string(pos.x) + " " + to_string(pos.y);
}

/** returns command to ask this tile to build a cart this turn */
string buildCart()
string buildCart() const
{
return "bc " + to_string(this->pos.x) + " " + to_string(this->pos.y);
return "bc " + to_string(pos.x) + " " + to_string(pos.y);
}
};

class City
{
public:
Expand All @@ -53,16 +57,23 @@ namespace lux
float fuel;
vector<CityTile> citytiles{};
float lightUpkeep;

City(){};
City(int teamid, const string &cityid, float fuel, float lightUpkeep) : cityid(cityid), team(teamid), fuel(fuel), lightUpkeep(lightUpkeep) {}
City(int teamid, const string &cityid, float fuel, float lightUpkeep)
: cityid(cityid)
, team(teamid)
, fuel(fuel)
, lightUpkeep(lightUpkeep) {}

void addCityTile(int x, int y, int cooldown)
{
citytiles.emplace_back(team, cityid, x, y, cooldown);
}
float getLightUpkeep()

float getLightUpkeep() const
{
return this->lightUpkeep;
return lightUpkeep;
}
};
}
#endif
#endif
1 change: 1 addition & 0 deletions kits/cpp/simple-transpiled/lux/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ namespace lux
};
static const DIRECTIONS ALL_DIRECTIONS[] = { NORTH, EAST, SOUTH, WEST };
};

#endif
24 changes: 13 additions & 11 deletions kits/cpp/simple-transpiled/lux/define.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#include "kit.hpp"
#include <map>
#include <ostream>
#include <string>

namespace kit
{
using namespace std;
string INPUT_CONSTANTS::DONE = "D_DONE";
string INPUT_CONSTANTS::RESOURCES = "r";
string INPUT_CONSTANTS::RESEARCH_POINTS = "rp";
string INPUT_CONSTANTS::UNITS = "u";
string INPUT_CONSTANTS::CITY = "c";
string INPUT_CONSTANTS::CITY_TILES = "ct";
string INPUT_CONSTANTS::ROADS = "ccd";
using namespace std;

string INPUT_CONSTANTS::DONE = "D_DONE";
string INPUT_CONSTANTS::RESOURCES = "r";
string INPUT_CONSTANTS::RESEARCH_POINTS = "rp";
string INPUT_CONSTANTS::UNITS = "u";
string INPUT_CONSTANTS::CITY = "c";
string INPUT_CONSTANTS::CITY_TILES = "ct";
string INPUT_CONSTANTS::ROADS = "ccd";
}

namespace lux
{
using namespace std;

ostream &operator<<(ostream &out, const Position &p)
ostream &operator<<(ostream &out, const Position &p)
{
out << "(" << p.x << "," << p.y << ")"; // access private data
out << "(" << p.x << "," << p.y << ")";
return out;
};
}
94 changes: 59 additions & 35 deletions kits/cpp/simple-transpiled/lux/game_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,55 @@
#include "map.hpp"
#include "position.hpp"
#include "constants.hpp"

namespace lux
{
using namespace std;

class Cargo
{
public:
int wood = 0;
int coal = 0;
int uranium = 0;
Cargo(){};

Cargo(){}
Cargo(int wood, int coal, int uranium) : wood(wood), coal(coal), uranium(uranium) {}
};

class Unit
{
public:
lux::Position pos;
Position pos;
int team;
string id;
int type;
int cooldown;
Cargo cargo;

Unit(){};
Unit(int teamid, int type, const string &unitid, int x, int y, int cooldown, int wood, int coal, int uranium)
: pos(x, y)
, team(teamid)
, id(unitid)
, type(type)
, cooldown(cooldown)
, cargo(wood, coal, uranium) {}

bool isWorker() const
{
this->pos = lux::Position(x, y);
this->team = teamid;
this->id = unitid;
this->type = type;
this->cooldown = cooldown;
this->cargo.wood = wood;
this->cargo.coal = coal;
this->cargo.uranium = uranium;
};
bool isWorker()
{
return this->type == 0;
return type == 0;
}
bool isCart()

bool isCart() const
{
return this->type == 1;
return type == 1;
}
int getCargoSpaceLeft()

int getCargoSpaceLeft() const
{
int spaceused = this->cargo.wood + this->cargo.coal + this->cargo.uranium;
if (this->type == 0)
int spaceused = cargo.wood + cargo.coal + cargo.uranium;
if (type == 0)
{
return (int)GAME_CONSTANTS["PARAMETERS"]["RESOURCE_CAPACITY"]["WORKER"] - spaceused;
}
Expand All @@ -58,44 +63,60 @@ namespace lux
}

/** whether or not the unit can act or not */
bool canAct()
bool canAct() const
{
return this->cooldown < 1;
return cooldown < 1;
}

/** whether or not the unit can build where it is right now */
bool canBuild(const GameMap &gameMap) {
auto cell = gameMap.getCellByPos(this->pos);
if (!cell->hasResource() && this->canAct() && (this->cargo.wood + this->cargo.coal + this->cargo.uranium) >= GAME_CONSTANTS["PARAMETERS"]["CITY_BUILD_COST"]) {
bool canBuild(const GameMap &gameMap) const
{
auto cell = gameMap.getCellByPos(pos);
if (!cell->hasResource() && canAct() && (cargo.wood + cargo.coal + cargo.uranium) >= GAME_CONSTANTS["PARAMETERS"]["CITY_BUILD_COST"])
{
return true;
}
return false;
}

/** return the command to move unit in the given direction */
string move(const DIRECTIONS &dir)
string move(const DIRECTIONS &dir) const
{
return "m " + this->id + " " + (char)dir;
return "m " + id + " " + (char)dir;
}

/** return the command to transfer a resource from a source unit to a destination unit as specified by their ids or the units themselves */
string transfer(const string &src_unit_id, const string &dest_unit_id, const ResourceType &resourceType, int amount)
string transfer(const string &src_unit_id, const string &dest_unit_id, const ResourceType &resourceType, int amount) const
{
return "t " + src_unit_id + " " + dest_unit_id + " " + to_string(resourceType) + " " + to_string(amount);
string resourceName;
switch (resourceType)
{
case ResourceType::wood:
resourceName = "wood";
break;
case ResourceType::coal:
resourceName = "coal";
break;
case ResourceType::uranium:
resourceName = "uranium";
break;
}
return "t " + src_unit_id + " " + dest_unit_id + " " + resourceName + " " + to_string(amount);
}

/** return the command to build a city right under the worker */
string buildCity()
string buildCity() const
{
return "bcity " + this->id;
return "bcity " + id;
}

/** return the command to pillage whatever is underneath the worker */
string pillage()
string pillage() const
{
return "p " + this->id;
return "p " + id;
}
};

class Player
{
public:
Expand All @@ -104,16 +125,19 @@ namespace lux
vector<Unit> units{};
map<string, City> cities{};
int cityTileCount = 0;

Player(){};
Player(int team_id) : team(team_id) {}

bool researchedCoal()
{
return this->researchPoints >= (int)GAME_CONSTANTS["PARAMETERS"]["RESEARCH_REQUIREMENTS"]["COAL"];
return researchPoints >= (int)GAME_CONSTANTS["PARAMETERS"]["RESEARCH_REQUIREMENTS"]["COAL"];
}

bool researchedUranium()
{
return this->researchPoints >= (int)GAME_CONSTANTS["PARAMETERS"]["RESEARCH_REQUIREMENTS"]["URANIUM"];
return researchPoints >= (int)GAME_CONSTANTS["PARAMETERS"]["RESEARCH_REQUIREMENTS"]["URANIUM"];
}
};
};
}
#endif
Loading

0 comments on commit f7cff3c

Please sign in to comment.