#include <map.h>
Public Types | |
enum | Piece { KEEPER = 0, KEEPER_ON_GOAL = 1, GEM = 2, GEM_ON_GOAL = 3, EMPTY = 4, GOAL = 5, WALL = 6, OUTSIDE = 7 } |
enum | MapValidity { IS_VALID, NO_KEEPER, TOO_MANY_KEEPERS, NO_GEMS, MORE_GEMS_THAN_GOALS, MORE_GOALS_THAN_GEMS, MAP_LEAKS, MAP_SOLVED, MAP_INVALID } |
Public Methods | |
Map (int width, int height, std::vector< int > const &pieces) | |
Map (QDataStream &stream) | |
Map (QStringList &lines) | |
Map (CompressedMap const &compressed_map) | |
void | writeToStream (QDataStream &stream) |
int | width () const |
int | height () const |
std::vector< int > const & | pieces () const |
bool | isValid () const |
MapValidity | validity () const |
bool | isSolved () const |
int | numberOfEmptyGoals () const |
int | getIndex (QPoint position) const |
QPoint | getPoint (int index) const |
bool | isValidPosition (QPoint position) const |
bool | isValidIndex (int index) const |
Piece | getPiece (QPoint position) const |
Piece | getPiece (int index) const |
void | setPiece (QPoint position, int piece) |
void | setPiece (int index, int piece) |
void | mirrorVertically () |
void | mirrorHorizontally () |
void | rotateLeft () |
void | rotateRight () |
bool | isCrossed (QPoint position) const |
bool | isCrossed (int index) const |
void | uncrossAll () |
bool | isReachable (QPoint position) const |
bool | isReachable (int index) const |
void | calcReachable () const |
void | calcReachable (QPoint position) const |
void | calcReachable (int index) const |
void | clearReachable () const |
bool | isDeadlock (QPoint position) const |
bool | isDeadlock (int index) const |
void | clearDeadlocks () const |
void | calcDeadlocks () const |
void | crossDeadlocks () const |
QPoint | keeper () const |
void | setKeeper (QPoint position) |
void | setKeeper (int index) |
void | setKeeperToFirstReachable () |
void | moveGem (QPoint from, QPoint to) |
void | moveGem (int from, int to) |
bool | containsKeeper (QPoint position) const |
bool | containsKeeper (int index) const |
bool | containsGem (QPoint position) const |
bool | containsGem (int index) const |
bool | containsGoal (QPoint position) const |
bool | containsGoal (int index) const |
bool | canDropKeeper (QPoint position) const |
bool | canDropKeeper (int index) const |
bool | canDropGem (QPoint position) const |
bool | canDropGem (int index) const |
void | doMove (Move const &move, bool retro_mode) |
void | doUndoMove (Move const &move, bool retro_mode) |
bool | isValidMove (Move const &move, bool retro_mode) const |
bool | isValidNonPushMove (Move const &move) const |
bool | isValidPushMove (Move const &move, bool retro_mode) const |
bool | isValidAtomicPushMove (Move const &move, bool retro_mode) const |
Movements | getShortestPath (QPoint from, QPoint to) const |
Movements | getShortestPathForGem (QPoint from, QPoint to, bool retro) const |
std::vector< int > | getDistanceMap (QPoint const &position, int unsolvable, bool retro_mode=false) const |
std::vector< int > | getDistanceMap (int index, int unsolvable, bool retro_mode=false) const |
Movements | expandMove (Move const &move, bool retro_mode) const |
Movements | expandUndoMove (Move const &move) const |
Movements | expandMoves (Movements moves, bool retro_mode) const |
Movements | collapseMoves (Movements moves) const |
bool | areValidMoves (Movements const &moves) const |
bool | areValidSolutionMoves (Movements const &moves, int &number_of_pushes, int &number_of_moves) const |
Map | adjustSize () const |
Map | fillEdges () const |
Map | simplify () const |
QString | toText () const |
QString | toServerFormat () const |
Static Public Methods | |
bool | isMapLine (QString const &line) |
bool | pieceContainsKeeper (int piece) |
bool | pieceContainsGem (int piece) |
bool | pieceContainsGoal (int piece) |
bool | canDropKeeperOnPiece (int piece) |
bool | canDropGemOnPiece (int piece) |
Private Types | |
enum | PieceFlags { CROSSED = 8, REACHABLE = 16, DEADLOCK = 32 } |
enum | Mask { PIECE = 7, ALL = PIECE + CROSSED + REACHABLE + DEADLOCK, CLEAR_PIECE = ALL - PIECE, CLEAR_CROSSED = ALL - CROSSED, CLEAR_REACHABLE = ALL - REACHABLE, CLEAR_DEADLOCK = ALL - DEADLOCK } |
Private Methods | |
bool | areValidSolutionMovesImpl (Movements const &moves, bool &is_solution, int &number_of_pushes, int &number_of_moves) const |
void | calcTrivialDeadlocks () const |
bool | isPossibleDeadlock (int index) const |
void | setupOffsets () |
void | setupNumberOfEmptyGoals () const |
void | setupKeeperAndEmptyGoals () |
void | createOutsidePieces () |
void | createOutsidePiecesHelper (int x, int y) |
Private Attributes | |
int | m_width |
int | m_height |
int | m_size |
QPoint | m_keeper |
MapValidity | m_validity |
int | m_empty_goals |
bool | m_deadlocks_valid |
bool | m_reachable_valid |
bool | m_empty_goals_valid |
bool | m_validity_valid |
std::vector< int > | m_pieces |
int | m_xy_offsets [4] |
Static Private Attributes | |
char const | s_piece_to_text [8] |
bool const | s_piece_contains_gem [8] |
bool const | s_piece_contains_goal [8] |
bool const | s_can_drop_keeper [24] |
bool const | s_can_drop_gem [8] |
QRegExp | s_map_regexp |
Note that there exists two version of most functions. One taking a point (x-, y-values) and one an index (x + y * width()).
|
|
Used to map out the different informations on the fields.
|
|
Here we define the pieces of a field.
|
|
Defines some additional flags for a piece.
|
|
Creates a new map.
|
|
Constructs a map from a data stream.
|
|
Constructs the map from a list of lines in xsb format. The constructor removes all lines in the string list, which were before the actual map and the lines of the actual map itself. Be sure to call isValid() afterwards.
|
|
Constructs a map from a compressed map.
|
|
Return a new map, which has the minimum possible size of the current map.
|
|
Returns true, if the given moves are valid starting from this map. Note that the moves must be atomic!
|
|
Returns true, if the given moves are valid starting from this map and solve this map. Note that the moves must be atomic!
|
|
Implementation of areValidSolutionMoves(). Also used in areValidMoves(). Note that the moves must be atomic!
|
|
Calculates all deadlock fields.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Calculates all reachable fields if the keeper stands on the specified position.
|
|
Calculates all reachable fields. Note that the position of the keeper is important. |
|
Calculates all trivial deadlocks (positions in which a stone can not be moved).
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns true, if a gem can be dropped to the given position.
|
|
Returns true, if a gem can be dropped on the given piece. A field with the keeper is also considered a valid gem drop field.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns true, if a keeper can be dropped on the field. Note that a field with a keeper is also considered a valid keeper drop field.
|
|
Returns true, if the keeper can be dropped in the piece.
|
|
Clears all deadlocks.
|
|
Clears all reachable fields.
|
|
Returns the movements given in a collapsed form. This means simple keeper moves are combined und ston pushes in one direction also. Note the we don't check, if the moves are valid, so it may be the best to call expandMoves first.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns true, if the piece at the given position contains a gem.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns true, if the piece at the given position contains a goal.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns true, if the piece at the given position contains a keeper.
|
|
Creates the outside pieces.
|
|
Helper function needed by createOutsidePieces().
|
|
Crosses all deadlocks.
|
|
Performs the given move.
|
|
Performs the given undo move. An undo move is the reverse of a normal move.
|
|
Returns a sequence of atomic moves for a given move. The move must be legal.
|
|
Returns the movements given in an explicit form (meaning all moves are simple moves). If the moves are illegal starting from the current map, an empty moves list ist returned.
|
|
Returns a sequence of atomic moves for a given undo move. The undo move must be legal.
|
|
Returns a version of the map with filled edges.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns the distance map for a given field. The value of the returned map at [d + 4 * gem_pos] is the number of moves required, to move a gem at position gem_pos to the given field, when the keeper stands left (d = 0), right (d = 1), above (d = 2) or down (d = 3) the gem.
|
|
Returns the index for the given position.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns the piece at the given position.
|
|
Returns the point for the given index.
|
|
Gets the shortes path for a keeper (if it exists) between two points. If no path exists, we return Movements with no moves.
|
|
Gets the shortes path (if it exists) for moving a gem from one position to another. If no path exists, we return Movements with no moves. Note that the position of the keeper matters.
|
|
Returns the height of the map.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns true, if the piece at the given position is crossed.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns true, if the given field is a deadlock field.
|
|
Returns true, if the given string is a map line.
|
|
Returns true, if the field is a possible deadlock field. This means it must be EMPTY, GEM or KEEPER.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Returns true, if the field is reachable. Note that you should have called calcReachable() before. |
|
Returns true, if the map is solved.
|
|
Returns true, if the map is valid.
|
|
Returns true, if the given stone push move is valid (meaning the stone can be pushed).
|
|
Returns true, if the index is valid.
|
|
Returns true, if the given move is valid.
|
|
Returns true, if the given (not push move) is valid.
|
|
Returns true, if the given position is valid (corresponds to a field of the map).
|
|
Returns true, if the given stone push move is valid (meaning the stone can be pushed).
|
|
Returns the position of the keeper.
|
|
Mirrors the map horizontally.
|
|
Mirrors the map vertically.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Moves a gem from one to another position.
|
|
Returns the number of goals without gems.
|
|
Returns true, if the piece contains a gem.
|
|
Returns true, of the piece contains a goal.
|
|
Returns true, if the piece contains a keeper.
|
|
Returns a vector with the raw piece codes.
|
|
Rotates the map left by 90 deg. This is implemented by 3 times rotateRight(). |
|
Rotates the map right by 90 deg.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Sets the position of the keeper. Removes the keeper from the old position (if it still was at the old position). Note that the keeper is 'beamed'.
|
|
Sets the keeper to the first reachable field.
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
Sets the piece at the given position. If you want to set the keeper, you better use setKeeper().
|
|
Finds and set the keeper and the number of empty goals.
|
|
Sets up the numer of empty goals.
|
|
Sets up the offsets.
|
|
Returns a simplified version of the map. In the simplified version we deleted as much as possible walls and gems, without changing the solution of the map. |
|
Returns a representation of the map which is understandable by the highscore server.
|
|
Returns a human readable representation of the map in xsokoban format.
|
|
Clears all crossed fields.
|
|
Returns the validity of the map. You should call this after creation of the map, when you can not be sure if the map is valid. |
|
Returns the width of the map.
|
|
Writes the map to a data stream.
|
|
If true, we have already calculated the deadlocks.
|
|
The number of empty goals.
|
|
If true, the numer of empty goals is valid.
|
|
The height of the map.
|
|
Here we store the position of the keeper.
|
|
Here we store the pieces and additional information of the fields.
|
|
If true, the reachable fields are up to date.
|
|
This is m_width * m_height.
|
|
The validity of the map.
|
|
If true, the validity is valid :).
|
|
The width of the map.
|
|
Here we store the offset to go one in x- or y-direction.
|
|
Used to determine, if we can drop a gem on the piece.
|
|
Used to determine, if we can drop the keeper on the piece.
|
|
The regexp used to identify map lines.
|
|
Used to determine, if a piece contains a gem.
|
|
Used to determine, if a piece contains a goal.
|
|
Used to convert compressed piece values to characters used by xsokoban.
|