Hexagon Generation

13»

Answers

  • Is this like a objective layout where you layout everything and slowly go threw and code it until its done to get a end result.

  • edited April 2018

    No, it was just a suggestion what you could do with what you have now, the game board.

    But if you like it, you can have the idea and make a game like it based on the current project.

    If you like it, it's your objective, your goal.

    So you can start and slowly go through the steps and make this game (or a similar game or a totally different game) bit by bit. Print the to do list, tick off what you have done. As you go on, you need to modify steps and fill possible gaps in the plan (e.g. displaying how many money each player has).

    But to do something with your current code, you need an idea or a game idea. You need a plan, break this plan down into steps and then follow them to reach a goal.

    Other ideas

    • of course you can have another game idea like doing the real Settlers of Catan (with numbers on the hexagons and 2 dices):

    https://forum.processing.org/two/discussion/25944/hexagon-pattern

    https://forum.processing.org/two/discussion/25944/hexagon-pattern#latest

    https://github.com/Kango/Games

    • or making the objective to sort the hexagons (swap them) until all the ocean hexagons etc. are in one patch

    Chrisir

  • Yeah that is true. The board game can be applied to any game.

  • I edited my post, you might want to hit F5 to see the changes

  • edited April 2018

    Thanks for post. I think i will try to do just that make a kind of new board game and have goals and objectives to do. Thanks again for the post.

  • edited April 2018

    Chrisir doing some thinking on your code and i was wondering how would you add a new statement for example if any tile besides ocean is beside ocean.

    if the non ocean tile is touching a ocean tile display a yellow quad on the non ocean tile where the too tiles connect. I was thinking it would have too be like this statement here.

        switch (direction) {
        case 0: //north
          newFieldIndex = startingNewGroupWhere  -1; 
          if (newFieldIndex >= 0 && newFieldIndex < AmountOfTiles) 
            TileColors[newFieldIndex] = startingNewGroupType;
          break;
    
        case 1: //north east 
          newFieldIndex= startingNewGroupWhere + 28; 
          if (newFieldIndex >= 0 && newFieldIndex < AmountOfTiles) 
            TileColors[newFieldIndex] = startingNewGroupType;
          break;
    
        case 2: //south east
          newFieldIndex= startingNewGroupWhere + 29; 
          if (newFieldIndex >= 0 && newFieldIndex < AmountOfTiles) 
            TileColors[newFieldIndex] = startingNewGroupType;
          break;
    
        case 3: //south 
          newFieldIndex= startingNewGroupWhere - 1; 
          if (newFieldIndex >= 0 && newFieldIndex < AmountOfTiles) 
            TileColors[newFieldIndex] = startingNewGroupType;
          break;
    
         case 4: //south west 
          newFieldIndex= startingNewGroupWhere - 29; 
          if (newFieldIndex >= 0 && newFieldIndex < AmountOfTiles) 
            TileColors[newFieldIndex] = startingNewGroupType;
          break;
    
         case 5: //north west 
          newFieldIndex= startingNewGroupWhere - 28; 
          if (newFieldIndex >= 0 && newFieldIndex < AmountOfTiles) 
            TileColors[newFieldIndex] = startingNewGroupType;
          break;
        }
    
  • When we talk about distributing the colors:

    There are two main functions:

    • patches(); and

    • fillGapsBetweenPatches();

    The latter fills gaps between patches. It basically goes through all tiles (in a random order) and checks if this tile (A) is empty. If so, it checks its neighbours. When one neighbour has a color, (A) is set to that color. That means, the existing patch grows.

    Your question:

    No.

    I don't think it works. Does it?

    if the non ocean tile is touching a ocean tile display a yellow quad on the non ocean tile where the two tiles connect

    This:

        case 0: //north
          newFieldIndex = startingNewGroupWhere  -1; 
          if (newFieldIndex >= 0 && newFieldIndex < AmountOfTiles) 
            TileColors[newFieldIndex] = startingNewGroupType;
          break;
    

    could be

    case 0: //north
      // index start field = startingNewGroupWhere 
      // index new field  = newFieldIndex 
      newFieldIndex = startingNewGroupWhere  -1; 
      if (newFieldIndex >= 0 && newFieldIndex < AmountOfTiles) 
        if (TileColors[startingNewGroupWhere] != OCEAN) 
        if (TileColors[newFieldIndex] == OCEAN) {
        TileColors[newFieldIndex] = -4; // indicating: display a yellow quad 
        }
        break;
    

    several issues here: to display a yellow quad somewhere you need a data structure to tell you which hexagons have a yellow quad. You could make a new array parallel to TileColors and name it boolean TileHoldsYellowQuad. Then set the value of TileHoldsYellowQuad[newFieldIndex] to true. Understand that the index newFieldIndex in TileHoldsYellowQuad is the same index as in TileColors. In that they are parallel: The properties of the hexagon is in the same line in the two arrays.

    But then in draw or so you need a functionality to display a yellow quad based on the data in TileHoldsYellowQuad.

    Like a for loop i and then

    if (TileHoldsYellowQuad[i]) {
        rect(...
    }
    

    Chrisir

  • Well done!

  • Chrisir i notice in the new patches generation code that the AI jumps screen i think what the problem is that if its at the last tile in the column then it moves south it jumps to the next column. I have a idea on how to fix code down below.

      if (AI's y == to last tile in the column) {
       if (direction == north) {
        AI's y - 1;
       }
       if (direction == north east) {
        AI's x + 1; AI's y + column.length;
       }
       if (direction == north west) {
        AI's x - 1; AI's y - column.length;
       }
      } else if (column % 2 && AI's y == to last tile in the column) {
       if (direction == north) {
        AI's y - 1;
       }
       if (direction == north east) {
        AI's x + 1; AI's y + column.length;
       }
       if (direction == north west) {
        AI's x - 1; AI's y - column.length;
       }
       if (direction == south west) {
        AI's x - 1;
       }
       if (direction == south east) {
        AI's x + 1;
       }
        }
        else {
       if (direction == north) {
        AI's y - 1;
       }
       if (direction == north east) {
        AI's x + 1; AI's y + column.length;
       }
       if (direction == north west) {
        AI's x - 1; AI's y - column.length;
       }
       if (direction == south east) {
        AI's y + 1;
       }       
       if (direction == south west) {
        AI's x - 1;
       }
       if (direction == south east) {
        AI's x + 1;
       }
        }
    

    This stops him on the edge of the map to jump over to the other side. Just need some help implementing into your code.

  • That’s why I said we want a 2D grid instead

    But it’s ok with a 2D grid as well

    My approach was the function tooFar. It can detect if the new tile is too far away from the previous

    If so it’s just went over the side

  • edited April 2018

    That is the grid we are using now. I did make a 2d grid but didn't implement in to the other code. Here's the code.

        //                                            int var etc..                                            //
    
        //can change the size of the hexagons
        int divider = 5;
        int cols = round(width*5.6/divider);
        int rows = round(height*4.55/divider);
        int Colm;
    
    
        //                                             void setup                                              //
    
        void setup() {
    
          size(900, 830);
    
          background(0);
    
          // Declare 2D array
          int[][] HexArray = new int[cols][rows];
    
          // Initialize 2D array values
          for (int C = 0; C < cols; C++) {
            for (int R = 0; R < rows; R++) {
              HexArray[C][R] = int(random(3));
            }
          }
    
          // Draw points
          for (int C = 0; C < cols; C++) {
            for (int R = 0;  R < rows; R++) {
              noStroke();
              if (HexArray[C][R] == 0) { fill(#13118E); }//ocean
              else if (HexArray[C][R] == 1) { fill(#5BAA24); }//grassland
              else if (HexArray[C][R] == 2) { fill(#176413); }//forest
              else { println("error"); noFill(); }
    
              if ((int)C % 2 == 0) {
                Colm = 0;
              } else {
                Colm = divider-divider/10;
                }
    
              Hexagon(divider + C * (divider-divider/5) * 2, divider + Colm + R * (divider-divider/10) * 2, divider);
            }
          }
    
        }//end of void setup
    
        //                                            void hexagon                                             //
    
        void Hexagon(float x, float y, float S) {
          noStroke();
          beginShape();
          for (int i=0; i<6; i++) {
            float angle = i * 2 * PI / 6;
            vertex(x + S*cos(angle), y + S*sin(angle));
          }
          endShape(CLOSE);
        }
    
  • edited April 2018

    Did you see this:

    My approach was the function tooFar. It can detect if the new tile is too far away from the previous

    You need to implement tooFar into the AI and let it bounce

  • What do you mean by bounce.

  • Instead of popping up on the other side of the screen, it reverses direction and goes away from the border towards center again

  • O okay that makes sense now.

  • edited April 2018

    Chrisir having trouble com bounding your code and my 2D array the two groups of code together generate the X and Y's different. Can you help the two groups of code are above.

  • Forget the 2D

    Let’s just stick with 1D

    Ok?

  • Okay is it easier with a 2D array or easier with a 1D array in this sort of area.

  • 1D is working so let’s stick with it

Sign In or Register to comment.