{"id":3239,"date":"2024-08-04T13:11:54","date_gmt":"2024-08-04T18:11:54","guid":{"rendered":"http:\/\/www.ishygddt.xyz\/~blog\/?p=3239"},"modified":"2024-08-04T13:11:54","modified_gmt":"2024-08-04T18:11:54","slug":"draft-data-structure-simple-hex-grid-for-catan","status":"publish","type":"post","link":"http:\/\/www.ishygddt.xyz\/~blog\/2024\/08\/draft-data-structure-simple-hex-grid-for-catan","title":{"rendered":"[DRAFT] Data structure simple hex grid for Catan"},"content":{"rendered":"<p>At this point, I'm sure you're already familiar with the basic \"hex grid\" data structure:<\/p>\n<pre>The q-axis is 0deg\u2192\ufe0e; the r-axis is 120deg\u2199\ufe0e.\r\n               \u250c\u2500\u2500\u2500\u2510   \u250c\u2500\u2500\u2500\u2510   \u250c\u2500\u2500\u2500\u2510   \u250c\u2500\u2500\u2500\u2510   \u250c\u2500\u2500\u2500\u2510\r\n             \u250c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\r\n             \u2502 (0,0) \u2502 (1,0) \u2502 (2,0) \u2502 (3,0) \u2502 (4,0) \u2502\r\n           \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\r\n         \u250c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518\r\n         \u2502 (0,1) \u2502 (1,1) \u2502 (2,1) \u2502 (3,1) \u2502 (4,1) \u2502\r\n       \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\r\n     \u250c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518\r\n     \u2502 (0,2) \u2502 (1,2) \u2502 (2,2) \u2502 (3,2) \u2502 (4,2) \u2502\r\n   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\r\n \u250c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518\r\n \u2502 (0,3) \u2502 (1,3) \u2502 (2,3) \u2502 (3,3) \u2502 (4,3) \u2502\r\n\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\u2510   \u250c\u2500\u2534\u2500\r\n   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518   \u2514\u2500\u252c\u2500\u2518\r\n\r\n<\/pre>\n<p>Here's a simple way to implement edges and intersections, for example if you're making a bootleg of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Settlers of Catan\"><i>Catan<\/i><\/a>:<\/p>\n<p>Say that your logical array for the <em>tiles<\/em> has a geometry of H\u00d7W; this array will of course be sparse if you have a board that's any shape other than a parallelogram.<\/p>\n<ol>\n<li>For edges \u2014 Catan \u201croads\u201d \u2014 allocate a logical array of (H+1)\u00d7(W+1)\u00d73<\/li>\n<li>For intersections \u2014 Catan \u201csettlements\u201d \u2014 allocate a logical array of (H+1)\u00d7(W+1)\u00d72<\/li>\n<li>Define the intersections \u201cadjacent\u201d to tile (q,r) to be {(q+1,r,2), (q+1,r+1,1), (q,r+1,0), (q,r,2), (q,r,1), (q,r,0)}\n<ul>\n<li>In other words, intersection 0 is due-north of its quasi-corresponding tile, and intersection 1 is north-west of it<\/li>\n<\/ul>\n<\/li>\n<li>Define the edges \u201cadjacent\u201d to intersection (q,r,0) to be {(q,r,0), (q,r,1), (q,r-1,2)}; and define the edges \u201cadjacent\u201d to intersection (q,r,1) to be {(q,r,2), (q-1,r-1,0), (q-1)}\n<ul>\n<li>In other words, edge 0 is north-east of its quasi-corresponding tile, edge 1 is north-west of it, and edge 2 is due-west of it.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>You could have chosen any arbitrary 2 intersections and 3 edges for each tile, but choosing them this way is optimal for tile-first applications. If a tile exists, all adjacent edges and intersections are <em>guaranteed<\/em> to exist; and for a non-sparse board, there are no wasted intersection or edge allocations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At this point, I'm sure you're already familiar with the basic \"hex grid\" data structure: The q-axis is 0deg\u2192\ufe0e; the r-axis is 120deg\u2199\ufe0e. \u250c\u2500\u2500\u2500\u2510 \u250c\u2500\u2500\u2500\u2510 \u250c\u2500\u2500\u2500\u2510 \u250c\u2500\u2500\u2500\u2510 \u250c\u2500\u2500\u2500\u2510 \u250c\u2500\u2518 \u2514\u2500\u252c\u2500\u2518 \u2514\u2500\u252c\u2500\u2518 \u2514\u2500\u252c\u2500\u2518 \u2514\u2500\u252c\u2500\u2518 \u2514\u2500\u252c\u2500 \u2502 (0,0) \u2502 (1,0) \u2502 (2,0) \u2502 (3,0) \u2502 (4,0) \u2502 \u250c\u2500\u2534\u2500\u2510 \u250c\u2500\u2534\u2500\u2510 \u250c\u2500\u2534\u2500\u2510 \u250c\u2500\u2534\u2500\u2510 \u250c\u2500\u2534\u2500\u2510 \u250c\u2500\u2534\u2500 \u250c\u2500\u2518 \u2514\u2500\u252c\u2500\u2518 \u2514\u2500\u252c\u2500\u2518 \u2514\u2500\u252c\u2500\u2518 &hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-3239","post","type-post","status-publish","format-standard","hentry","category-drafts"],"_links":{"self":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/3239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/comments?post=3239"}],"version-history":[{"count":15,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/3239\/revisions"}],"predecessor-version":[{"id":3256,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/posts\/3239\/revisions\/3256"}],"wp:attachment":[{"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/media?parent=3239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/categories?post=3239"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ishygddt.xyz\/~blog\/wp-json\/wp\/v2\/tags?post=3239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}