Sokoban
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Map Class Referenceabstract

Abstract class representing general map (ancestor for two player and single player map) and its api. More...

#include <Map.h>

Inheritance diagram for Map:
SinglePlayerMap TwoPlayerMap

Public Member Functions

virtual bool complete ()=0
 Checks if map is completed (all barrels are on targets). More...
 
virtual void restart ()=0
 Restarts level. More...
 
virtual ~Map ()
 Virtual destructor. More...
 
int get_width () const
 Gets with of map (horizontal number of cells). More...
 
int get_height () const
 Gets with of map (vertical number of cells). More...
 
virtual bool solve ()=0
 Tries to solve map using backtracking. More...
 
virtual bool play_solution_next ()=0
 If map is solved do next step in solution. More...
 
virtual element get_field_type (int x, int y)=0
 Gets type of cell. More...
 
virtual bool is_dead_position ()=0
 Determines if in actual state of game is possible to move with all barrels. More...
 
virtual void right_move ()=0
 
virtual void left_move ()=0
 
virtual void up_move ()=0
 
virtual void down_move ()=0
 
virtual void right_move_second ()=0
 
virtual void left_move_second ()=0
 
virtual void up_move_second ()=0
 
virtual void down_move_second ()=0
 

Static Public Attributes

static const char NUMBER_OF_FIELDS = 10
 
static const int MAX_STEPS = 1000
 
static const char EOM = 'x'
 
Constants which represents the number of game elements. They use easy arithmetics which is used in engine.

ground + barrel = barrel
ground + sokoban = sokoban
ground + sokoban2 = sokoban2
target + barrel = barrel target
target + sokoban = sokoban target
target + sokoban2 = sokoban2 target

static const element GROUND = 0
 
static const element TARGET = 1
 
static const element BARREL = 2
 
static const element BARREL_TARGET = 3
 
static const element SOKOBAN = 4
 
static const element SOKOBAN_TARGET = 5
 
static const element WALL = 6
 
static const element GRASS = 7
 
static const element SOKOBAN_2 = 8
 
static const element SOKOBAN_2_TARGET = 9
 

Protected Member Functions

 Map (std::ifstream &map_stream)
 Constructor. More...
 
bool is_valid_position (int x, int y)
 Checks if position (x,y) is in map grid. More...
 

Protected Attributes

std::vector< std::vector< char > > game_grid
 
int number_of_barrels
 
int width
 
int height
 
TwoPlayerGameState init_state
 Game state which is used by the constructor for general map including a position of sokoban and position of barrels. More...
 

Detailed Description

Abstract class representing general map (ancestor for two player and single player map) and its api.

Constructor & Destructor Documentation

◆ ~Map()

virtual Map::~Map ( )
inlinevirtual

Virtual destructor.

◆ Map()

Map::Map ( std::ifstream &  map_stream)
protected

Constructor.

Creates general map from the input stream.

Parameters
map_streamInput stream which the map is made from.

Member Function Documentation

◆ complete()

virtual bool Map::complete ( )
pure virtual

Checks if map is completed (all barrels are on targets).

Returns
Bool value which determines if map is completed.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ down_move()

virtual void Map::down_move ( )
pure virtual

Moves the first sokoban down if it is possible.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ down_move_second()

virtual void Map::down_move_second ( )
pure virtual

Moves the second sokoban down if it is possible.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ get_field_type()

virtual element Map::get_field_type ( int  x,
int  y 
)
pure virtual

Gets type of cell.

Parameters
xThe coordinate x of cell.
yThe coordinate y of cell.
Returns
Byte number which represents field type according to the constants.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ get_height()

int Map::get_height ( ) const
inline

Gets with of map (vertical number of cells).

Returns
Height of map in number of cells.

◆ get_width()

int Map::get_width ( ) const
inline

Gets with of map (horizontal number of cells).

Returns
Width of map in number of cells.

◆ is_dead_position()

virtual bool Map::is_dead_position ( )
pure virtual

Determines if in actual state of game is possible to move with all barrels.

Returns
Bool value which determines if in actual state of game is possible to move with all barrels.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ is_valid_position()

bool Map::is_valid_position ( int  x,
int  y 
)
inlineprotected

Checks if position (x,y) is in map grid.

Parameters
xFirst position coordinate.
ySecond position coordinate.
Returns
True if position (x,y) is in map grid. False otherwise.

◆ left_move()

virtual void Map::left_move ( )
pure virtual

Moves the first sokoban to the left if it is possible.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ left_move_second()

virtual void Map::left_move_second ( )
pure virtual

Moves the second sokoban to the left if it is possible.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ play_solution_next()

virtual bool Map::play_solution_next ( )
pure virtual

If map is solved do next step in solution.

Returns
True if map is sloved and steps is done, false if map is not solved yet.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ restart()

virtual void Map::restart ( )
pure virtual

Restarts level.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ right_move()

virtual void Map::right_move ( )
pure virtual

Moves the first sokoban to the right if it is possible.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ right_move_second()

virtual void Map::right_move_second ( )
pure virtual

Moves the second sokoban to the right if it is possible.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ solve()

virtual bool Map::solve ( )
pure virtual

Tries to solve map using backtracking.

Returns
Bool value which determines if map was solved.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ up_move()

virtual void Map::up_move ( )
pure virtual

Moves the first sokoban up if it is possible.

Implemented in TwoPlayerMap, and SinglePlayerMap.

◆ up_move_second()

virtual void Map::up_move_second ( )
pure virtual

Moves the second sokoban up if it is possible.

Implemented in TwoPlayerMap, and SinglePlayerMap.

Member Data Documentation

◆ BARREL

const element Map::BARREL = 2
static

◆ BARREL_TARGET

const element Map::BARREL_TARGET = 3
static

◆ EOM

const char Map::EOM = 'x'
static

◆ game_grid

std::vector<std::vector<char> > Map::game_grid
protected

Array which represents game grid.

◆ GRASS

const element Map::GRASS = 7
static

◆ GROUND

const element Map::GROUND = 0
static

◆ height

int Map::height
protected

Number of vertical fields of the map.

◆ init_state

TwoPlayerGameState Map::init_state
protected

Game state which is used by the constructor for general map including a position of sokoban and position of barrels.

It is not used in concrete map. Information from it is copied to another variables

◆ MAX_STEPS

const int Map::MAX_STEPS = 1000
static

Maximal number of steps in backtracking.

◆ number_of_barrels

int Map::number_of_barrels
protected

Number of barrels in the map.

◆ NUMBER_OF_FIELDS

const char Map::NUMBER_OF_FIELDS = 10
static

Number of game elements.

◆ SOKOBAN

const element Map::SOKOBAN = 4
static

◆ SOKOBAN_2

const element Map::SOKOBAN_2 = 8
static

◆ SOKOBAN_2_TARGET

const element Map::SOKOBAN_2_TARGET = 9
static

◆ SOKOBAN_TARGET

const element Map::SOKOBAN_TARGET = 5
static

◆ TARGET

const element Map::TARGET = 1
static

◆ WALL

const element Map::WALL = 6
static

◆ width

int Map::width
protected

Number of horizontal cells of the map.


The documentation for this class was generated from the following file: