renamed team.h in behavior.h and added basic simulation class

This commit is contained in:
Lendemor 2016-05-17 20:39:40 +02:00
parent 5a7c32a26e
commit bd420fe97b
10 changed files with 61 additions and 20 deletions

21
src/behavior.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "behavior.h"
#include "map.h"
// TODO Info functions
Info::Info(){
}
Info::Info(Map *_map):p_map(_map){
}
int Info::getNear(Dir d)
{
return (*p_map)[Coord(d)].type;
}
int Info::getInfo(Dir d)
{
return (*p_map)[Coord(d)].data.nbRes;
}

View File

@ -7,6 +7,8 @@
#define LIBRARY_SIZE 128
#define COM_SIZE 32
class Map;
struct Com
{
enum Flags {
@ -43,10 +45,15 @@ struct Action
class Info
{
// TODO
private:
Map *p_map;
Coord m_pos;
// TODO
public:
bool success;
int inventory;
bool m_success;
int m_inventory;
Info();
Info(Map*);
const Com& getCom();
int getNear(Dir d);
int getInfo(Dir d);

View File

@ -54,10 +54,10 @@ struct Coord
Coord& operator/=(const Coord &c)
{ x/=c.x; y/=c.y; return *this; }
int dist() const // manhatthan distance
{ return abs(x) + abs(y); }
{ return std::abs(x) + std::abs(y); }
int operator~() const
{ return dist(); }
static dist(const Coord &c1, const Coord &c2)
static int dist(const Coord &c1, const Coord &c2)
{ return ~(c1-c2); }
int dist(const Coord &c) const
{ return dist(*this, c); }

View File

@ -5,7 +5,7 @@
#include <QOpenGLWidget>
#include "map.h"
#include "team.h"
#include "behavior.h"
class PixelPipeline;
class MapScene;

View File

@ -1,6 +1,12 @@
#include "dude.h"
#include "string.h"
Dude::Dude()
{
}
Dude::Dude(Coord _pos, Info _info, bool _dead, BehaviorFunction _behavior):m_pos(_pos),m_info(_info),m_dead(_dead),m_behavior(_behavior)
{
memset(&m_memory,0,DUDE_MEMORY_SIZE*sizeof(char));
}

View File

@ -1,20 +1,20 @@
#ifndef DUDE_H
#define DUDE_H
#include "team.h"
#include "behavior.h"
class Dude
{
private:
Coord pos;
Info info;
bool dead;
char memory[DUDE_MEMORY_SIZE];
BehaviorFunction behavior;
Coord m_pos;
Info m_info;
bool m_dead;
char m_memory[DUDE_MEMORY_SIZE];
BehaviorFunction m_behavior;
public:
Dude();
Dude(Coord,Info,bool,BehaviorFunction);
};
#endif // DUDE_H

View File

@ -7,7 +7,7 @@ namespace Ui {
class LibWidget;
}
#include "team.h"
#include "behavior.h"
#include "map.h"
class LibWidget : public QWidget

View File

@ -1,6 +1,7 @@
#include "simulation.h"
Simulation::Simulation()
Simulation::Simulation(Map *_map,std::vector<BehaviorFunction> _behaviors):
p_map(_map),m_behaviors(_behaviors)
{
}

View File

@ -1,11 +1,20 @@
#ifndef SIMULATION_H
#define SIMULATION_H
#include <vector>
#include "behavior.h"
class Map;
class Simulation
{
private:
Map *p_map;
std::vector<BehaviorFunction> m_behaviors;
public:
Simulation();
Simulation(Map *_map,std::vector<BehaviorFunction> _behaviors);
};
#endif // SIMULATION_H
#endif // SIMULATION_H

View File

@ -1,3 +0,0 @@
#include "team.h"
// TODO Info functions