diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/2048.hpp | 6 | ||||
| -rw-r--r-- | include/expectimax.hpp | 17 | ||||
| -rw-r--r-- | include/game.hpp | 30 | ||||
| -rw-r--r-- | include/graphics.hpp | 48 |
4 files changed, 63 insertions, 38 deletions
diff --git a/include/2048.hpp b/include/2048.hpp index fff7a80..08669fa 100644 --- a/include/2048.hpp +++ b/include/2048.hpp @@ -1,12 +1,12 @@ #ifndef H2048_HPP # define H2048_HPP -typedef enum +enum Direction { - DIRECTION_LEFT, + DIRECTION_LEFT = 0, DIRECTION_RIGHT, DIRECTION_DOWN, DIRECTION_UP -} Direction; +}; #endif diff --git a/include/expectimax.hpp b/include/expectimax.hpp new file mode 100644 index 0000000..a3163e1 --- /dev/null +++ b/include/expectimax.hpp @@ -0,0 +1,17 @@ +#ifndef EXPECTIMAX_HPP +# define EXPECTIMAX_HPP + +#include "2048.hpp" +#include "game.hpp" + +class Expectimax +{ + public: + Expectimax(Game *g); + Direction move(); + + private: + Game *game; +}; + +#endif diff --git a/include/game.hpp b/include/game.hpp index 62a024c..5e01b0d 100644 --- a/include/game.hpp +++ b/include/game.hpp @@ -1,6 +1,8 @@ #ifndef GAME_HPP # define GAME_HPP +#include <iostream> +#include <iomanip> #include <cstdlib> #include <vector> #include <utility> @@ -9,23 +11,27 @@ class Game { public: - Game(int s); + Game(int size); + Game(Game const &other); + Game &operator=(Game const &other); ~Game(); - int getSize(); - int getScore(); - int at(int x, int y); - void move(Direction direction); + int getSize() const; + int getScore() const; + int get(int y, int x) const; + bool move(Direction direction); void spawn(); - bool lost(); + bool lost() const; private: - int size; - int **grid; - int score; + int m_size; + int m_score; + int **m_grid; + void mergeRow(std::vector<int> &row); - int **gridCopy(); - bool gridEqual(int **other); - void gridDestroy(int **g); }; +bool operator==(Game const &a, Game const &b); +bool operator!=(Game const &a, Game const &b); +std::ostream &operator<<(std::ostream &out, Game const &game); + #endif diff --git a/include/graphics.hpp b/include/graphics.hpp index 6951fc0..42de214 100644 --- a/include/graphics.hpp +++ b/include/graphics.hpp @@ -16,38 +16,40 @@ class Graphics { public: - Graphics(Game *g, std::string t, int w, int h, AI *ai = NULL); + Graphics(Game &game, std::string title, int width, int height, AI *ai = NULL); ~Graphics(); void update(); - bool isRunning(); + bool isRunning() const; private: - bool running; - std::string title; - int width; - int height; - int gridSize; - Game *game; - SDL_Renderer *renderer; - SDL_Window *window; - TTF_Font *font; - SDL_Texture *scoreText; - std::vector< std::pair<int, SDL_Texture*> > numberTexBuf; - std::map< int, SDL_Color > palette; - AI *ai; - Uint32 aiTimeStep; - Uint32 aiNextTime; + bool m_running; + Game &m_game; + std::string m_title; + int m_width; + int m_height; + AI *m_ai; + Uint32 m_aiTimeStep; + int m_gridSize; + Uint32 m_aiNextTime; + SDL_Renderer *m_renderer; + SDL_Window *m_window; + TTF_Font *m_font; + SDL_Texture *m_scoreText; + std::vector< std::pair<int, SDL_Texture*> > + m_numberTexBuf; + std::map< int, SDL_Color > + m_palette; - void drawGame(); - void drawCell(int x, int y); - void drawScore(); - void handleEvent(); + void drawGame(); + void drawCell(int x, int y); + void drawScore(); + void handleEvent(); SDL_Texture *addNumberTex(int n); - SDL_Texture *getNumberTex(int n); + SDL_Texture *getNumberTex(int n) const; SDL_Texture *newTextTex(std::string s, SDL_Color c); - void error(); + void error() const; }; #endif |
