Algorithm for finding constellations in a grid












1














So I dont know if this is the type of post people don't like to see here but I thought I'd give it a shot.





Imagine a $7$ by $7$ grid like in this picture.
Every square can have 1 of five states or colours to make it easier.
the goal is it to create a row of at least three, horizontally or perpendicular, NOT diagonally, of 1 colour. This shall be achieved by swapping to tiles with each other, again not diagonally. as soon as this is accomplished the tiles that meet this condition (being in a row of at least 3 tiles with the same colour), vanish and get replaced by the ones above them. the tiles above them "fall down" if you will. new random tiles that are replacing the missing ones on "top".



I couldn't think of any other constellation, where you can swap some tile to meet the condition, but the three you can see in the picture, except for them rotated by 90, 180 or 270 degrees of course.
my initial thought was to just take a tile and check if any of the surrounding tiles have the same colour and then look from there if any tile adds up to form one of the three constellations.
If not, the next tile will be checked and so on. I realised though that this would be extremely slow, because inevitably there would be checks that wouldn't be necessary anymore.



My question now is if there are any algorithms already that solve a similar problem and if not if anyone would help me out creating one.










share|cite|improve this question





























    1














    So I dont know if this is the type of post people don't like to see here but I thought I'd give it a shot.





    Imagine a $7$ by $7$ grid like in this picture.
    Every square can have 1 of five states or colours to make it easier.
    the goal is it to create a row of at least three, horizontally or perpendicular, NOT diagonally, of 1 colour. This shall be achieved by swapping to tiles with each other, again not diagonally. as soon as this is accomplished the tiles that meet this condition (being in a row of at least 3 tiles with the same colour), vanish and get replaced by the ones above them. the tiles above them "fall down" if you will. new random tiles that are replacing the missing ones on "top".



    I couldn't think of any other constellation, where you can swap some tile to meet the condition, but the three you can see in the picture, except for them rotated by 90, 180 or 270 degrees of course.
    my initial thought was to just take a tile and check if any of the surrounding tiles have the same colour and then look from there if any tile adds up to form one of the three constellations.
    If not, the next tile will be checked and so on. I realised though that this would be extremely slow, because inevitably there would be checks that wouldn't be necessary anymore.



    My question now is if there are any algorithms already that solve a similar problem and if not if anyone would help me out creating one.










    share|cite|improve this question



























      1












      1








      1







      So I dont know if this is the type of post people don't like to see here but I thought I'd give it a shot.





      Imagine a $7$ by $7$ grid like in this picture.
      Every square can have 1 of five states or colours to make it easier.
      the goal is it to create a row of at least three, horizontally or perpendicular, NOT diagonally, of 1 colour. This shall be achieved by swapping to tiles with each other, again not diagonally. as soon as this is accomplished the tiles that meet this condition (being in a row of at least 3 tiles with the same colour), vanish and get replaced by the ones above them. the tiles above them "fall down" if you will. new random tiles that are replacing the missing ones on "top".



      I couldn't think of any other constellation, where you can swap some tile to meet the condition, but the three you can see in the picture, except for them rotated by 90, 180 or 270 degrees of course.
      my initial thought was to just take a tile and check if any of the surrounding tiles have the same colour and then look from there if any tile adds up to form one of the three constellations.
      If not, the next tile will be checked and so on. I realised though that this would be extremely slow, because inevitably there would be checks that wouldn't be necessary anymore.



      My question now is if there are any algorithms already that solve a similar problem and if not if anyone would help me out creating one.










      share|cite|improve this question















      So I dont know if this is the type of post people don't like to see here but I thought I'd give it a shot.





      Imagine a $7$ by $7$ grid like in this picture.
      Every square can have 1 of five states or colours to make it easier.
      the goal is it to create a row of at least three, horizontally or perpendicular, NOT diagonally, of 1 colour. This shall be achieved by swapping to tiles with each other, again not diagonally. as soon as this is accomplished the tiles that meet this condition (being in a row of at least 3 tiles with the same colour), vanish and get replaced by the ones above them. the tiles above them "fall down" if you will. new random tiles that are replacing the missing ones on "top".



      I couldn't think of any other constellation, where you can swap some tile to meet the condition, but the three you can see in the picture, except for them rotated by 90, 180 or 270 degrees of course.
      my initial thought was to just take a tile and check if any of the surrounding tiles have the same colour and then look from there if any tile adds up to form one of the three constellations.
      If not, the next tile will be checked and so on. I realised though that this would be extremely slow, because inevitably there would be checks that wouldn't be necessary anymore.



      My question now is if there are any algorithms already that solve a similar problem and if not if anyone would help me out creating one.







      algorithms






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited Nov 28 at 14:38









      amWhy

      191k28224439




      191k28224439










      asked Sep 28 '16 at 14:58









      Tazua

      62




      62



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "69"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1945130%2falgorithm-for-finding-constellations-in-a-grid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Mathematics Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1945130%2falgorithm-for-finding-constellations-in-a-grid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Tonle Sap (See)

          I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

          Guatemaltekische Davis-Cup-Mannschaft