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

View File

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

View File

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

View File

@ -1,6 +1,12 @@
#include "dude.h" #include "dude.h"
#include "string.h"
Dude::Dude() 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 #ifndef DUDE_H
#define DUDE_H #define DUDE_H
#include "team.h" #include "behavior.h"
class Dude class Dude
{ {
private: private:
Coord pos; Coord m_pos;
Info info; Info m_info;
bool dead; bool m_dead;
char memory[DUDE_MEMORY_SIZE]; char m_memory[DUDE_MEMORY_SIZE];
BehaviorFunction behavior; BehaviorFunction m_behavior;
public: public:
Dude(); Dude();
Dude(Coord,Info,bool,BehaviorFunction);
}; };
#endif // DUDE_H #endif // DUDE_H

View File

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

View File

@ -1,6 +1,7 @@
#include "simulation.h" #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 #ifndef SIMULATION_H
#define SIMULATION_H #define SIMULATION_H
#include <vector>
#include "behavior.h"
class Map;
class Simulation class Simulation
{ {
private:
Map *p_map;
std::vector<BehaviorFunction> m_behaviors;
public: 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