{"id":5252,"date":"2021-04-17T10:26:28","date_gmt":"2021-04-17T17:26:28","guid":{"rendered":"https:\/\/mattfife.com\/?p=5252"},"modified":"2021-04-17T13:30:06","modified_gmt":"2021-04-17T20:30:06","slug":"optimal-battleship","status":"publish","type":"post","link":"https:\/\/mattfife.com\/?p=5252","title":{"rendered":"Optimal Battleship"},"content":{"rendered":"\n<p>Nick Berry, president of DataGenetics, <a rel=\"noreferrer noopener\" href=\"https:\/\/www.datagenetics.com\/blog\/december32011\/index.html\" data-type=\"URL\" data-id=\"https:\/\/www.datagenetics.com\/blog\/december32011\/index.html\" target=\"_blank\">meticulously analyzes different strategies<\/a> to play the classic board game Battleship (he also has done <a rel=\"noreferrer noopener\" href=\"http:\/\/www.datagenetics.com\/blog\/november12011\/index.html\" target=\"_blank\">Chutes &amp; Ladders<\/a>,\u00a0<a rel=\"noreferrer noopener\" href=\"http:\/\/www.datagenetics.com\/blog\/december12011\/index.html\" target=\"_blank\">Candyland<\/a>\u00a0and\u00a0<a rel=\"noreferrer noopener\" href=\"http:\/\/www.datagenetics.com\/blog\/november22011\/index.html\" target=\"_blank\">Risk<\/a>)<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5259\" data-permalink=\"https:\/\/mattfife.com\/?attachment_id=5259\" data-orig-file=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?fit=1600%2C1125&amp;ssl=1\" data-orig-size=\"1600,1125\" 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=\"battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?fit=640%2C450&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?resize=460%2C323&#038;ssl=1\" alt=\"\" class=\"wp-image-5259\" width=\"460\" height=\"323\" srcset=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?resize=1024%2C720&amp;ssl=1 1024w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?resize=300%2C211&amp;ssl=1 300w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?resize=768%2C540&amp;ssl=1 768w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?resize=1536%2C1080&amp;ssl=1 1536w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?resize=384%2C270&amp;ssl=1 384w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?w=1600&amp;ssl=1 1600w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/battleship-game-complete-all-of-the-plastic-battleships-1stopretroshop-s52832-1-1.jpg?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 460px) 100vw, 460px\" \/><\/figure><\/div>\n\n\n\n<p>It&#8217;s a great example of how computer scientists often work. He explores a host of techniques and analyzes the results by calculating how often you&#8217;ll get a perfect game, median number of guesses, and how bad it gets in the worst case. <\/p>\n\n\n\n<p>He examines 4 major strategies:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Pure random searching<\/li><li>Hunt and Target &#8211; Hunt randomly until you get a hit, then proceed methodically to sink the hit ship.<\/li><li>Hunt and Target with parity &#8211; since the minimum length of a ship is 2 units, you need only search even or odd squares<\/li><li>Hunt and Target with parity combined with a <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Probability_density_function\" data-type=\"URL\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/Probability_density_function\" target=\"_blank\">probability density function<\/a>. <\/li><\/ol>\n\n\n\n<p>His fourth approach is the most fascinating. The system calculates every possible configuration of the remaining ships, and then sums up the probability of a ship on each square. At the beginning, all the squares are basically equally probable, but as more and more guesses are made, the number of possible configurations decreases. If you continually calculate the sum of these possibilities, pick the square with the highest probability and repeat this process, you get significantly better results.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-3 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"198\" height=\"198\" data-attachment-id=\"5253\" data-permalink=\"https:\/\/mattfife.com\/?attachment_id=5253\" data-orig-file=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh3.png?fit=198%2C198&amp;ssl=1\" data-orig-size=\"198,198\" 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=\"sh3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh3.png?fit=198%2C198&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh3.png?resize=198%2C198&#038;ssl=1\" alt=\"\" data-id=\"5253\" data-full-url=\"https:\/\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh3.png\" data-link=\"https:\/\/mattfife.com\/?attachment_id=5253\" class=\"wp-image-5253\" srcset=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh3.png?w=198&amp;ssl=1 198w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh3.png?resize=150%2C150&amp;ssl=1 150w\" sizes=\"auto, (max-width: 198px) 100vw, 198px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"198\" height=\"198\" data-attachment-id=\"5254\" data-permalink=\"https:\/\/mattfife.com\/?attachment_id=5254\" data-orig-file=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh7.png?fit=198%2C198&amp;ssl=1\" data-orig-size=\"198,198\" 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=\"sh7\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh7.png?fit=198%2C198&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh7.png?resize=198%2C198&#038;ssl=1\" alt=\"\" data-id=\"5254\" data-full-url=\"https:\/\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh7.png\" data-link=\"https:\/\/mattfife.com\/?attachment_id=5254\" class=\"wp-image-5254\" srcset=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh7.png?w=198&amp;ssl=1 198w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/sh7.png?resize=150%2C150&amp;ssl=1 150w\" sizes=\"auto, (max-width: 198px) 100vw, 198px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"198\" height=\"198\" data-attachment-id=\"5255\" data-permalink=\"https:\/\/mattfife.com\/?attachment_id=5255\" data-orig-file=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/shx.png?fit=198%2C198&amp;ssl=1\" data-orig-size=\"198,198\" 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=\"shx\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/shx.png?fit=198%2C198&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/shx.png?resize=198%2C198&#038;ssl=1\" alt=\"\" data-id=\"5255\" data-full-url=\"https:\/\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/shx.png\" data-link=\"https:\/\/mattfife.com\/?attachment_id=5255\" class=\"wp-image-5255\" srcset=\"https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/shx.png?w=198&amp;ssl=1 198w, https:\/\/i0.wp.com\/mattfife.com\/wp-content\/themes\/mattTheme\/headerimgs\/2021\/04\/shx.png?resize=150%2C150&amp;ssl=1 150w\" sizes=\"auto, (max-width: 198px) 100vw, 198px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p>How much better? Purely random guessing gives you a median of 97 moves. Using parity with the hunt+target method averages 64 moves. But using the probability density function increases that to a staggering 42 moves on average.<\/p>\n\n\n\n<p>Turns out, I <a rel=\"noreferrer noopener\" href=\"https:\/\/mattfife.com\/?p=4498\" data-type=\"URL\" data-id=\"https:\/\/mattfife.com\/?p=4498\" target=\"_blank\">discussed the use of this kind of probability density function by speedrunners<\/a> who used the same technique to beat the splosh-kaboom minigame in the Legend of Zelda Wind Waker.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nick Berry, president of DataGenetics, meticulously analyzes different strategies to play the classic board game Battleship (he also has done Chutes &amp; Ladders,\u00a0Candyland\u00a0and\u00a0Risk) It&#8217;s a great example of how computer scientists often work. He explores a host of techniques and analyzes the results by calculating how often you&#8217;ll get a perfect game, median number of guesses, and how bad it gets in the worst case. He examines 4 major strategies: Pure random searching Hunt and Target &#8211; Hunt randomly until&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/mattfife.com\/?p=5252\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"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":[9,6,5],"tags":[],"class_list":["post-5252","post","type-post","status-publish","format-standard","hentry","category-cool","category-technicalproblemsolutions","category-technical"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4WECr-1mI","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/5252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5252"}],"version-history":[{"count":4,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/5252\/revisions"}],"predecessor-version":[{"id":5261,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/5252\/revisions\/5261"}],"wp:attachment":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}