Skip to content

pangqiao/NPuzzle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPuzzle

In the 16-puzzle version of the game, a 4x4 board consists of 15 tiles numbered 1 through 15 and an empty tile (marked as 0). One may move any tile into an orthogonally adjacent empty square, but maynot move outside the board or diagonally.The problem is to find a sequence of moves that transforms an initial board configuration into a specified goal configuration. The following are examples of an initial and goal configurations.

Initial configuration

initial

Goal configuration

goal

Algorithm

The mouse click is mapped to UP, DOWN, LEFT and RIGHT accordingly. Such as: 0 is in the tile of(2,3),if I click 11, 11 moves to the right.

goal

The method to move RIGHT like this:

def move( direction):
  ... ...
  if(direction == Direction.RIGHT): 
    if column_0 != 0:
      blocks[row_0][column_0] = blocks[row_0][column_0 - 1]
      blocks[row_0][column_0 - 1] = 0
      column_0 -= 1 

Make sure the final configuration can be reached

In initial state, make all the data according to the final configuration first. And then move the tiles in random direction with different rounds. The round decides the different Level :easy, medium or high.

Tool chain

  1. Python3
  2. tkinter

About

NPuzzle game with python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages