{"id":2267,"date":"2019-07-06T13:00:28","date_gmt":"2019-07-06T12:00:28","guid":{"rendered":"https:\/\/chewett.co.uk\/blog\/?p=2267"},"modified":"2019-07-24T23:21:21","modified_gmt":"2019-07-24T22:21:21","slug":"creating-a-talos-principle-puzzle-solver","status":"publish","type":"post","link":"https:\/\/chewett.co.uk\/blog\/2267\/creating-a-talos-principle-puzzle-solver\/","title":{"rendered":"Creating a Talos Principle Puzzle Solver"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"254\" data-attachment-id=\"2272\" data-permalink=\"https:\/\/chewett.co.uk\/blog\/2267\/creating-a-talos-principle-puzzle-solver\/talos_puzzle_solver\/\" data-orig-file=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/Talos_puzzle_solver.jpg?fit=800%2C300&amp;ssl=1\" data-orig-size=\"800,300\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Talos_puzzle_solver\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/Talos_puzzle_solver.jpg?fit=300%2C113&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/Talos_puzzle_solver.jpg?fit=678%2C254&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/Talos_puzzle_solver.jpg?resize=678%2C254&#038;ssl=1\" alt=\"\" class=\"wp-image-2272\" srcset=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/Talos_puzzle_solver.jpg?w=800&amp;ssl=1 800w, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/Talos_puzzle_solver.jpg?resize=300%2C113&amp;ssl=1 300w, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/Talos_puzzle_solver.jpg?resize=768%2C288&amp;ssl=1 768w, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/Talos_puzzle_solver.jpg?resize=50%2C19&amp;ssl=1 50w\" sizes=\"auto, (max-width: 678px) 100vw, 678px\" \/><\/figure>\n\n\n\n<p>This blog post talks about the Talos Principle puzzle solver I wrote to help solve the Sigil puzzles.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2269\" data-permalink=\"https:\/\/chewett.co.uk\/blog\/2267\/creating-a-talos-principle-puzzle-solver\/example_talos_solver\/\" data-orig-file=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/example_talos_solver.jpg?fit=422%2C501&amp;ssl=1\" data-orig-size=\"422,501\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"example_talos_solver\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/example_talos_solver.jpg?fit=253%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/example_talos_solver.jpg?fit=422%2C501&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/example_talos_solver.jpg?resize=383%2C455&#038;ssl=1\" alt=\"\" class=\"wp-image-2269\" width=\"383\" height=\"455\" srcset=\"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/example_talos_solver.jpg?w=422&amp;ssl=1 422w, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/example_talos_solver.jpg?resize=253%2C300&amp;ssl=1 253w, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/example_talos_solver.jpg?resize=42%2C50&amp;ssl=1 42w\" sizes=\"auto, (max-width: 383px) 100vw, 383px\" \/><\/figure><\/div>\n\n\n\n<p>The game &#8220;The Talos Principle&#8221; has points where you need to place a series of Tetris pieces, called sigils in the game, onto a puzzle board to move onto<br> the next area. Some of the smaller boards requiring less sigils are easier, but the larger ones can take considerable time to complete.<\/p>\n\n\n\n<p>So, instead of doing it manually I coded up a brute force solution which will attempt every single possible solution until it finds a working one.<\/p>\n\n\n\n<p>In the above image you can see the current interface. First the width and height is typed up and then each Tetris piece is added to the list by pressing the blue buttons.<\/p>\n\n\n\n<p>Once entered, pressing the solve button will either draw a grid below as shown or display that it cannot solve the puzzle.<\/p>\n\n\n\n<p>Pressing reset will allow entering a new set of pieces.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Initial implementation<\/h2>\n\n\n\n<p>To start with, an empty board is created with all the sigils added as possible pieces to place. This creates the first board state.<\/p>\n\n\n\n<p>Then until it finds a solution it will take a board state object from the list and perform the following operations:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Takes the next sigil to place, and then finds every location that the sigil could be placed. (This also takes into account some sigils have one, two or four rotations.<\/li><li>Once it finds every location that it can be placed it creates a new state for every placement<\/li><li>If that placement has placed all pieces, it will be returned as a finished board<\/li><li>If no more sigils can be placed then it ignores that state, and continues to the next one<\/li><\/ul>\n\n\n\n<p>This continues until it no longer has any more attempts, or it has found an instance that works.<\/p>\n\n\n\n<p>The basic web application has been <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/chewett.net\/talossolver\/\" target=\"_blank\">added on my website here<\/a>. Please note the code isn&#8217;t cleaned up, or commented well as I threw this together. These improvements are planned for the future.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What can be done to speed it up<\/h2>\n\n\n\n<p>There are a couple of logic checks that can be made to speed up the calculations. These will probably be added in the future as for larger puzzles this solver is quite slow.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Ignoring solutions that have impossible gaps<\/h3>\n\n\n\n<p>Every Tetris piece that is to be placed is 4 connected squares.<\/p>\n\n\n\n<p>This means that for any hole in the puzzle to be filled it must be a multiple of four squares. This means that if there is a hole in the puzzle with only three squares, no piece will be able to be placed to fill it.<\/p>\n\n\n\n<p>This means that if any puzzle state has a hole that is not a multiple of four it will be invalid. These could be checked as they are generated and the invalid states removed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Smart corner placement<\/h3>\n\n\n\n<p>All these puzzles are a rectangle which means that there must always be a piece in each of the corners.<\/p>\n\n\n\n<p>By creating a set of states with every possible combination of corner pieces it should reduce the state space to brute force. This is because you know that one of the generated state spaces must be correct as each corner must be filled.<\/p>\n\n\n\n<p>This will likely cause a number of states of quickly be found as invalid and will speed up the state space checking.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using a web worker to perform the checking<\/h3>\n\n\n\n<p>Currently all the calculations are performed in the main JavaScript thread.<\/p>\n\n\n\n<p>This means that for larger puzzles it locks up the page and may appear unresponsive.<\/p>\n\n\n\n<p>Using a WebWorker to calculate the maths would stop it slowing down the UI. In addition while it is running it will be relatively easy to show the progress of the computation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Converting the Web Worker to WebAssembly<\/h3>\n\n\n\n<p>WebAssembly allows you to write code in a lower level language and compile it to run in the browser. This has advantages as it allows more control over the memory and runtime of the application.<\/p>\n\n\n\n<p>Therefore rewriting the computation into a lower level language and compiling it into WebAssembly may speed up the calculations.<\/p>\n\n\n\n<p>However it is not supported in all browsers so potentially it will need a fallback method, possibly to a Web Worker<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary of Solver<\/h2>\n\n\n\n<p>This solver can help you solve the sigil puzzles in &#8220;The Talos Principle&#8221;. It still needs some work but as a basic solver it works quite well.<\/p>\n\n\n\n<p>The future plans are to speed it up and document it better so people can see how it works.<\/p>\n\n\n\n<p>As noted before the basic web application has been <a rel=\"noreferrer noopener\" href=\"https:\/\/chewett.net\/talossolver\/\" target=\"_blank\">added on my website here<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog post talks about the Talos Principle puzzle solver I wrote to help solve the Sigil puzzles.<\/p>\n","protected":false},"author":1,"featured_media":2271,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[98],"tags":[14,353,72,352,266],"class_list":["post-2267","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-game","tag-html","tag-javascript","tag-the-talos-principle","tag-web"],"wppr_data":{"cwp_meta_box_check":"No"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/talos_principle_solver.jpg?fit=800%2C800&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p2toWX-Az","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2375,"url":"https:\/\/chewett.co.uk\/blog\/2375\/im-participating-in-advent-of-code-2019\/","url_meta":{"origin":2267,"position":0},"title":"I&#8217;m Participating in Advent of Code 2019","author":"Chewett","date":"December 14, 2019","format":false,"excerpt":"This post talks about my participation in the Advent of Code competition 2019. What is Advent of Code Advent of code is a set of programming puzzles that slowly increase in complexity. Every day during advent a new puzzle is released which has two parts. The first part is typically\u2026","rel":"","context":"In &quot;Informational&quot;","block_context":{"text":"Informational","link":"https:\/\/chewett.co.uk\/blog\/category\/informational\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/12\/advent_of_code_2019-1.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/12\/advent_of_code_2019-1.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/12\/advent_of_code_2019-1.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/12\/advent_of_code_2019-1.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2102,"url":"https:\/\/chewett.co.uk\/blog\/2102\/checking-if-two-points-are-closer-than-a-distance\/","url_meta":{"origin":2267,"position":1},"title":"Checking if two points are closer than a distance","author":"Chewett","date":"April 3, 2019","format":false,"excerpt":"This blog post talks about how you can quickly check if two point are closer than a specific distance. How to calculate the distance between two points To calculate the distance between two points you can use Pythagoras Theorem. This states that for a right angled triangle you can find\u2026","rel":"","context":"In &quot;Software&quot;","block_context":{"text":"Software","link":"https:\/\/chewett.co.uk\/blog\/category\/software\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/03\/two_points_closer_distance-1.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/03\/two_points_closer_distance-1.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/03\/two_points_closer_distance-1.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/03\/two_points_closer_distance-1.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1431,"url":"https:\/\/chewett.co.uk\/blog\/1431\/simple-d3-js-version-5-data-binding-and-updating-example-and-code\/","url_meta":{"origin":2267,"position":2},"title":"Simple D3.js version 5 data binding and updating example and code","author":"Chewett","date":"August 11, 2018","format":false,"excerpt":"This post goes through the process of binding data to elements and creating a simple updatable SVG graphic using D3.js version 5. Data binding and updating in D3.js version 5 In D3.js version 4 there was quite a big update to how data is bound to elements and updated. This\u2026","rel":"","context":"In &quot;Software&quot;","block_context":{"text":"Software","link":"https:\/\/chewett.co.uk\/blog\/category\/software\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/08\/d3_simple_data_binding.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/08\/d3_simple_data_binding.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/08\/d3_simple_data_binding.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/08\/d3_simple_data_binding.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":109,"url":"https:\/\/chewett.co.uk\/blog\/109\/magicduel-a-different-sort-of-game\/","url_meta":{"origin":2267,"position":3},"title":"MagicDuel &#8211; A different sort of game","author":"Chewett","date":"July 20, 2019","format":false,"excerpt":"Today I have written a short piece about a game I play and program for from time to time, MagicDuel. Many years ago I found a small website that had great hand drawn artwork of a creature\u00a0pulling something out of a box, inviting you to guess what was inside it.\u2026","rel":"","context":"In &quot;Informational&quot;","block_context":{"text":"Informational","link":"https:\/\/chewett.co.uk\/blog\/category\/informational\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/magicduel_a_strange_game.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/magicduel_a_strange_game.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/magicduel_a_strange_game.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/07\/magicduel_a_strange_game.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1139,"url":"https:\/\/chewett.co.uk\/blog\/1139\/helping-the-silph-road-as-a-pokemon-go-researcher\/","url_meta":{"origin":2267,"position":4},"title":"Helping the Silph Road as a Pokemon Go Researcher","author":"Chewett","date":"April 25, 2018","format":false,"excerpt":"Here I talk about what I do as a Silph Road Researcher in the Pokemon Go Community. What is the Silph Road? The Silph Road is a group of Pokemon Go players who contribute data and produce publications detailing how Pokemon Go works. They typically focus on researching areas which\u2026","rel":"","context":"In &quot;Informational&quot;","block_context":{"text":"Informational","link":"https:\/\/chewett.co.uk\/blog\/category\/informational\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/04\/silph_road_researcher.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/04\/silph_road_researcher.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/04\/silph_road_researcher.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/04\/silph_road_researcher.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2366,"url":"https:\/\/chewett.co.uk\/blog\/2366\/fixing-startup-company-save-file-lost\/","url_meta":{"origin":2267,"position":5},"title":"Fixing Startup Company Save file lost","author":"Chewett","date":"November 16, 2019","format":false,"excerpt":"This post talks about what you can do if your Startup Company save is lost. (Note, its probably not lost). Dont worry, its probably not lost If you haven't played the game in a while and come back to it, you will likely find your save is lost. This happened\u2026","rel":"","context":"In &quot;Fixes&quot;","block_context":{"text":"Fixes","link":"https:\/\/chewett.co.uk\/blog\/category\/fixes\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/11\/startup_company_save_file_lost.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/11\/startup_company_save_file_lost.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/11\/startup_company_save_file_lost.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2019\/11\/startup_company_save_file_lost.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/2267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=2267"}],"version-history":[{"count":6,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/2267\/revisions"}],"predecessor-version":[{"id":2278,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/2267\/revisions\/2278"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/media\/2271"}],"wp:attachment":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=2267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=2267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=2267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}