Skip to content
Snippets Groups Projects
Commit 9e3f7e86 authored by Ori Almog's avatar Ori Almog
Browse files

No errors!

parent 7d7cc676
No related branches found
No related tags found
No related merge requests found
#include "include/terrain.h"
#include "include/tiles.h"
#include "include/level.h"
#include "include/coord.h"
#include <vector>
#include <queue>
#include <map>
#include <math.h>
Algs::Algs(){}
void Algs::addPerps(Coord current, &std::vector<Coord> deltas, Level& lvl, std::map<Coord, Coord>& parents){
Coord target;
target = current + Coord(1, 0);
tryAdd(current, delta, lvl, parents, target);
target = current + Coord(-1, 0);
tryAdd(current, delta, lvl, parents, target);
target = current + Coord(0, 1);
tryAdd(current, delta, lvl, parents, target);
target = current + Coord(0, -1);
tryAdd(current, delta, lvl, parents, target);
}
void Algs::addDiags(Coord current, std::vector<Coord>& deltas, Level& lvl, std::map<Coord, Coord>& parents){
Coord target;
target = current + Coord(1, 1);
tryAdd(current, delta, lvl, parents, target);
target = current + Coord(-1, 1);
tryAdd(current, delta, lvl, parents, target);
target = current + Coord(-1, -1);
tryAdd(current, delta, lvl, parents, target);
target = current + Coord(1, -1);
tryAdd(current, delta, lvl, parents, target);
}
void Algs::tryAdd(Coord current, std::vector<Coord>& deltas, Level& lvl, std::map<Coord, Coord>& parents, Coord target){
if(lvl[target].isPassable() == Terrain::Passable && !lvl[target].checked){
delta.push_back(target);
lvl[target].checked = true;
parents[target, current];
}
}
std::vector<Coord> Algs::bfsDiag(Coord start, Coord end, Level& lvl){
std::map<Coord, Coord> parents;
std::queue<Coord> delta;
delta.push(start.copy());
while(!delta.empty()){
Coord current = delta.front();
delta.pop();
if (current == end){
break;
}
addPerps(current, delta, lvl, parents);
addDiags(current, delta, lvl, parents);
}
}
std::vector<Coord> Algs::bfsPerp(Coord start, Coord end){
}
std::vector<Coord> Algs::getPath(std::vector<Coord> delta, Coord start){
}
\ No newline at end of file
#include "include/coord.h"
#include <string>
#include <cmath>
Coord::Coord(int x, int y)
: x(x)
......@@ -52,6 +53,10 @@ Coord& Coord::operator-=(const Coord& other) {
return *this;
}
bool Coord::operator<(const Coord& other) const {
return std::sqrt(x * x + y * y) < std::sqrt(other.x * other.x + other.y * other.y);
}
Coord& Coord::operator*=(const int& scalar) {
*this = *this * scalar;
return *this;
......
#pragma once
#include "include/terrain.h"
#include "include/tiles.h"
#include "include/level.h"
#include "include/coord.h"
#include <map>
#include <vector>
class Level;
class Algs {
public:
Algs();
//Performs BFS with diagonals
std::vector<Coord> bfsDiag(Coord, Coord);
//Performs BFS without diagonals
std::vector<Coord> bfsPerp(Coord, Coord);
//Gets a path given a delta vector and starting position
std::vector<Coord> getPath(Coord, std::vector<Coord>);
private:
//Add perpendicular coords
void addPerps(Coord, std::vector<Coord>, Level* , std::map<Coord, Coord>);
//Add diagonal coords
void addDiags(Coord, std::vector<Coord>, Level* , std::map<Coord, Coord>);
//Add diagonal coords
void tryAdd(Coord, std::vector<Coord>, Level* , std::map<Coord, Coord>, Coord);
};
\ No newline at end of file
......@@ -16,6 +16,9 @@ class Coord {
Coord operator*(const int&);
Coord& operator+=(const Coord&);
Coord& operator-=(const Coord&);
bool operator<(const Coord&) const;
Coord& operator*=(const int&);
bool operator==(const Coord&);
bool operator!=(const Coord&);
......
#pragma once
#include <vector>
#include <map>
#include <queue>
#include "coord.h"
#include "terrain.h"
#include "random.h"
......@@ -21,13 +23,32 @@ class Level {
void generate(PlayerChar);
bool contains(Coord);
static Coord getSize() { return Coord(X_SIZE, Y_SIZE); };
// Add a mob to the level's collection
void registerMob(Mob*);
std::vector<Mob*> getMobs();
Mob* popTurnClock();
// move a mob back in the turn clock equal to the amount specified
void pushMob(Mob*, int);
//Performs BFS with diagonals
std::vector<Coord> bfsDiag(Coord, Coord);
//Performs BFS without diagonals
std::vector<Coord> bfsPerp(Coord, Coord);
//Gets a path given a delta vector and starting position
std::vector<Coord> getPath(std::vector<Coord>, Coord);
std::vector<Coord> getAdjPassable(Coord);
Coord throwLocation(Coord, Coord);
private:
// Store mobs with a notation for how many
// 'ticks' they are from being the current actor
struct ClockItem {
......@@ -37,6 +58,7 @@ class Level {
Mob* mob;
int delay;
};
const int MAX_ROOMS = 9;
const double GOLD_CHANCE = .333;
const double ROOM_EXIST_CHANCE = 0.9;
......@@ -52,4 +74,13 @@ class Level {
void addTunnel(int, int, bool*, bool*, Generator);
Coord size;
int depth;
//Add perpendicular coords
void addPerps(Coord, std::queue<Coord>&, std::map<Coord, Coord>&);
//Add diagonal coords
void addDiags(Coord, std::queue<Coord>&, std::map<Coord, Coord>&);
//Add diagonal coords
void tryAdd(Coord, std::queue<Coord>&, std::map<Coord, Coord>&, Coord);
};
#include "include/terrain.h"
#include "include/mob.h"
#include <vector>
#include <queue>
#include <map>
#include <math.h>
#include <iostream>
#include "include/tiles.h"
#include "include/level.h"
......@@ -181,3 +186,75 @@ void Level::addTunnel(int i, int j, bool* a, bool* b, Generator gen){
tunnels.push_back(Tunnel(&rooms[i], &rooms[j], gen));
}
}
void Level::addPerps(Coord current, std::queue<Coord>& deltas, std::map<Coord, Coord>& parents){
Coord target;
target = current + Coord(1, 0);
tryAdd(current, deltas, parents, target);
target = current + Coord(-1, 0);
tryAdd(current, deltas, parents, target);
target = current + Coord(0, 1);
tryAdd(current, deltas, parents, target);
target = current + Coord(0, -1);
tryAdd(current, deltas, parents, target);
}
void Level::addDiags(Coord current, std::queue<Coord>& deltas, std::map<Coord, Coord>& parents){
Coord target;
target = current + Coord(1, 1);
tryAdd(current, deltas, parents, target);
target = current + Coord(-1, 1);
tryAdd(current, deltas, parents, target);
target = current + Coord(-1, -1);
tryAdd(current, deltas, parents, target);
target = current + Coord(1, -1);
tryAdd(current, deltas, parents, target);
}
void Level::tryAdd(Coord current, std::queue<Coord>& deltas, std::map<Coord, Coord>& parents, Coord target){
if(tiles[target[0]][target[1]].isPassable() == Terrain::Passable && !tiles[target[0]][target[1]].checked){
deltas.push(target.copy());
tiles[target[0]][target[1]].checked = true;
parents[target.copy()] = current.copy();
}
}
std::vector<Coord> Level::bfsDiag(Coord start, Coord end){
std::map<Coord, Coord> parents;
std::queue<Coord> delta;
delta.push(start.copy());
while(!delta.empty()){
Coord current = delta.front();
delta.pop();
if (current == end){
break;
}
addPerps(current, delta, parents);
addDiags(current, delta, parents);
}
}
std::vector<Coord> Level::bfsPerp(Coord start, Coord end){
}
std::vector<Coord> Level::getPath(std::vector<Coord> delta, Coord start){
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment