Skip to content

Commit 3070bc9

Browse files
committed
Adding structure :
Action (one must overload the function operator) State
1 parent 7afd233 commit 3070bc9

13 files changed

+107
-9
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
1010
INCLUDE_DIRECTORIES(".")
1111

1212
add_subdirectory(Motor)
13+
add_subdirectory(Samples)
1314
#add_subdirectory(Sample_Rubik2D)

Motor/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project(Sample_Rubik2D)
1+
project(Motor)
22
cmake_minimum_required(VERSION 2.8)
33
file ( GLOB_RECURSE SRC *.?pp )
44
SET(CMAKE_CXX_FLAGS "-std=c++11")

Motor/action.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "action.hpp"
2+
3+
Action::Action()
4+
{
5+
6+
}
7+
8+
Action::~Action()
9+
{
10+
11+
}
12+

Motor/action.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef ACTION_HPP
2+
#define ACTION_HPP
3+
4+
#include <state.hpp>
5+
6+
7+
class Action
8+
{
9+
public:
10+
Action();
11+
virtual ~Action() = 0;
12+
13+
virtual State *operator()(State *s) = 0;
14+
};
15+
16+
#endif // ACTION_HPP

Motor/node.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
#include "node.hpp"
22

3-
template <typename StateType>
4-
Node<StateType>::Node(StateType s)
5-
{
6-
7-
}
8-
93
template <typename StateType>
104
Node<StateType>::~Node()
115
{
@@ -15,5 +9,11 @@ Node<StateType>::~Node()
159
delete *it;
1610
}
1711

18-
//note that we did not delete the parent node, so if you want to destroy the whole tree you want to call delete on root.
12+
//note that we did not delete the parent node, so if want to destroy the whole tree you must call delete on root.
13+
}
14+
15+
template <typename StateType>
16+
void Node<StateType>::develop()
17+
{
18+
state.getChildren();
1919
}

Motor/node.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#ifndef NODE_HPP
22
#define NODE_HPP
33

4+
#include "action.hpp"
5+
46
#include <vector>
57

68
using std::vector;
79

10+
/**
11+
* the templated Statetype must extend State
12+
*/
813
template <typename StateType>
914
class Node
1015
{
@@ -16,8 +21,11 @@ class Node
1621
vector<Node *> children;
1722

1823
public:
19-
Node(StateType s);
24+
Node(Node* p, Action *a) : parent(p), depth(p->depth + 1), state(a(p->state)) {}
2025
~Node();
26+
27+
//computes children
28+
void develop();
2129
};
2230

2331
#endif // NODE_HPP

Samples/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project(Samples)
2+
3+
add_subdirectory(Rubik2D)

Samples/Rubik2D/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project(Rubik2D)
2+
cmake_minimum_required(VERSION 2.8)
3+
file ( GLOB_RECURSE SRC *.?pp )
4+
SET(CMAKE_CXX_FLAGS "-std=c++11")
5+
add_executable(Rubik2D ${SRC})

Samples/Rubik2D/board.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "board.hpp"
2+
3+
Board::Board()
4+
{
5+
6+
}
7+
8+
Board::~Board()
9+
{
10+
11+
}
12+

Samples/Rubik2D/board.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef BOARD_HPP
2+
#define BOARD_HPP
3+
4+
5+
class Board
6+
{
7+
public:
8+
Board();
9+
~Board();
10+
};
11+
12+
#endif // BOARD_HPP

Samples/Rubik2D/main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "board.hpp"
2+
3+
#include <iostream>
4+
5+
#include <Motor/node.hpp>
6+
#include <Motor/action.hpp>
7+
8+
int main(int argc, char* argv[])
9+
{
10+
11+
}

state.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "state.hpp"
2+
3+
State::State()
4+
{
5+
6+
}

state.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef STATE_HPP
2+
#define STATE_HPP
3+
4+
5+
class State
6+
{
7+
public:
8+
State();
9+
virtual ~State() = 0;
10+
};
11+
12+
#endif // STATE_HPP

0 commit comments

Comments
 (0)