{"id":80144,"date":"2020-11-26T09:30:17","date_gmt":"2020-11-26T04:00:17","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=80144"},"modified":"2026-06-03T15:54:01","modified_gmt":"2026-06-03T10:24:01","slug":"sliding-tile-puzzle-in-python","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/","title":{"rendered":"Sliding Tile Puzzle in Python"},"content":{"rendered":"<p>Sliding tiles game also known as sliding puzzle or sliding blocks game. In this game, the player has to arrange the tiles or blocks in the correct order.<\/p>\n<h3>About Sliding Tiles Puzzle Python Project<\/h3>\n<p>The objective of this project is to create a sliding tile game of multiple levels. In this game, the player has to select level which he\/she wants to play. Now, he can start playing the game by clicking on the tile which they want to move.<\/p>\n<h3>Project Prerequisites<\/h3>\n<p>This sliding tile game python project is build using pygame, random, sys, os module, and with concepts of python.<\/p>\n<ul>\n<li><strong>Pygame<\/strong> module is used to build gaming or multimedia type application<\/li>\n<li><strong>Random<\/strong> module is used to generate numbers randomly<\/li>\n<\/ul>\n<h3>Download Code of Sliding Tile Game Python Project<\/h3>\n<p>Please download the source code of sliding tile puzzle: <a href=\"https:\/\/drive.google.com\/file\/d\/1MMWAkyoowDaN8K686NZmDYCVQDwMr66r\/view?usp=drive_link\"><strong>Sliding Tile in Python<\/strong><\/a><\/p>\n<h3>Project File Structure<\/h3>\n<p>To build this project we follow the below steps:<\/p>\n<ul>\n<li>Importing required modules<\/li>\n<li>Initializing and creating game window<\/li>\n<li>Creating class for main concept of game<\/li>\n<li>Defining function<\/li>\n<li>Creating levels<\/li>\n<li>Mainloop<\/li>\n<\/ul>\n<p>Lets start building sliding tiles game<\/p>\n<h4>1. Importing required modules<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import pygame\r\nimport sys, os, random\r\n<\/pre>\n<p>In this step, we import the required modules.<\/p>\n<h4>2. Initializing window<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#initializing window\r\nWIDTH = 800\r\nHEIGHT = 600\r\nFPS = 12\r\n\r\npygame.init()\r\npygame.display.set_caption('sliding tiles- TechVivdan')\r\ngameDisplay = pygame.display.set_mode((WIDTH, HEIGHT))\r\nclock = pygame.time.Clock()\r\n\r\n# Define colors\r\nWHITE = (255,255,255)\r\nBLACK = (0,0,0)\r\nRED = (255,0,0)\r\nbrown = (100,40,0)\r\n\r\n\r\nbackground = pygame.image.load('white.jpg')\r\nbackground = pygame.transform.scale(background, (800, 600))\r\n\r\nfont = pygame.font.Font(os.path.join(os.getcwd(), 'comic.ttf'), 70)\r\n<\/pre>\n<ul>\n<li><strong>pygame.init()<\/strong> used to initialize pygame<\/li>\n<li><strong>pygame.display.set_caption<\/strong> used to set the caption of the game window<\/li>\n<li><strong>FPS<\/strong> used to controls how the gameDisplay should refresh.<\/li>\n<li><strong>WIDTH<\/strong> and <strong>HEIGHT<\/strong> store the width and height of the game window<\/li>\n<li>The width and height of the window are set by using pygame.display.set_mode<\/li>\n<li><strong>pygame.image.load<\/strong> is used to set image<\/li>\n<li><strong>pygame.transform.scale<\/strong> is used to scale image according to the requirement<\/li>\n<\/ul>\n<h4>3. Creating the main concept behind the game<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Generate_Puzzle:                     \r\n    def __init__(self, gridsize, tilesize, margin):  \r\n        \r\n        self.gridsize,self.tilesize,self.margin = gridsize, tilesize, margin\r\n\r\n        self.tiles_no = gridsize[0]*gridsize[1]-1          # no of tiles\r\n        self.tiles = [(x,y) for y in range(gridsize[1]) for x in range(gridsize[0])]  #coordinate of tiles\r\n       \r\n\r\n        self.tilepos = {(x,y):(x*(tilesize+margin)+margin,y*(tilesize+margin)+margin) for y in range(gridsize[1]) for x in range(gridsize[0])}  #tile position\r\n        self.prev = None\r\n\r\n        self.tile_images =[]\r\n        font = pygame.font.Font(None, 80)           \r\n\r\n        for i in range(self.tiles_no):\r\n            image = pygame.Surface((tilesize,tilesize))    #display tiles \r\n            image.fill(brown)\r\n            text = font.render(str(i+1),2,(255,255,255))  ##text on tiles\r\n            width,height = text.get_size()  #text size\r\n            image.blit(text,((tilesize-width)\/2 , (tilesize-height)\/2))   #####display text in the middle of tile\r\n            self.tile_images += [image]\r\n           \r\n\r\n    def Blank_pos(self):  \r\n        \r\n        return self.tiles[-1]\r\n    \r\n    \r\n\r\n    def set_Blank_pos(self,pos):\r\n\r\n        self.tiles[-1] = pos\r\n    opentile = property(Blank_pos, set_Blank_pos)   #get and set the pos of blank\r\n\r\n\r\n\r\n    def switch_tile(self, tile):\r\n        self.tiles[self.tiles.index(tile)]=self.opentile\r\n        self.opentile = tile\r\n        self.prev= self.opentile\r\n        \r\n\r\n\r\n    def check_in_grid(self, tile):\r\n        return tile[0]&gt;=0 and tile[0]&lt;self.gridsize[0] and tile[1]&gt;=0 and tile[1]&lt;self.gridsize[1]\r\n\r\n\r\n    def close_to(self):              #adjacent tile postion to blank (which tiles can move to blank position)\r\n        x, y = self.opentile\r\n        return (x-1,y),(x+1,y),(x,y-1),(x,y+1)\r\n\r\n    def set_tile_randomly(self):\r\n        adj = self.close_to()\r\n        adj = [pos for pos in adj if self.check_in_grid(pos)and pos!= self.prev ]\r\n        tile = random.choice(adj)\r\n        self.switch_tile(tile)\r\n        #print(self.prev)\r\n\r\n\r\n    def update_tile_pos(self,dt):        #update tile position\r\n\r\n        mouse = pygame.mouse.get_pressed()\r\n        mpos = pygame.mouse.get_pos()\r\n\r\n        if mouse[0]:\r\n            x,y = mpos[0]%(self.tilesize+self.margin),mpos[1]%(self.tilesize+self.margin)\r\n            if x&gt;self.margin and y&gt;self.margin:\r\n                tile = mpos[0]\/\/self.tilesize,mpos[1]\/\/self.tilesize\r\n                if self.check_in_grid(tile) and tile in self.close_to():\r\n                    self.switch_tile(tile)\r\n\r\n\r\n    def draw_tile(self,gameDisplay):                             #####draw tiles in particular positioned\r\n        for i in range(self.tiles_no):\r\n            x,y = self.tilepos[self.tiles[i]]\r\n            gameDisplay.blit(self.tile_images[i],(x,y))\r\n                    \r\n\r\n\r\n    def events(self, event):\r\n        if event.type == pygame.KEYDOWN:\r\n            if event.key == pygame.K_SPACE:    #press space to random the tiles\r\n                for i in range(100):\r\n                    self.set_tile_randomly()\r\n\r\n<\/pre>\n<ul>\n<li>tiles_no stores no of tiles.<\/li>\n<li>Function set_Blank_pos() will get and set the blank position.<\/li>\n<li>Switch_tile function will switch the tles.<\/li>\n<li>close_to() function will return the adjacent tiles position to blank position that means will tiles can move in blank pos.<\/li>\n<li>events() functon take events.<\/li>\n<li>If space key pressed then set_tile_randomly() functin will calll in which the tiles will set randomly.<\/li>\n<li>update_tile_pos() function will update the tiles position when it clicked<\/li>\n<\/ul>\n<h4>4. Creating functions to draw fonts<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def makeText(text, color, bgcolor, top, left):\r\n    textSurf = font.render(text, True, color, bgcolor)\r\n    textRect = textSurf.get_rect()\r\n    textRect.topleft = (top, left)\r\n    return (textSurf, textRect)    \r\n\r\n\r\n# Generic method to draw fonts on the screen   \r\nfont_name = pygame.font.match_font('comic.ttf')\r\ndef draw_text(display, text, size, x, y):\r\n    font = pygame.font.Font(font_name, size)\r\n    text_surface = font.render(text, True, brown)\r\n    text_rect = text_surface.get_rect()\r\n    text_rect.midtop = (x, y)\r\n    gameDisplay.blit(text_surface, text_rect)\r\n<\/pre>\n<ul>\n<li><strong>makeText<\/strong> and <strong>draw_text<\/strong> is a function that helps to draw text on the screen in a given font and size.<\/li>\n<li><strong>get_rect()<\/strong> is a method that will return a rect object<\/li>\n<li><strong>x, y<\/strong> is the dimension of x and y-direction<\/li>\n<li><strong>blit()<\/strong> is used to draw an image or text to the screen at a given position<\/li>\n<\/ul>\n<h4>5. Front screen of the game<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def game_front_screen():\r\n    gameDisplay.blit(background, (0,0))\r\n    draw_text(gameDisplay, \"SLIDING TILE GAME!\", 90, WIDTH \/ 2, HEIGHT \/ 4)\r\n    draw_text(gameDisplay, \"Press a key to begin!\", 80, WIDTH \/ 2, HEIGHT * 3 \/ 4)\r\n    pygame.display.flip()\r\n    waiting = True\r\n    while waiting:\r\n        clock.tick(FPS)\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT:\r\n                pygame.quit()\r\n            if event.type == pygame.KEYUP:\r\n                waiting = False                \r\n<\/pre>\n<ul>\n<li><strong>game_front_screen()<\/strong> function show the front game screen of game<\/li>\n<li><strong>pygame.display.flip()<\/strong> will update only a portion of screen but if no argument will pass then it will update entire screen<\/li>\n<li><strong>pygame.event.get()<\/strong> will return all the event stored in the pygame event queue<\/li>\n<li>If the type of the event is equal to quit then the pygame will quit<\/li>\n<li><strong>event.KEYUP<\/strong> is the event that occurs when a keyboard key is pressed and released<\/li>\n<\/ul>\n<h4>6. Creating and defining levels<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def level_screen():\r\n    L1, L1_RECT   = makeText('Level1', RED,True,100 , 40)\r\n    L2, L2_RECT   = makeText('Level2', RED, True,500 , 40)\r\n    L3, L3_RECT   = makeText('Level3', RED, True,100 , 180)\r\n    L4, L4_RECT   = makeText('Level4',  RED,True,500 , 180)\r\n    L5, L5_RECT   = makeText('Level5',RED, True, 100 , 320)\r\n    L6, L6_RECT   = makeText('Level6', RED,True,500 ,  320)\r\n    L7, L7_RECT   = makeText('Level7', RED,True,100 , 460)\r\n    L8, L8_RECT   = makeText('Level8', RED,True,500 , 460\r\n\r\n    gameDisplay.blit(L1, L1_RECT)\r\n         gameDisplay.blit(L2, L2_RECT)\r\n    gameDisplay.blit(L3, L3_RECT)\r\n    gameDisplay.blit(L4, L4_RECT)\r\n    gameDisplay.blit(L5, L5_RECT)\r\n    gameDisplay.blit(L6, L6_RECT)\r\n    gameDisplay.blit(L7, L7_RECT)\r\n    gameDisplay.blit(L8, L8_RECT)\r\n  \r\n    mpos = pygame.mouse.get_pos()\r\n    for event in pygame.event.get():\r\n        if L1_RECT.collidepoint(mpos):\r\n            level1()\r\n        elif L2_RECT.collidepoint(mpos):\r\n            level2()             \r\n        elif L3_RECT.collidepoint(mpos):\r\n            level3()\r\n        elif L4_RECT.collidepoint(mpos):\r\n            level4()\r\n        elif L5_RECT.collidepoint(mpos):\r\n            level5()\r\n         elif L6_RECT.collidepoint(mpos):\r\n            level6()\r\n        elif L7_RECT.collidepoint(mpos):\r\n            level7()\r\n        elif L8_RECT.collidepoint(mpos):\r\n            level8()\r\n\r\ndef level1():\r\n    program=Generate_Puzzle((3,3),80,5)\r\n    while True:\r\n        dt = clock.tick()\/1000\r\n        gameDisplay.blit(background, (0,0))\r\n        draw_text(gameDisplay,'PRESS SPACE TO START GAME', 60,370 , 500)\r\n        program.draw_tile(gameDisplay)\r\n        pygame.display.flip()        \r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT: pygame.quit();sys.exit()\r\n            program.events(event)\r\n        program.update_tile_pos(dt)\r\n\r\n\r\ndef level2():\r\n    program=Generate_Puzzle((3,4),80,5)\r\n    while True:\r\n        dt = clock.tick()\/1000\r\n        gameDisplay.blit(background, (0,0))\r\n        draw_text(gameDisplay,'PRESS SPACE TO START GAME', 60,370 , 500)\r\n        program.draw_tile(gameDisplay)\r\n        pygame.display.flip()        \r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT: pygame.quit();sys.exit()\r\n            program.events(event)\r\n        program.update_tile_pos(dt)\r\n\r\n\r\ndef level3():\r\n    program=Generate_Puzzle((4,3),80,5)\r\n    while True:\r\n        dt = clock.tick()\/1000\r\n        gameDisplay.blit(background, (0,0))\r\n        draw_text(gameDisplay,'PRESS SPACE TO START GAME', 60,370 , 500)\r\n        program.draw_tile(gameDisplay)\r\n        pygame.display.flip()\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT: pygame.quit();sys.exit()\r\n            program.events(event)\r\n        program.update_tile_pos(dt)\r\n\r\n\r\ndef level4():\r\n    program=Generate_Puzzle((4,4),80,5)\r\n    while True:\r\n        dt = clock.tick()\/1000\r\n        gameDisplay.blit(background, (0,0))\r\n        draw_text(gameDisplay,'PRESS SPACE TO START GAME', 60,370 , 500)\r\n        program.draw_tile(gameDisplay)\r\n        pygame.display.flip()\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT: pygame.quit();sys.exit()\r\n            program.events(event)\r\n        program.update_tile_pos(dt)\r\n\r\n\r\ndef level5():\r\n    program=Generate_Puzzle((4,5),80,5)\r\n    while True:\r\n        dt = clock.tick()\/1000\r\n        gameDisplay.blit(background, (0,0))\r\n        draw_text(gameDisplay,'PRESS SPACE TO START GAME', 60,370 , 500)\r\n        program.draw_tile(gameDisplay)\r\n        pygame.display.flip()\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT: pygame.quit();sys.exit()\r\n            program.events(event)\r\n        program.update_tile_pos(dt)\r\n\r\n\r\ndef level6():\r\n    program=Generate_Puzzle((5,5),80,5)\r\n    while True:\r\n        dt = clock.tick()\/1000\r\n        gameDisplay.blit(background, (0,0))\r\n        draw_text(gameDisplay,'PRESS SPACE TO START GAME', 60,370 , 500)\r\n        program.draw_tile(gameDisplay)\r\n        pygame.display.flip()   \r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT:\r\n                pygame.quit();sys.exit()\r\n            program.events(event)\r\n        program.update_tile_pos(dt)\r\n\r\n\r\ndef level7():\r\n    program=Generate_Puzzle((5,4),80,5)\r\n    while True:\r\n        dt = clock.tick()\/1000\r\n        gameDisplay.blit(background, (0,0))\r\n        draw_text(gameDisplay,'PRESS SPACE TO START GAME', 60,370 , 500)\r\n        program.draw_tile(gameDisplay)\r\n        pygame.display.flip()\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT: pygame.quit();sys.exit()\r\n            program.events(event)\r\n        program.update_tile_pos(dt)\r\n\r\n\r\ndef level8():\r\n    program=Generate_Puzzle((6,5),80,5)\r\n    while True:\r\n        dt = clock.tick()\/1000\r\n        gameDisplay.blit(background, (0,0))\r\n        draw_text(gameDisplay,'PRESS SPACE TO START GAME', 60,370 , 500)\r\n        program.draw_tile(gameDisplay)\r\n        pygame.display.flip()\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT: pygame.quit();sys.exit()\r\n            program.events(event)\r\n        program.update_tile_pos(dt)\r\n<\/pre>\n<p>level_screen() function will display levels on game window and checking the collision of the level postion and mouse postion . according to the coliision it will call the level. We create 8 levels in our game. Each level has their different grid value.<\/p>\n<h4>7. Main loop of the game<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">game_over = True        \r\ngame_running = True \r\nwhile game_running :\r\n    if game_over :\r\n        game_front_screen()       \r\n    game_over = False\r\n\r\n    for event in pygame.event.get():\r\n        if event.type == pygame.QUIT:          \r\n            game_running = False\r\n    gameDisplay.blit(background, (0,0))  \r\n    level_screen()              \r\n   \r\n    pygame.display.update()\r\n    clock.tick(FPS)\r\npygame.quit()\r\n\r\n<\/pre>\n<ul>\n<li>This is the mainloop of the game<\/li>\n<li>If <strong>game_over<\/strong> is true then call game_front_screen() function<\/li>\n<li><strong>game_running<\/strong> used to manage the while loop. If game_running become false then terminates the game While loop<\/li>\n<li>Event type quit will close the game window<\/li>\n<li><strong>clock.tick()<\/strong> will keep the loop running at the right speed (manages the frame\/second).<\/li>\n<\/ul>\n<h3>Project output<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/11\/sliding-tile-puzzle-python-output.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-80148\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/11\/sliding-tile-puzzle-python-output.jpg\" alt=\"sliding tile puzzle python output\" width=\"1366\" height=\"729\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>In this sliding tile puzzle python project, we used popular pygame library which is used to build game and multimedia application. We create multiple levels in the game. We also used random module to randomly organize tiles when space key will pressed. In this way, we successfully developed the sliding tile game of multiple levels in Python.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sliding tiles game also known as sliding puzzle or sliding blocks game. In this game, the player has to arrange the tiles or blocks in the correct order. About Sliding Tiles Puzzle Python Project&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":80149,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[483,3249,3330],"class_list":["post-80144","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-project","tag-python-project-for-beginners","tag-sliding-tile-puzzle-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sliding Tile Puzzle in Python - TechVidvan<\/title>\n<meta name=\"description\" content=\"Sliding tile puzzle game in Python - In this Python project, we used popular python libraries - pygame &amp; random. We also created multiple levels in the game.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sliding Tile Puzzle in Python - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Sliding tile puzzle game in Python - In this Python project, we used popular python libraries - pygame &amp; random. We also created multiple levels in the game.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-26T04:00:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-03T10:24:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/11\/sliding-tile-puzzle-in-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sliding Tile Puzzle in Python - TechVidvan","description":"Sliding tile puzzle game in Python - In this Python project, we used popular python libraries - pygame & random. We also created multiple levels in the game.","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:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Sliding Tile Puzzle in Python - TechVidvan","og_description":"Sliding tile puzzle game in Python - In this Python project, we used popular python libraries - pygame & random. We also created multiple levels in the game.","og_url":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-11-26T04:00:17+00:00","article_modified_time":"2026-06-03T10:24:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/11\/sliding-tile-puzzle-in-python.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Sliding Tile Puzzle in Python","datePublished":"2020-11-26T04:00:17+00:00","dateModified":"2026-06-03T10:24:01+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/"},"wordCount":674,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/11\/sliding-tile-puzzle-in-python.jpg","keywords":["Python project","python project for beginners","Sliding Tile Puzzle in Python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/","url":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/","name":"Sliding Tile Puzzle in Python - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/11\/sliding-tile-puzzle-in-python.jpg","datePublished":"2020-11-26T04:00:17+00:00","dateModified":"2026-06-03T10:24:01+00:00","description":"Sliding tile puzzle game in Python - In this Python project, we used popular python libraries - pygame & random. We also created multiple levels in the game.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/11\/sliding-tile-puzzle-in-python.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/11\/sliding-tile-puzzle-in-python.jpg","width":1200,"height":628,"caption":"sliding tile puzzle in python"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/sliding-tile-puzzle-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Sliding Tile Puzzle in Python"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=80144"}],"version-history":[{"count":1,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80144\/revisions"}],"predecessor-version":[{"id":448144,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80144\/revisions\/448144"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/80149"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=80144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=80144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=80144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}