{"id":606,"date":"2020-06-29T16:19:34","date_gmt":"2020-06-29T16:19:34","guid":{"rendered":"https:\/\/potatodie.nl\/diffuse-write-ups\/?p=606"},"modified":"2022-04-07T06:21:53","modified_gmt":"2022-04-07T06:21:53","slug":"bishops-swap-game","status":"publish","type":"post","link":"https:\/\/potatodie.nl\/diffuse-write-ups\/bishops-swap-game\/","title":{"rendered":"Bishops Swap Game"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Bishops Swap Game is a classic puzzle from the <a href=\"https:\/\/en.wikipedia.org\/wiki\/The_7th_Guest\">7th Guest<\/a>. Here is the start position of it:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"392\" height=\"486\" src=\"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/bishop-beginposition.png\" alt=\"\" class=\"wp-image-607\" srcset=\"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/bishop-beginposition.png 392w, https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/bishop-beginposition-242x300.png 242w\" sizes=\"auto, (max-width: 392px) 100vw, 392px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The end position is the same, except that the black and white bishops have swapped: the black bishops are on the top row, the white bishops are on the bottom row. Move the bishops to get the end position, according to the following rules.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The bishops move like they do in chess: diagonally only.<\/li><li>There can be at most one bishop on a square. <\/li><li>You may not put a bishop on a diagonal on which there is already a bishop of the opposite color.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Decades ago when someone described the puzzle to me, I couldn&#8217;t solve it I&#8217;m afraid and wrote a little program in JavaScript to figure it out. Down below you&#8217;ll find the output of that program,  but you may want to <a href=\"https:\/\/potatodie.nl\/lab\/bishops-and-rooks\/\">try to solve the puzzle<\/a> first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I can&#8217;t remember if I couldn&#8217;t find a solution because I didn&#8217;t realize you don&#8217;t have to alternate between white and black moves or I just was not as clever as I thought I was.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Alternative view<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">All bishops move on squares of the same color. The other squares don&#8217;t play a role in the puzzle. Maybe the puzzle is easier when those squares are left out? This would lead to a Rooks Swap Puzzle:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"362\" height=\"371\" src=\"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/rooks.png\" alt=\"\" class=\"wp-image-613\" srcset=\"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/rooks.png 362w, https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/rooks-293x300.png 293w\" sizes=\"auto, (max-width: 362px) 100vw, 362px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Graphs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Is a chessboard necessary at all? No, the problem can be described too in terms of graphs. The graph consists of ten nodes, neighboring nodes correspond with squares that can be reached in one move.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I thought this would be a good opportunity to get better acquainted with Vue.js. The model (or state, or data) would deal with the graph, while the chessboard with bishops or rooks would be two alternative views of it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To solve the puzzle visit <a href=\"https:\/\/potatodie.nl\/lab\/bishops-and-rooks\/\">Bishops and Rooks Swap Game<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Brute force solution<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The output of the script I mentioned above (from 2005) is below. Along with part of the script. Most of it is dutch!<\/p>\n\n\n<div class=\"wp-block-advanced-gutenberg-blocks-code\">\n  <header class=\"wp-block-advanced-gutenberg-blocks-code__header\">\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__lang is-lang-js\">\n      JS    <\/div>\n    <div class=\"wp-block-advanced-gutenberg-blocks-code__file\">\n          <\/div>\n  <\/header>\n  <textarea \n    class=\"wp-block-advanced-gutenberg-blocks-code__source\" \n    name=\"codemirror-1568768108\" \n    id=\"codemirror-1568768108\"\n  >function getalKomtVoorInRij ( rij, getal )\n{\n\t\/\/ Getal komt voor in een blokje van 4 bits\n\t\/\/ Je kijkt steeds naar het laatste blokje en schuift de reeks dan 4 naar rechts\n\tfor ( var n = 16; n &gt; 0; n -= 4 )\n\t{\n\t\tif ( getal == (rij % 16) )\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\trij &gt;&gt;= 4;\n\t}\n\n\treturn false;\n}\n\nfunction bestrekenVeldenPerKleur ( s, k )\n{\n\tvar a = [];\n\tvar stukken = s[k];\n\t\n\tfor ( var i = 0; i != stukken.length; i++)\n\t{\n\t\t\/\/ Stop alle velden in een array zonder dubbele\n\t\tarraysSamenvoegen ( a, bereikVanafVeld ( s, stukken[i] ) );\n\t}\n\t\n\treturn a;\n}<\/textarea>\n  <script>\n    CodeMirror.fromTextArea( document.getElementById('codemirror-1568768108'), {\n      mode: 'javascript',\n      readOnly: true,\n      theme: 'hopscotch', \n      lineNumbers: true,\n      firstLineNumber: 1,\n      matchBrackets: true,\n      indentUnit: 4,\n      tabSize: 4,\n      lineWrapping: true,\n    } ); \n  <\/script>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Finally!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"591\" src=\"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/swap-legacy.png\" alt=\"\" class=\"wp-image-612\" srcset=\"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/swap-legacy.png 686w, https:\/\/potatodie.nl\/diffuse-write-ups\/wp-content\/uploads\/2020\/06\/swap-legacy-300x258.png 300w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Bishops Swap Game is a classic puzzle from the 7th Guest. Here is the start position of it: The end position is the same, except that the black and white bishops have swapped: the black bishops are on the top row, the white bishops are on the bottom row. Move the bishops to get [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,20],"tags":[35],"class_list":["post-606","post","type-post","status-publish","format-standard","hentry","category-games","category-javascript","tag-vue-js"],"acf":[],"_links":{"self":[{"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/posts\/606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/comments?post=606"}],"version-history":[{"count":3,"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/posts\/606\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/posts\/606\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/media?parent=606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/categories?post=606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/potatodie.nl\/diffuse-write-ups\/wp-json\/wp\/v2\/tags?post=606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}