{"id":22723,"date":"2020-08-14T08:36:03","date_gmt":"2020-08-14T08:36:03","guid":{"rendered":"http:\/\/itsourcecode.com\/?p=22723"},"modified":"2025-04-07T08:19:46","modified_gmt":"2025-04-07T08:19:46","slug":"puzzle-game-in-python-with-source-code","status":"publish","type":"post","link":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/","title":{"rendered":"Puzzle Game In Python With Source Code"},"content":{"rendered":"\n<p>The <strong>Puzzle Game In Python<\/strong> is written in the Python programming language, <strong>Puzzle Game Code In Python<\/strong>, there is a 4*4 board with 15 numbers. The numbers are then shuffled randomly. <\/p>\n\n\n\n<p>In this tutorial, I will teach you how to create a <strong>Memory Puzzle Game In Python<\/strong>.<\/p>\n\n\n\n<p>A game <strong>Python Puzzle Game<\/strong> has steps to follow, the first is to move the number of tiles into the empty tile space until the tiles are back in their original order from 1 to 15.<\/p>\n\n\n\n<p>Anyway, if you want to level up your knowledge in programming especially games in Python, try this new article I\u2019ve made for you <a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/code-for-game-in-python\/\">Code For Game in Python: Python Game Projects With Source Code<\/a>.<\/p>\n\n\n\n<p>This <strong>Puzzle Game In Python<\/strong> also includes a downloadable <strong>Source Code For Puzzle Game in Python<\/strong> for free, just find the downloadable source code below and click to start downloading.<\/p>\n\n\n\n<p>To start creating a <strong><a href=\"http:\/\/inventwithpython.com\/pygame\/chapter4.html\">Puzzle Game<\/a> In Python<\/strong>, make sure that you have <strong>PyCharm IDE<\/strong> installed on your computer.<\/p>\n\n\n\n<p>By the way, if you are new to Python programming and don&#8217;t know what Python IDE to use, I have here a list of the Best Python IDE for Windows, Linux,  and Mac OS that will suit you. I also have here How to Download and Install the <a href=\"https:\/\/itsourcecode.com\/blogs\/how-to-download-and-install-latest-version-of-python-on-windows-2021\/\">Latest Version of Python on Windows<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Create a Puzzle Game In Python?<\/strong><\/h2>\n\n\n\n<div class=\"schema-how-to wp-block-yoast-how-to-block\"><p class=\"schema-how-to-description\"><strong>Puzzle Game In Python<\/strong> <strong>With Source Code<\/strong><\/p> <ul class=\"schema-how-to-steps\"><li class=\"schema-how-to-step\" id=\"how-to-step-1597382213945\"><strong class=\"schema-how-to-step-name\">Step 1: Create a project name.<\/strong> <p class=\"schema-how-to-step-text\">First, open\u00a0<strong>Pycharm IDE<\/strong>\u00a0and then create a &#8220;<strong>project name<\/strong>&#8221; after creating a project name click the &#8220;<strong>create<\/strong>&#8221; button.<br\/><img decoding=\"async\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-Project-Name-1.png\" alt=\"Puzzle Game In Python Project Name\"\/><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1597382272396\"><strong class=\"schema-how-to-step-name\">Step 2: Create a python file.<\/strong> <p class=\"schema-how-to-step-text\">Second, after creating a project name, &#8220;<strong>right click<\/strong>&#8221; your project name and then click &#8220;<strong>new<\/strong>&#8221; after that click the &#8220;<strong>python file<\/strong>&#8220;.<br\/><img decoding=\"async\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-File.png\" alt=\"Puzzle Game In Python File\"\/><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1597382289077\"><strong class=\"schema-how-to-step-name\">Step 3: Name your python file.<\/strong> <p class=\"schema-how-to-step-text\">Third, after creating a Python file, Name your Python file after that click &#8220;<strong>enter<\/strong>\u201c.<br\/><img decoding=\"async\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-File-Name.png\" alt=\"Puzzle Game In Python File Name\"\/><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1597382314773\"><strong class=\"schema-how-to-step-name\">Step 4: The actual code.<\/strong> <p class=\"schema-how-to-step-text\">You are free to copy the code given below and download the full source code below.<\/p> <\/li><\/ul><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For Importing Modules or Libraries<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame, sys, random\nfrom pygame.locals import *<\/code><\/pre>\n\n\n\n<p>The code is given which is importing all modules or libraries.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Design Of The Puzzle<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Create the constants (go ahead and experiment with different values)\nBOARDWIDTH = 4  # number of columns in the board\nBOARDHEIGHT = 4 # number of rows in the board\nTILESIZE = 80\nWINDOWWIDTH = 640\nWINDOWHEIGHT = 480\nFPS = 30\nBLANK = None\n\n#                 R    G    B\nBLACK =         (  0,   0,   0)\nWHITE =         (255, 255, 255)\nBRIGHTBLUE =    (  0,  50, 255)\nDARKTURQUOISE = (  3,  54,  73)\nBLUE =         (  0,  50, 255)\nGREEN =        (  0, 128,   0)\nRED =           (255, 0, 0)\nBGCOLOR = DARKTURQUOISE\nTILECOLOR = BLUE\nTEXTCOLOR = WHITE\nBORDERCOLOR = RED\nBASICFONTSIZE = 20\nTEXT = GREEN\n\nBUTTONCOLOR = WHITE\nBUTTONTEXTCOLOR = BLACK\nMESSAGECOLOR = WHITE\n\nXMARGIN = int((WINDOWWIDTH - (TILESIZE * BOARDWIDTH + (BOARDWIDTH - 1))) \/ 2)\nYMARGIN = int((WINDOWHEIGHT - (TILESIZE * BOARDHEIGHT + (BOARDHEIGHT - 1))) \/ 2)\n\nUP = 'up'\nDOWN = 'down'\nLEFT = 'left'\nRIGHT = 'right'<\/code><\/pre>\n\n\n\n<p>The code is given which declares the design of the puzzle window, on its size of tiles, color, border, margins, and background color.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Main Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def main():\n    global FPSCLOCK, DISPLAYSURF, BASICFONT, RESET_SURF, RESET_RECT, NEW_SURF, NEW_RECT, SOLVE_SURF, SOLVE_RECT\n\n    pygame.init()\n    FPSCLOCK = pygame.time.Clock()\n    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))\n    pygame.display.set_caption('Slide Puzzle')\n    BASICFONT = pygame.font.Font('freesansbold.ttf', BASICFONTSIZE)\n\n    # Store the option buttons and their rectangles in OPTIONS.\n    RESET_SURF, RESET_RECT = makeText('Reset',    TEXT, BGCOLOR, WINDOWWIDTH - 120, WINDOWHEIGHT - 310)\n    NEW_SURF,   NEW_RECT   = makeText('New Game', TEXT, BGCOLOR, WINDOWWIDTH - 120, WINDOWHEIGHT - 280)\n    SOLVE_SURF, SOLVE_RECT = makeText('Solve',    TEXT, BGCOLOR, WINDOWWIDTH - 120, WINDOWHEIGHT - 250)\n\n    mainBoard, solutionSeq = generateNewPuzzle(80)\n    SOLVEDBOARD = getStartingBoard() # a solved board is the same as the board in a start state.\n    allMoves = &#91;] # list of moves made from the solved configuration\n\n    while True: # main game loop\n        slideTo = None # the direction, if any, a tile should slide\n        msg = 'Click tile or press arrow keys to slide.' # contains the message to show in the upper left corner.\n        if mainBoard == SOLVEDBOARD:\n            msg = 'Solved!'\n\n        drawBoard(mainBoard, msg)\n\n        checkForQuit()\n        for event in pygame.event.get(): # event handling loop\n            if event.type == MOUSEBUTTONUP:\n                spotx, spoty = getSpotClicked(mainBoard, event.pos&#91;0], event.pos&#91;1])\n\n                if (spotx, spoty) == (None, None):\n                    # check if the user clicked on an option button\n                    if RESET_RECT.collidepoint(event.pos):\n                        resetAnimation(mainBoard, allMoves) # clicked on Reset button\n                        allMoves = &#91;]\n                    elif NEW_RECT.collidepoint(event.pos):\n                        mainBoard, solutionSeq = generateNewPuzzle(80) # clicked on New Game button\n                        allMoves = &#91;]\n                    elif SOLVE_RECT.collidepoint(event.pos):\n                        resetAnimation(mainBoard, solutionSeq + allMoves) # clicked on Solve button\n                        allMoves = &#91;]\n                else:\n                    # check if the clicked tile was next to the blank spot\n\n                    blankx, blanky = getBlankPosition(mainBoard)\n                    if spotx == blankx + 1 and spoty == blanky:\n                        slideTo = LEFT\n                    elif spotx == blankx - 1 and spoty == blanky:\n                        slideTo = RIGHT\n                    elif spotx == blankx and spoty == blanky + 1:\n                        slideTo = UP\n                    elif spotx == blankx and spoty == blanky - 1:\n                        slideTo = DOWN\n\n            elif event.type == KEYUP:\n                # check if the user pressed a key to slide a tile\n                if event.key in (K_LEFT, K_a) and isValidMove(mainBoard, LEFT):\n                    slideTo = LEFT\n                elif event.key in (K_RIGHT, K_d) and isValidMove(mainBoard, RIGHT):\n                    slideTo = RIGHT\n                elif event.key in (K_UP, K_w) and isValidMove(mainBoard, UP):\n                    slideTo = UP\n                elif event.key in (K_DOWN, K_s) and isValidMove(mainBoard, DOWN):\n                    slideTo = DOWN\n\n        if slideTo:\n            slideAnimation(mainBoard, slideTo, 'Click tile or press arrow keys to slide.', 8) # show slide on screen\n            makeMove(mainBoard, slideTo)\n            allMoves.append(slideTo) # record the slide\n        pygame.display.update()\n        FPSCLOCK.tick(FPS)<\/code><\/pre>\n\n\n\n<p>This module is the main module of the puzzle game.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is The Module Exit<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def terminate():\n    pygame.quit()\n    sys.exit()<\/code><\/pre>\n\n\n\n<p>In this module which is the exit module of the puzzle game.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Making Move Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def makeMove(board, move):\n    # This function does not check if the move is valid.\n    blankx, blanky = getBlankPosition(board)\n\n    if move == UP:\n        board&#91;blankx]&#91;blanky], board&#91;blankx]&#91;blanky + 1] = board&#91;blankx]&#91;blanky + 1], board&#91;blankx]&#91;blanky]\n    elif move == DOWN:\n        board&#91;blankx]&#91;blanky], board&#91;blankx]&#91;blanky - 1] = board&#91;blankx]&#91;blanky - 1], board&#91;blankx]&#91;blanky]\n    elif move == LEFT:\n        board&#91;blankx]&#91;blanky], board&#91;blankx + 1]&#91;blanky] = board&#91;blankx + 1]&#91;blanky], board&#91;blankx]&#91;blanky]\n    elif move == RIGHT:\n        board&#91;blankx]&#91;blanky], board&#91;blankx - 1]&#91;blanky] = board&#91;blankx - 1]&#91;blanky], board&#91;blankx]&#91;blanky]<\/code><\/pre>\n\n\n\n<p>In this module which is the condition when a player makes a move.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Random Move Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def getRandomMove(board, lastMove=None):\n    # start with a full list of all four moves\n    validMoves = &#91;UP, DOWN, LEFT, RIGHT]\n\n    # remove moves from the list as they are disqualified\n    if lastMove == UP or not isValidMove(board, DOWN):\n        validMoves.remove(DOWN)\n    if lastMove == DOWN or not isValidMove(board, UP):\n        validMoves.remove(UP)\n    if lastMove == LEFT or not isValidMove(board, RIGHT):\n        validMoves.remove(RIGHT)\n    if lastMove == RIGHT or not isValidMove(board, LEFT):\n        validMoves.remove(LEFT)\n\n    # return a random move from the list of remaining moves\n    return random.choice(validMoves)<\/code><\/pre>\n\n\n\n<p>In this module which is getting the random move.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Generate New Puzzle Module<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def generateNewPuzzle(numSlides):\n    # From a starting configuration, make numSlides number of moves (and\n    # animate these moves).\n    sequence = &#91;]\n    board = getStartingBoard()\n    drawBoard(board, '')\n    pygame.display.update()\n    pygame.time.wait(500) # pause 500 milliseconds for effect\n    lastMove = None\n    for i in range(numSlides):\n        move = getRandomMove(board, lastMove)\n        slideAnimation(board, move, 'Generating new puzzle...', animationSpeed=int(TILESIZE \/ 3))\n        makeMove(board, move)\n        sequence.append(move)\n        lastMove = move\n    return (board, sequence)<\/code><\/pre>\n\n\n\n<p>In this module which is generating new puzzles.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Complete Source Code<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame, sys, random\nfrom pygame.locals import *\n\n# Create the constants (go ahead and experiment with different values)\nBOARDWIDTH = 4  # number of columns in the board\nBOARDHEIGHT = 4 # number of rows in the board\nTILESIZE = 80\nWINDOWWIDTH = 640\nWINDOWHEIGHT = 480\nFPS = 30\nBLANK = None\n\n#                 R    G    B\nBLACK =         (  0,   0,   0)\nWHITE =         (255, 255, 255)\nBRIGHTBLUE =    (  0,  50, 255)\nDARKTURQUOISE = (  3,  54,  73)\nBLUE =         (  0,  50, 255)\nGREEN =        (  0, 128,   0)\nRED =           (255, 0, 0)\nBGCOLOR = DARKTURQUOISE\nTILECOLOR = BLUE\nTEXTCOLOR = WHITE\nBORDERCOLOR = RED\nBASICFONTSIZE = 20\nTEXT = GREEN\n\nBUTTONCOLOR = WHITE\nBUTTONTEXTCOLOR = BLACK\nMESSAGECOLOR = WHITE\n\nXMARGIN = int((WINDOWWIDTH - (TILESIZE * BOARDWIDTH + (BOARDWIDTH - 1))) \/ 2)\nYMARGIN = int((WINDOWHEIGHT - (TILESIZE * BOARDHEIGHT + (BOARDHEIGHT - 1))) \/ 2)\n\nUP = 'up'\nDOWN = 'down'\nLEFT = 'left'\nRIGHT = 'right'\n\ndef main():\n    global FPSCLOCK, DISPLAYSURF, BASICFONT, RESET_SURF, RESET_RECT, NEW_SURF, NEW_RECT, SOLVE_SURF, SOLVE_RECT\n\n    pygame.init()\n    FPSCLOCK = pygame.time.Clock()\n    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))\n    pygame.display.set_caption('Slide Puzzle')\n    BASICFONT = pygame.font.Font('freesansbold.ttf', BASICFONTSIZE)\n\n    # Store the option buttons and their rectangles in OPTIONS.\n    RESET_SURF, RESET_RECT = makeText('Reset',    TEXT, BGCOLOR, WINDOWWIDTH - 120, WINDOWHEIGHT - 310)\n    NEW_SURF,   NEW_RECT   = makeText('New Game', TEXT, BGCOLOR, WINDOWWIDTH - 120, WINDOWHEIGHT - 280)\n    SOLVE_SURF, SOLVE_RECT = makeText('Solve',    TEXT, BGCOLOR, WINDOWWIDTH - 120, WINDOWHEIGHT - 250)\n\n    mainBoard, solutionSeq = generateNewPuzzle(80)\n    SOLVEDBOARD = getStartingBoard() # a solved board is the same as the board in a start state.\n    allMoves = &#91;] # list of moves made from the solved configuration\n\n    while True: # main game loop\n        slideTo = None # the direction, if any, a tile should slide\n        msg = 'Click tile or press arrow keys to slide.' # contains the message to show in the upper left corner.\n        if mainBoard == SOLVEDBOARD:\n            msg = 'Solved!'\n\n        drawBoard(mainBoard, msg)\n\n        checkForQuit()\n        for event in pygame.event.get(): # event handling loop\n            if event.type == MOUSEBUTTONUP:\n                spotx, spoty = getSpotClicked(mainBoard, event.pos&#91;0], event.pos&#91;1])\n\n                if (spotx, spoty) == (None, None):\n                    # check if the user clicked on an option button\n                    if RESET_RECT.collidepoint(event.pos):\n                        resetAnimation(mainBoard, allMoves) # clicked on Reset button\n                        allMoves = &#91;]\n                    elif NEW_RECT.collidepoint(event.pos):\n                        mainBoard, solutionSeq = generateNewPuzzle(80) # clicked on New Game button\n                        allMoves = &#91;]\n                    elif SOLVE_RECT.collidepoint(event.pos):\n                        resetAnimation(mainBoard, solutionSeq + allMoves) # clicked on Solve button\n                        allMoves = &#91;]\n                else:\n                    # check if the clicked tile was next to the blank spot\n\n                    blankx, blanky = getBlankPosition(mainBoard)\n                    if spotx == blankx + 1 and spoty == blanky:\n                        slideTo = LEFT\n                    elif spotx == blankx - 1 and spoty == blanky:\n                        slideTo = RIGHT\n                    elif spotx == blankx and spoty == blanky + 1:\n                        slideTo = UP\n                    elif spotx == blankx and spoty == blanky - 1:\n                        slideTo = DOWN\n\n            elif event.type == KEYUP:\n                # check if the user pressed a key to slide a tile\n                if event.key in (K_LEFT, K_a) and isValidMove(mainBoard, LEFT):\n                    slideTo = LEFT\n                elif event.key in (K_RIGHT, K_d) and isValidMove(mainBoard, RIGHT):\n                    slideTo = RIGHT\n                elif event.key in (K_UP, K_w) and isValidMove(mainBoard, UP):\n                    slideTo = UP\n                elif event.key in (K_DOWN, K_s) and isValidMove(mainBoard, DOWN):\n                    slideTo = DOWN\n\n        if slideTo:\n            slideAnimation(mainBoard, slideTo, 'Click tile or press arrow keys to slide.', 8) # show slide on screen\n            makeMove(mainBoard, slideTo)\n            allMoves.append(slideTo) # record the slide\n        pygame.display.update()\n        FPSCLOCK.tick(FPS)\n\n\ndef terminate():\n    pygame.quit()\n    sys.exit()\n\n\ndef checkForQuit():\n    for event in pygame.event.get(QUIT): # get all the QUIT events\n        terminate() # terminate if any QUIT events are present\n    for event in pygame.event.get(KEYUP): # get all the KEYUP events\n        if event.key == K_ESCAPE:\n            terminate() # terminate if the KEYUP event was for the Esc key\n        pygame.event.post(event) # put the other KEYUP event objects back\n\n\ndef getStartingBoard():\n    # Return a board data structure with tiles in the solved state.\n    # For example, if BOARDWIDTH and BOARDHEIGHT are both 3, this function\n    # returns &#91;&#91;1, 4, 7], &#91;2, 5, 8], &#91;3, 6, BLANK]]\n    counter = 1\n    board = &#91;]\n    for x in range(BOARDWIDTH):\n        column = &#91;]\n        for y in range(BOARDHEIGHT):\n            column.append(counter)\n            counter += BOARDWIDTH\n        board.append(column)\n        counter -= BOARDWIDTH * (BOARDHEIGHT - 1) + BOARDWIDTH - 1\n\n    board&#91;BOARDWIDTH-1]&#91;BOARDHEIGHT-1] = BLANK\n    return board\n\n\ndef getBlankPosition(board):\n    # Return the x and y of board coordinates of the blank space.\n    for x in range(BOARDWIDTH):\n        for y in range(BOARDHEIGHT):\n            if board&#91;x]&#91;y] == BLANK:\n                return (x, y)\n\n\ndef makeMove(board, move):\n    # This function does not check if the move is valid.\n    blankx, blanky = getBlankPosition(board)\n\n    if move == UP:\n        board&#91;blankx]&#91;blanky], board&#91;blankx]&#91;blanky + 1] = board&#91;blankx]&#91;blanky + 1], board&#91;blankx]&#91;blanky]\n    elif move == DOWN:\n        board&#91;blankx]&#91;blanky], board&#91;blankx]&#91;blanky - 1] = board&#91;blankx]&#91;blanky - 1], board&#91;blankx]&#91;blanky]\n    elif move == LEFT:\n        board&#91;blankx]&#91;blanky], board&#91;blankx + 1]&#91;blanky] = board&#91;blankx + 1]&#91;blanky], board&#91;blankx]&#91;blanky]\n    elif move == RIGHT:\n        board&#91;blankx]&#91;blanky], board&#91;blankx - 1]&#91;blanky] = board&#91;blankx - 1]&#91;blanky], board&#91;blankx]&#91;blanky]\n\n\ndef isValidMove(board, move):\n    blankx, blanky = getBlankPosition(board)\n    return (move == UP and blanky != len(board&#91;0]) - 1) or \\\n           (move == DOWN and blanky != 0) or \\\n           (move == LEFT and blankx != len(board) - 1) or \\\n           (move == RIGHT and blankx != 0)\n\n\ndef getRandomMove(board, lastMove=None):\n    # start with a full list of all four moves\n    validMoves = &#91;UP, DOWN, LEFT, RIGHT]\n\n    # remove moves from the list as they are disqualified\n    if lastMove == UP or not isValidMove(board, DOWN):\n        validMoves.remove(DOWN)\n    if lastMove == DOWN or not isValidMove(board, UP):\n        validMoves.remove(UP)\n    if lastMove == LEFT or not isValidMove(board, RIGHT):\n        validMoves.remove(RIGHT)\n    if lastMove == RIGHT or not isValidMove(board, LEFT):\n        validMoves.remove(LEFT)\n\n    # return a random move from the list of remaining moves\n    return random.choice(validMoves)\n\n\ndef getLeftTopOfTile(tileX, tileY):\n    left = XMARGIN + (tileX * TILESIZE) + (tileX - 1)\n    top = YMARGIN + (tileY * TILESIZE) + (tileY - 1)\n    return (left, top)\n\n\ndef getSpotClicked(board, x, y):\n    # from the x &amp; y pixel coordinates, get the x &amp; y board coordinates\n    for tileX in range(len(board)):\n        for tileY in range(len(board&#91;0])):\n            left, top = getLeftTopOfTile(tileX, tileY)\n            tileRect = pygame.Rect(left, top, TILESIZE, TILESIZE)\n            if tileRect.collidepoint(x, y):\n                return (tileX, tileY)\n    return (None, None)\n\n\ndef drawTile(tilex, tiley, number, adjx=0, adjy=0):\n    # draw a tile at board coordinates tilex and tiley, optionally a few\n    # pixels over (determined by adjx and adjy)\n    left, top = getLeftTopOfTile(tilex, tiley)\n    pygame.draw.rect(DISPLAYSURF, TILECOLOR, (left + adjx, top + adjy, TILESIZE, TILESIZE))\n    textSurf = BASICFONT.render(str(number), True, TEXTCOLOR)\n    textRect = textSurf.get_rect()\n    textRect.center = left + int(TILESIZE \/ 2) + adjx, top + int(TILESIZE \/ 2) + adjy\n    DISPLAYSURF.blit(textSurf, textRect)\n\n\ndef makeText(text, color, bgcolor, top, left):\n    # create the Surface and Rect objects for some text.\n    textSurf = BASICFONT.render(text, True, color, bgcolor)\n    textRect = textSurf.get_rect()\n    textRect.topleft = (top, left)\n    return (textSurf, textRect)\n\n\ndef drawBoard(board, message):\n    DISPLAYSURF.fill(BGCOLOR)\n    if message:\n        textSurf, textRect = makeText(message, MESSAGECOLOR, BGCOLOR, 5, 5)\n        DISPLAYSURF.blit(textSurf, textRect)\n\n    for tilex in range(len(board)):\n        for tiley in range(len(board&#91;0])):\n            if board&#91;tilex]&#91;tiley]:\n                drawTile(tilex, tiley, board&#91;tilex]&#91;tiley])\n\n    left, top = getLeftTopOfTile(0, 0)\n    width = BOARDWIDTH * TILESIZE\n    height = BOARDHEIGHT * TILESIZE\n    pygame.draw.rect(DISPLAYSURF, BORDERCOLOR, (left - 5, top - 5, width + 11, height + 11), 4)\n\n    DISPLAYSURF.blit(RESET_SURF, RESET_RECT)\n    DISPLAYSURF.blit(NEW_SURF, NEW_RECT)\n    DISPLAYSURF.blit(SOLVE_SURF, SOLVE_RECT)\n\n\ndef slideAnimation(board, direction, message, animationSpeed):\n    # Note: This function does not check if the move is valid.\n\n    blankx, blanky = getBlankPosition(board)\n    if direction == UP:\n        movex = blankx\n        movey = blanky + 1\n    elif direction == DOWN:\n        movex = blankx\n        movey = blanky - 1\n    elif direction == LEFT:\n        movex = blankx + 1\n        movey = blanky\n    elif direction == RIGHT:\n        movex = blankx - 1\n        movey = blanky\n\n    # prepare the base surface\n    drawBoard(board, message)\n    baseSurf = DISPLAYSURF.copy()\n    # draw a blank space over the moving tile on the baseSurf Surface.\n    moveLeft, moveTop = getLeftTopOfTile(movex, movey)\n    pygame.draw.rect(baseSurf, BGCOLOR, (moveLeft, moveTop, TILESIZE, TILESIZE))\n\n    for i in range(0, TILESIZE, animationSpeed):\n        # animate the tile sliding over\n        checkForQuit()\n        DISPLAYSURF.blit(baseSurf, (0, 0))\n        if direction == UP:\n            drawTile(movex, movey, board&#91;movex]&#91;movey], 0, -i)\n        if direction == DOWN:\n            drawTile(movex, movey, board&#91;movex]&#91;movey], 0, i)\n        if direction == LEFT:\n            drawTile(movex, movey, board&#91;movex]&#91;movey], -i, 0)\n        if direction == RIGHT:\n            drawTile(movex, movey, board&#91;movex]&#91;movey], i, 0)\n\n        pygame.display.update()\n        FPSCLOCK.tick(FPS)\n\n\ndef generateNewPuzzle(numSlides):\n    # From a starting configuration, make numSlides number of moves (and\n    # animate these moves).\n    sequence = &#91;]\n    board = getStartingBoard()\n    drawBoard(board, '')\n    pygame.display.update()\n    pygame.time.wait(500) # pause 500 milliseconds for effect\n    lastMove = None\n    for i in range(numSlides):\n        move = getRandomMove(board, lastMove)\n        slideAnimation(board, move, 'Generating new puzzle...', animationSpeed=int(TILESIZE \/ 3))\n        makeMove(board, move)\n        sequence.append(move)\n        lastMove = move\n    return (board, sequence)\n\n\ndef resetAnimation(board, allMoves):\n    # make all of the moves in allMoves in reverse.\n    revAllMoves = allMoves&#91;:] # gets a copy of the list\n    revAllMoves.reverse()\n\n    for move in revAllMoves:\n        if move == UP:\n            oppositeMove = DOWN\n        elif move == DOWN:\n            oppositeMove = UP\n        elif move == RIGHT:\n            oppositeMove = LEFT\n        elif move == LEFT:\n            oppositeMove = RIGHT\n        slideAnimation(board, oppositeMove, '', animationSpeed=int(TILESIZE \/ 2))\n        makeMove(board, oppositeMove)\n\n\nif __name__ == '__main__':\n    main()<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Output<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"511\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-Output.png\" alt=\"\" class=\"wp-image-22745\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-Output.png 642w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-Output-300x239.png 300w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-Output-528x420.png 528w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-puzzle-game-in-python-project-information\"><strong>Puzzle Game In Python<\/strong>: Project Information<\/h2>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Project Name:<\/strong><\/td><td>Puzzle Game In Python<\/td><\/tr><tr><td><strong>Language\/s Used:<\/strong><\/td><td>Python (GUI) Based<\/td><\/tr><tr><td><strong>Python version (Recommended):<\/strong><\/td><td>2.x or 3.x<\/td><\/tr><tr><td><strong>Database:<\/strong><\/td><td>None<\/td><\/tr><tr><td><strong>Type:<\/strong><\/td><td>Python App<\/td><\/tr><tr><td><strong>Developer:<\/strong><\/td><td>IT SOURCECODE<\/td><\/tr><tr><td><strong>Updates:<\/strong><\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Downloadable Source Code<\/strong><\/h2>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-Source-Code.zip\">DOWNLOAD<\/a><\/div>\n<\/div>\n\n\n\n<p>I have here the list of&nbsp;<a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/best-python-project-with-source-code-2020\/\">Best Python Projects with Source code free to download for free<\/a>, I hope this can help you a lot.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary<\/strong><\/h2>\n\n\n\n<p>The <strong>Puzzle Game In Python<\/strong> is written in Python programming language, Python is very easy to research the syntax emphasizes readability and it is able to reduce time ingesting in developing.<\/p>\n\n\n\n<p>Also, this tutorial is the simplest way for beginners or students to enhance their logical skills in programming. Also, this game project is a way for students or beginners to design and develop games.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-e2102932-3919-4751-8ae9-e2e013e9a506\"><strong>Related Articles<\/strong><\/h2>\n\n\n\n<ul id=\"block-88f08f8a-129d-4b30-927c-64214788c140\" class=\"wp-block-list\">\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/tank-game-python-with-source-code\/\">Tank Game Python with Source Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/tetris-in-python-code\/\">Tetris In Python Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/mario-game-in-python-with-source-code\/\">Mario Game In Python With Source Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/hangman-game-in-python-with-source-code\/\">Hangman Game In Python With Source Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/aircraft-war-game-in-python-with-source-code\/\">Aircraft War Game in Python with Source Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/snake-game-in-python-code\/\">Snake Game In Python Code<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-0863d1d8-f13d-4559-af50-69cbc78f862a\"><strong>Inquiries<\/strong><\/h2>\n\n\n\n<p id=\"block-da714d96-2ee9-4dd6-bfb6-24791bd6ca8f\">If you have any questions or suggestions about <strong>Puzzle Game In Python<\/strong>, please feel free to leave a comment below.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Puzzle Game In Python is written in the Python programming language, Puzzle Game Code In Python, there is a 4*4 board with 15 numbers. The numbers are then shuffled &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Puzzle Game In Python With Source Code\" class=\"read-more button\" href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#more-22723\" aria-label=\"Read more about Puzzle Game In Python With Source Code\">Read more<\/a><\/p>\n","protected":false},"author":1767,"featured_media":119158,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19632,60567],"tags":[36552,36550,36548,36549,36553,21761,36554,21762,36551],"class_list":["post-22723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-projects","category-pygame","tag-bfs-code-for-8-puzzle-game-in-python","tag-memory-puzzle-game-in-python","tag-puzzle-game-code-in-python","tag-puzzle-game-in-python","tag-puzzle-game-python-code","tag-python-projects-with-source-code","tag-python-puzzle-game","tag-python-source-code","tag-source-code-for-puzzle-game-in-python","resize-featured-image"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Puzzle Game In Python With Source Code<\/title>\n<meta name=\"description\" content=\"This Puzzle Game In Python has steps to be follow, first is to move the number tiles into the empty tile space, it also includes a sourc\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Puzzle Game In Python With Source Code\" \/>\n<meta property=\"og:description\" content=\"This Puzzle Game In Python has steps to be follow, first is to move the number tiles into the empty tile space, it also includes a sourc\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Itsourcecode.com\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-14T08:36:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-07T08:19:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-with-source-code.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"angel jude suarez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"angel jude suarez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/\"},\"author\":{\"name\":\"angel jude suarez\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/dafb6a91b43e60537c56e3e1d227d460\"},\"headline\":\"Puzzle Game In Python With Source Code\",\"datePublished\":\"2020-08-14T08:36:03+00:00\",\"dateModified\":\"2025-04-07T08:19:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/\"},\"wordCount\":677,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-with-source-code.png\",\"keywords\":[\"bfs code for 8 puzzle game in python\",\"memory puzzle game in python\",\"puzzle game code in python\",\"puzzle game in python\",\"puzzle game python code\",\"python projects with source code\",\"python puzzle game\",\"python source code\",\"source code for puzzle game in python\"],\"articleSection\":[\"Best Python Projects With Source Code\",\"Pygame Projects\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/\",\"name\":\"Puzzle Game In Python With Source Code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-with-source-code.png\",\"datePublished\":\"2020-08-14T08:36:03+00:00\",\"dateModified\":\"2025-04-07T08:19:46+00:00\",\"description\":\"This Puzzle Game In Python has steps to be follow, first is to move the number tiles into the empty tile space, it also includes a sourc\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#primaryimage\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-with-source-code.png\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-with-source-code.png\",\"width\":1200,\"height\":675,\"caption\":\"Puzzle Game In Python with source code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/itsourcecode.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Puzzle Game In Python With Source Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/\",\"name\":\"Itsourcecode.com\",\"description\":\"Partner In Your Coding Journey!\",\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/itsourcecode.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\",\"name\":\"itsourcecode\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"width\":409,\"height\":409,\"caption\":\"itsourcecode\"},\"logo\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\"},\"description\":\"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!\",\"sameAs\":[\"https:\\\/\\\/itsourcecode.com\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/dafb6a91b43e60537c56e3e1d227d460\",\"name\":\"angel jude suarez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"caption\":\"angel jude suarez\"},\"description\":\"Hello programmers, I'm Angel Jude Reyes Suarez, a student and a programmer of different programming languages like Python, Java, JavaScript, PHP, C, C++, Vb.net, and MySQL. and I have also knowledge in developing system or websites from Front-End to Back-End. and also a writer of itsourcecode.com.\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/author\\\/angeljudesuarez\\\/\"},{\"@type\":\"HowTo\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#howto-1\",\"name\":\"Puzzle Game In Python With Source Code\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#article\"},\"description\":\"<strong>Puzzle Game In Python<\\\/strong> <strong>With Source Code<\\\/strong>\",\"step\":[{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#how-to-step-1597382213945\",\"name\":\"Step 1: Create a project name.\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"First, open\u00a0Pycharm IDE\u00a0and then create a \\\"project name\\\" after creating a project name click the \\\"create\\\" button.\"}],\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#schema-image-49dc44571d2c0f9536b0423109dfe1e2\",\"url\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-Project-Name-1.png\",\"contentUrl\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-Project-Name-1.png\"}},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#how-to-step-1597382272396\",\"name\":\"Step 2: Create a python file.\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"Second, after creating a project name, \\\"right click\\\" your project name and then click \\\"new\\\" after that click the \\\"python file\\\".\"}],\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#schema-image-97ab262c5097c779ae5e3a90b8df9497\",\"url\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-File.png\",\"contentUrl\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-File.png\"}},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#how-to-step-1597382289077\",\"name\":\"Step 3: Name your python file.\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"Third, after creating a Python file, Name your Python file after that click \\\"enter\u201c.\"}],\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#schema-image-4795436e106e6567b9f873551da532a4\",\"url\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-File-Name.png\",\"contentUrl\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Puzzle-Game-In-Python-File-Name.png\"}},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/puzzle-game-in-python-with-source-code\\\/#how-to-step-1597382314773\",\"name\":\"Step 4: The actual code.\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"You are free to copy the code given below and download the full source code below.\"}]}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Puzzle Game In Python With Source Code","description":"This Puzzle Game In Python has steps to be follow, first is to move the number tiles into the empty tile space, it also includes a sourc","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/","og_locale":"en_US","og_type":"article","og_title":"Puzzle Game In Python With Source Code","og_description":"This Puzzle Game In Python has steps to be follow, first is to move the number tiles into the empty tile space, it also includes a sourc","og_url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/","og_site_name":"Itsourcecode.com","article_published_time":"2020-08-14T08:36:03+00:00","article_modified_time":"2025-04-07T08:19:46+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-with-source-code.png","type":"image\/png"}],"author":"angel jude suarez","twitter_card":"summary_large_image","twitter_misc":{"Written by":"angel jude suarez","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#article","isPartOf":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/"},"author":{"name":"angel jude suarez","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/dafb6a91b43e60537c56e3e1d227d460"},"headline":"Puzzle Game In Python With Source Code","datePublished":"2020-08-14T08:36:03+00:00","dateModified":"2025-04-07T08:19:46+00:00","mainEntityOfPage":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/"},"wordCount":677,"commentCount":0,"publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"image":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-with-source-code.png","keywords":["bfs code for 8 puzzle game in python","memory puzzle game in python","puzzle game code in python","puzzle game in python","puzzle game python code","python projects with source code","python puzzle game","python source code","source code for puzzle game in python"],"articleSection":["Best Python Projects With Source Code","Pygame Projects"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/","name":"Puzzle Game In Python With Source Code","isPartOf":{"@id":"https:\/\/itsourcecode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#primaryimage"},"image":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-with-source-code.png","datePublished":"2020-08-14T08:36:03+00:00","dateModified":"2025-04-07T08:19:46+00:00","description":"This Puzzle Game In Python has steps to be follow, first is to move the number tiles into the empty tile space, it also includes a sourc","breadcrumb":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#primaryimage","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-with-source-code.png","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-with-source-code.png","width":1200,"height":675,"caption":"Puzzle Game In Python with source code"},{"@type":"BreadcrumbList","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/itsourcecode.com\/"},{"@type":"ListItem","position":2,"name":"Puzzle Game In Python With Source Code"}]},{"@type":"WebSite","@id":"https:\/\/itsourcecode.com\/#website","url":"https:\/\/itsourcecode.com\/","name":"Itsourcecode.com","description":"Partner In Your Coding Journey!","publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itsourcecode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc","name":"itsourcecode","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","width":409,"height":409,"caption":"itsourcecode"},"logo":{"@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg"},"description":"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!","sameAs":["https:\/\/itsourcecode.com\/"]},{"@type":"Person","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/dafb6a91b43e60537c56e3e1d227d460","name":"angel jude suarez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","url":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","caption":"angel jude suarez"},"description":"Hello programmers, I'm Angel Jude Reyes Suarez, a student and a programmer of different programming languages like Python, Java, JavaScript, PHP, C, C++, Vb.net, and MySQL. and I have also knowledge in developing system or websites from Front-End to Back-End. and also a writer of itsourcecode.com.","url":"https:\/\/itsourcecode.com\/author\/angeljudesuarez\/"},{"@type":"HowTo","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#howto-1","name":"Puzzle Game In Python With Source Code","mainEntityOfPage":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#article"},"description":"<strong>Puzzle Game In Python<\/strong> <strong>With Source Code<\/strong>","step":[{"@type":"HowToStep","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#how-to-step-1597382213945","name":"Step 1: Create a project name.","itemListElement":[{"@type":"HowToDirection","text":"First, open\u00a0Pycharm IDE\u00a0and then create a \"project name\" after creating a project name click the \"create\" button."}],"image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#schema-image-49dc44571d2c0f9536b0423109dfe1e2","url":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-Project-Name-1.png","contentUrl":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-Project-Name-1.png"}},{"@type":"HowToStep","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#how-to-step-1597382272396","name":"Step 2: Create a python file.","itemListElement":[{"@type":"HowToDirection","text":"Second, after creating a project name, \"right click\" your project name and then click \"new\" after that click the \"python file\"."}],"image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#schema-image-97ab262c5097c779ae5e3a90b8df9497","url":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-File.png","contentUrl":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-File.png"}},{"@type":"HowToStep","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#how-to-step-1597382289077","name":"Step 3: Name your python file.","itemListElement":[{"@type":"HowToDirection","text":"Third, after creating a Python file, Name your Python file after that click \"enter\u201c."}],"image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#schema-image-4795436e106e6567b9f873551da532a4","url":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-File-Name.png","contentUrl":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Puzzle-Game-In-Python-File-Name.png"}},{"@type":"HowToStep","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/puzzle-game-in-python-with-source-code\/#how-to-step-1597382314773","name":"Step 4: The actual code.","itemListElement":[{"@type":"HowToDirection","text":"You are free to copy the code given below and download the full source code below."}]}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/22723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/users\/1767"}],"replies":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/comments?post=22723"}],"version-history":[{"count":13,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/22723\/revisions"}],"predecessor-version":[{"id":127643,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/22723\/revisions\/127643"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media\/119158"}],"wp:attachment":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media?parent=22723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/categories?post=22723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/tags?post=22723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}