renamed team.h in behavior.h and added basic simulation class
This commit is contained in:
parent
5a7c32a26e
commit
bd420fe97b
21
src/behavior.cpp
Normal file
21
src/behavior.cpp
Normal 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;
|
||||
}
|
@ -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);
|
@ -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); }
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <QOpenGLWidget>
|
||||
|
||||
#include "map.h"
|
||||
#include "team.h"
|
||||
#include "behavior.h"
|
||||
|
||||
class PixelPipeline;
|
||||
class MapScene;
|
||||
|
@ -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));
|
||||
}
|
||||
|
14
src/dude.h
14
src/dude.h
@ -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
|
||||
|
@ -7,7 +7,7 @@ namespace Ui {
|
||||
class LibWidget;
|
||||
}
|
||||
|
||||
#include "team.h"
|
||||
#include "behavior.h"
|
||||
#include "map.h"
|
||||
|
||||
class LibWidget : public QWidget
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "simulation.h"
|
||||
|
||||
Simulation::Simulation()
|
||||
Simulation::Simulation(Map *_map,std::vector<BehaviorFunction> _behaviors):
|
||||
p_map(_map),m_behaviors(_behaviors)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1,3 +0,0 @@
|
||||
#include "team.h"
|
||||
|
||||
// TODO Info functions
|
Loading…
x
Reference in New Issue
Block a user