Skip to content

vacondio/cpp-15puzzle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

15puzzle

Pet project to pick up C++ after some years of not using it.

Compile instructions

Compile with g++ on GNU/Linux with

make

Clean the source tree with

make clean

Game instructions

Use the wasd keys to slide numbers into the empty cell from the neighbouring cells. For example, enter the s character to slide the number down from the cell above the empty cell. The goal is to arrange all numbers in increasing order with no empty cells in between them!

You can enter all the moves you want in a single line: after hitting <RET>, they will all be executed at once. Invalid input is ignored.

Enter q to quit the game at any time.

Technical Remarks

There are currently three random generation algorithms for the initial puzzle: randomOrder, randomOrderDumb and randomOrderDumber.

randomOrder makes use of a very straightforward method based on std::vector; whereas randomOrderDumb is based on std::array, avoiding dynamic memory allocation. In both cases a random number i is generated to extract the integer in the i-th position inside the {1, ..., 16} array. While randomOrder just removes the extracted number from the array, randomOrderDumb has to make sure at every extraction that previously extracted numbers are not re-extracted, since its array cannot be resized. This is done by setting to 0 extracted numbers.

randomOrderDumber is an implementation of randomOrderDumb that does not destroy the {1, ..., 16} array by setting extracted numbers to 0. It scales horribly: just try to recompile the program by increasing the nRows and nCols variables by one or two orders of magnitude.

To-do list

  • Change name to randomOrderDumb (it is not so dumb after all)
  • Polishing (e.g. add a welcome message)
  • Add command line argument support (for e.g. choosing the init mode)
  • Add undo/redo support by recording the commands injected into Puzzle (a separate class is likely to be needed?)
  • Save high score in a directory in user home (e.g. $HOME/.cpp15puzzle/)

About

A 15 Puzzle implementation written in C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors