-
Notifications
You must be signed in to change notification settings - Fork 2
/
mouse.h
89 lines (64 loc) · 1.93 KB
/
mouse.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef MOUSE_H_
#define MOUSE_H_
#include <array>
#include <cmath>
#include <iostream>
#include <vector>
#include "maze.h"
#include "sensor.h"
#include "command.h"
#include "algorithm.h"
#include "simulation.h"
#define _USE_MATH_DEFINES
float deg2rad(int deg);
class Maze;
class Sensor;
class Simulation;
class Algorithm;
class Mouse
{
private:
// internal representation of explored maze
Maze* internalMaze;
// Algorithm used to move in the maze
Algorithm * algorithm;
void readWalls();
void turn(int theta);
void updateTf();
/**
Attempt moving forward.
Args:
refMaze: ptr to maze in which to move forward.
Returns false on collision with refMaze.
*/
bool advance(Maze const* refMaze);
// Intended to be private. To be used with the appropriate Command interface
bool advance(float theta, float x, Maze const* refMaze);
// writes an individual sensor's output to the internal maze
void writeSensorData(bool data, int theta);
// Reads current sensorOutputs and updates the internal rep of maze
void updateInternalMaze();
//current x,y, theta position
// This mouse only supports integer coords
int cx, cy, ctheta;
std::array<int, 4> Tf;
// Sensors on this mouse
std::vector<Sensor> sensors;
std::vector<bool> sensorOutputs;
public:
Mouse(void);
bool executeCommand(CommandI const* command, Maze const * refMaze);
void addSensor(Sensor * sensor);
void readSensors(Maze const* refMaze);
const std::vector<bool> getSensorState() const {return sensorOutputs;};
Maze * getInternalMaze() const { return internalMaze; };
int getX() const {return cx;}
int getY() const {return cy;}
int getTheta() const {
int theta = (ctheta + 360) % 360;
return theta;}
void show();
void start(Maze const* refMaze, Simulation * sim = nullptr);
void setAlgorithm(Algorithm * algorithm);
};
#endif