Search algorithms for the 8-puzzle solution
Game.hpp
Go to the documentation of this file.
1 /**
2  * @author Douglas De Rizzo Meneghetti (douglasrizzom@gmail.com)
3  * @date 2017-6-22
4  * @brief Class representing the rules of a game.
5  */
6 
7 #ifndef SEARCH_GAME_HPP
8 #define SEARCH_GAME_HPP
9 
10 #include "GameState.hpp"
11 #include "GameAction.hpp"
12 
13 //! Class representing the rules of a game.
14 //! Used to generalize the search algorithms to any dimension of the 8-puzzle game.
15 class Game {
16  private:
17 
19 
20  public:
21 
22  ~Game() {
23  delete goal;
24  }
25 
26  //! Creates a game representation and keeps a GameState of the goal state.
27  //! \param dimension dimensions of the puzzle board.
28  explicit Game(int dimension) {
29  goal = new GameState();
30  int **representation = new int *[dimension];
31 
32  int val = 1;
33 
34  for (int x = 0; x < dimension; x ++) {
35  representation[x] = new int[dimension];
36 
37  for (int y = 0; y < dimension; y ++) {
38  representation[x][y] = val ++ % (dimension * dimension);
39  }
40  }
41 
42  goal->setRepresentation(representation);
43  }
44 
45  GameState *getGoal() const {
46  return goal;
47  }
48 };
49 
50 #endif // ifndef SEARCH_GAME_HPP
~Game()
Definition: Game.hpp:22
Class representing the rules of a game.
Definition: Game.hpp:15
GameState()
Default constructor, everything starts as 0 or NULL.
Definition: GameState.hpp:60
void setRepresentation(int **representation)
Definition: GameState.hpp:328
Game(int dimension)
Creates a game representation and keeps a GameState of the goal state.
Definition: Game.hpp:28
GameState * getGoal() const
Definition: Game.hpp:45
Describes a single state in the 8-puzzle.
Definition: GameState.hpp:18
GameState * goal
Definition: Game.hpp:18