{"id":40,"date":"2025-09-20T19:34:10","date_gmt":"2025-09-20T23:34:10","guid":{"rendered":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/?p=40"},"modified":"2025-09-20T19:40:35","modified_gmt":"2025-09-20T23:40:35","slug":"fusion-coding-2048","status":"publish","type":"post","link":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/2025\/09\/20\/fusion-coding-2048\/","title":{"rendered":"Fusion Coding\u2014 2048"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This blog is dedicated to a small project I built for this coding assignment. I decided to go with coding a text-based 2048 game since I\u2019ve played the game a lot from a long time ago, and I think it would be really interesting to try to bring my own flair into it. <\/p>\n\n\n\n<div class=\"wp-block-media-text has-media-on-the-right is-stacked-on-mobile\"><div class=\"wp-block-media-text__content\">\n<h2 class=\"wp-block-heading\">So what is 2048?<\/h2>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"220\" height=\"220\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2661.png\" alt=\"\" class=\"wp-image-41 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2661.png 220w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2661-150x150.png 150w\" sizes=\"auto, (max-width: 220px) 100vw, 220px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">2048 by Gabriele Cirulli commonly starts with a <strong>4&#215;4 <\/strong>grid of blank tiles, with 2 tiles filled with either a 2 or a 4. With every move, you move the board in your preferred direction, combining adjacent tiles as you go, and another random tile appears. The goal of the game is to reach the number 2048, in any way that you please. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u201cFailing to plan is planning to fail&#8221;\u2014 Benjamin Franklin<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\">Planning the Flow Chart<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Flowcharts are a great way to map out your thinking, especially if you have a big project at hand. I decided to map out the main components of the game in the flowchart, asking Google Gemini for any gaps in my flowchart.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"801\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2662-1024x801.jpeg\" alt=\"\" class=\"wp-image-43\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2662-1024x801.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2662-300x235.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2662-768x600.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2662-1536x1201.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2662.jpeg 1820w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Flowchart of the 2048 game loop made in Freeform<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Functions in 2048<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A function in code is a specific set of instructions that you map to a certain name in order to reference it easily throughout the code. In terms of 2048, I listed the functions I would need in 2048 on the right of the flowchart. I\u2019m guessing overall this saved me hundreds of lines of code throughout the whole game code. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Translating the Flowchart into Python<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Making a flowchart is one thing, but actually coding the game in Python is another thing entirely. I first have to import I\u2019ll go through each of the functions one by one and explain each of them:<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile\" style=\"grid-template-columns:auto 42%\"><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This <strong>clear console<\/strong> function isn\u2019t really needed but it\u2019s easier to reference. I asked Gemini how I would clear the terminal in Google Colab so I did what it told me and imported the library along with the <em>random <\/em>library for picking random tiles.<\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"229\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2665-1024x229.jpeg\" alt=\"\" class=\"wp-image-51 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2665-1024x229.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2665-300x67.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2665-768x172.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2665-1536x344.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2665.jpeg 1718w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\" style=\"grid-template-columns:54% auto\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"302\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2666-1024x302.jpeg\" alt=\"\" class=\"wp-image-52 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2666-1024x302.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2666-300x89.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2666-768x227.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2666-1536x454.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2666-2048x605.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This function creates a <strong>2D array<\/strong> for the board based on its size. You can see it calls the <em>add_new_tile<\/em> function which will make sense soon.<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile is-vertically-aligned-top\" style=\"grid-template-columns:auto 44%\"><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This function first finds all the empty cells by looping through each cell and checking if it\u2019s 0. Next if there are any empty cells it chooses a random cell(this is where the random library becomes useful) and chooses a number randomly between 2 and 4.<\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"187\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2668-1024x187.jpeg\" alt=\"\" class=\"wp-image-53 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2668-1024x187.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2668-300x55.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2668-768x140.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2668-1536x280.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2668.jpeg 1877w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile\"><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This <em>print_board<\/em> function was a bit annoying to figure out because I had to mess around a lot with the text. What it does is when the game is running, it prints the game title, score, and board. It then turns the board from just a simple grid of numbers into an actually nice looking text-based graphic. The comment on the bottom helps explain most of the function, or at least the hardest part.<\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"470\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2670-1024x470.jpeg\" alt=\"\" class=\"wp-image-54 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2670-1024x470.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2670-300x138.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2670-768x352.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2670-1536x705.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2670-2048x939.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"491\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2671-1-1024x491.jpeg\" alt=\"\" class=\"wp-image-57 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2671-1-1024x491.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2671-1-300x144.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2671-1-768x368.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2671-1-1536x737.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2671-1-2048x982.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This function is part of what is responsible for what happens on the board after a move. Let\u2019s look into the logic of the function when it <strong>slides a row left. <\/strong>It starts with making a copy of the current row <strong>without<\/strong> 0s. I decided to go with the left direction because when the code iterates through most <span style=\"text-decoration: underline\">data structures<\/span> it goes from left to right in our case. The next few lines combine the duplicates and in the end it returns the row with 0s filled in on the right.<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"375\" src=\"http:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2687-1024x375.jpeg\" alt=\"\" class=\"wp-image-59 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2687-1024x375.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2687-300x110.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2687-768x281.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2687-1536x563.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2687-2048x750.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">Obviously when you make a move it\u2019s not just <em>one <\/em>row that slides left, it\u2019s the whole board, so this function just goes through each row, slides it left and returns the new board. Notice the <em>merge_score <\/em>and <em>total_score<\/em> variables in the two functions, these will be used to display scores in the main function.<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile\"><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This function is a little deceiving to the eye because even though it\u2019s only one line it took a bit of thinking to get right. The comment explains everything.<\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"155\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2674-1024x155.jpeg\" alt=\"\" class=\"wp-image-60 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2674-1024x155.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2674-300x46.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2674-768x117.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2674-1536x233.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2674-2048x311.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile\" style=\"grid-template-columns:auto 32%\"><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This function, despite its size isn\u2019t that complicated. I did make a little bit of a mistake naming the variables because <em>total_score<\/em> isn\u2019t actually the total score of the game, just the total score of the one move. <em>score<\/em> is actually the total score, so the naming is a bit misleading. You can see the <em>rotate_board<\/em> function be put to full use here. I could\u2019ve spent some more time maybe making a counterclockwise \u201c<em>rotate_board<\/em>\u201d function but I don\u2019t think it makes <strong>too<\/strong> much of a difference. I also don\u2019t use <span style=\"text-decoration: underline\">for loops<\/span> here because it won\u2019t really save much space compared to just repeating the line over a few times. The <em>direction <\/em>variable is referring to the main function later on where we prompt the user for the move. <\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"918\" height=\"1024\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2675-918x1024.jpeg\" alt=\"\" class=\"wp-image-61 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2675-918x1024.jpeg 918w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2675-269x300.jpeg 269w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2675-768x857.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2675.jpeg 1228w\" sizes=\"auto, (max-width: 918px) 100vw, 918px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"374\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2676-1024x374.jpeg\" alt=\"\" class=\"wp-image-64 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2676-1024x374.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2676-300x110.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2676-768x281.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2676-1536x561.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2676-2048x749.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">The following 2 functions are going to decide when you lose or win the game. Most of the logic is explained in the comments. As a reminder you lose the game when the following 2 criteria are met:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>There are no more blank cells on the board<\/li>\n\n\n\n<li>There are no adjacent cells that you can merge<\/li>\n<\/ol>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"308\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2678-1024x308.jpeg\" alt=\"\" class=\"wp-image-65 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2678-1024x308.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2678-300x90.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2678-768x231.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2678-1536x462.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2678-2048x616.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This function is much more simple than the loss condition because there\u2019s only one condition that has to be met to win the game\u2014 if your biggest tile is 2048 or more. <\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile\" style=\"grid-template-columns:auto 39%\"><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This <em>main <\/em>function is so big I\u2019m going to split it into 2 images because my screen couldn\u2019t fit the whole function. This is <strong>Part 1<\/strong> where the functions handles the input responsible for the board size, printing the board, and the win and loss conditions. You might notice that the <em>score<\/em> variable I mentioned earlier is defined here\u2014 where the actual score is saved. If you <em>really <\/em>like the game and want to play past 2048, the <em>asked_continue<\/em> variable is responsible for letting you do that. If I didn\u2019t make that variable, for <strong>every move<\/strong> you do after winning it will prompt you <strong>after every move<\/strong> to ask you if you want to continue, which is a hassle if you really want to keep playing. <\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"979\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2681-1-1024x979.jpeg\" alt=\"\" class=\"wp-image-68 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2681-1-1024x979.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2681-1-300x287.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2681-1-768x734.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2681-1.jpeg 1349w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile\" style=\"grid-template-columns:auto 39%\"><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">This second part of the <em>main <\/em>function will handle what happens <strong>after a move<\/strong>. If you decide to quit it will print how many moves you made. This might be useful in future use cases if for some reason I have to work on this further. It also handles invalid inputs. After that it works on the score, adding a new tile, and increasing the move count. The <span style=\"text-decoration: underline\">if statement<\/span> at the end is something I learned a long time ago and don\u2019t really remember what its use is. It <em>might <\/em>be used to only run if it\u2019s the main program in the file, but I\u2019m not sure.<\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"456\" src=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2682-1024x456.jpeg\" alt=\"\" class=\"wp-image-69 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2682-1024x456.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2682-300x134.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2682-768x342.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2682-1536x684.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-content\/uploads\/sites\/36\/2025\/09\/IMG_2682-2048x912.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Links<\/h2>\n\n\n<nav class=\"is-responsive wp-block-navigation is-layout-flex wp-block-navigation-is-layout-flex\" aria-label=\"Footer menu 3\" \n\t\t data-wp-interactive=\"core\/navigation\" data-wp-context='{\"overlayOpenedBy\":{\"click\":false,\"hover\":false,\"focus\":false},\"type\":\"overlay\",\"roleAttribute\":\"\",\"ariaLabel\":\"Menu\"}'><button aria-haspopup=\"dialog\" aria-label=\"Open menu\" class=\"wp-block-navigation__responsive-container-open\" \n\t\t\t\tdata-wp-on--click=\"actions.openMenuOnClick\"\n\t\t\t\tdata-wp-on--keydown=\"actions.handleMenuKeydown\"\n\t\t\t><svg width=\"24\" height=\"24\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M4 7.5h16v1.5H4z\"><\/path><path d=\"M4 15h16v1.5H4z\"><\/path><\/svg><\/button>\n\t\t\t\t<div class=\"wp-block-navigation__responsive-container\"  id=\"modal-1\" \n\t\t\t\tdata-wp-class--has-modal-open=\"state.isMenuOpen\"\n\t\t\t\tdata-wp-class--is-menu-open=\"state.isMenuOpen\"\n\t\t\t\tdata-wp-watch=\"callbacks.initMenu\"\n\t\t\t\tdata-wp-on--keydown=\"actions.handleMenuKeydown\"\n\t\t\t\tdata-wp-on--focusout=\"actions.handleMenuFocusout\"\n\t\t\t\ttabindex=\"-1\"\n\t\t\t>\n\t\t\t\t\t<div class=\"wp-block-navigation__responsive-close\" tabindex=\"-1\">\n\t\t\t\t\t\t<div class=\"wp-block-navigation__responsive-dialog\" \n\t\t\t\tdata-wp-bind--aria-modal=\"state.ariaModal\"\n\t\t\t\tdata-wp-bind--aria-label=\"state.ariaLabel\"\n\t\t\t\tdata-wp-bind--role=\"state.roleAttribute\"\n\t\t\t>\n\t\t\t\t\t\t\t<button aria-label=\"Close menu\" class=\"wp-block-navigation__responsive-container-close\" \n\t\t\t\tdata-wp-on--click=\"actions.closeMenuOnClick\"\n\t\t\t><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" aria-hidden=\"true\" focusable=\"false\"><path d=\"m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z\"><\/path><\/svg><\/button>\n\t\t\t\t\t\t\t<div class=\"wp-block-navigation__responsive-container-content\" \n\t\t\t\tdata-wp-watch=\"callbacks.focusFirstElement\"\n\t\t\t id=\"modal-1-content\">\n\t\t\t\t\t\t\t\t<ul class=\"wp-block-navigation__container is-responsive wp-block-navigation\"><li class=\"wp-block-navigation-item wp-block-navigation-link\"><a class=\"wp-block-navigation-item__content\"  href=\"https:\/\/wp.stgeorges.bc.ca\/trisonc\/fusion-personal-projectnotion-dashboard\/\"><span class=\"wp-block-navigation-item__label\">Personal Project Notion Dashboard<\/span><\/a><\/li><\/ul>\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div><\/nav>","protected":false},"excerpt":{"rendered":"<p>This blog is dedicated to a small project I built for this coding assignment. I decided to go with coding a text-based 2048 game since I\u2019ve played the game a lot from a long time ago, and I think it would be really interesting to try to bring my own flair into it. So what [&hellip;]<\/p>\n","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":23,"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":93,"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/posts\/40\/revisions\/93"}],"wp:attachment":[{"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/trisonc\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}