Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7556935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:59:38+00:00 2026-05-30T11:59:38+00:00

I’m making a game. In the game there is a grid that is populated

  • 0

I’m making a game. In the game there is a grid that is populated by cells. Each cell has a partner (same type of cell). There should be 24 total cells which would mean 12 different pairs of cells. For example a cell can be type 1, there will be two type 1 cells on the grid.
All the way until type 12.
What I’m trying to achieve with my code is to randomly generate a row and column and then place a cell of type 1 on it. AGAIN, generate random row and column and place type 1 cell on it.
Then increment type.

Now what I am struggling with is the condition that will make sure my entire grid is fully populated with cells.
Further more a condition that makes sure that once a cell has been placed at a spot on the grid, it cannot be replaced by another cell.

Here is the code that I’ve come up with for now.

     int type =1;
    int row=0;
    int column=0;
    board[row][column] = new Cell(this, type, row, column);



    while(board[row][column] != null){

      if(type <=12){



      row = generator.nextInt(4);
      column = generator.nextInt(6);      
      board[row][column] = new Cell(this, type, row, column);
      type++;

        if (type < 13){
      row = generator.nextInt(4);      
      column = generator.nextInt(6);      
      board[row][column] = new Cell(this, type, row, column);


      row = generator.nextInt(4);
      column = generator.nextInt(6);
      board[row][column] = new Cell(this, type, row, column);


      add(board[row][column]);} //Adding a Cell object **board is a 2d array of type Cell**
      }
  }
  }

Tried my best to explain the problem in the most simple terms

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:59:40+00:00Added an answer on May 30, 2026 at 11:59 am

    A better way to do this than adding items at random would be to populate the array in a straightforward way and then randomise it, but there is no easy way to do that.

    There is an equivalent thing you can do: create a List with all the required values in, randomly shuffle the List and then populate your array from that, mapping the entries in the List to the rows and columns on your array:

    List<Integer> list = new ArrayList<Integer>(24);
    
    for (int type = 1; type <= 12; type++) {
      //Add each type twice
      list.add(type);
      list.add(type);
    }
    
    Collections.shuffle(list);
    int[][] board = new int[4][6];
    
    for (int row = 0; row < 4; row++) {
      for (int column = 0; column < 6; column++) {
        int type = list.get(row + column * 4);
        board[row][column] = new Cell(this, type, row, column);
      }
    }
    

    The mapping of rows and columns to List entries isn’t all that important, as long as you use each entry from the shuffled List only once, so you could do this:

    Iterator<Integer> i = list.iterator();
    
    for (int row = 0; row < 4; row++) {
      for (int column = 0; column < 6; column++) {
        int type = i.next();
        board[row][column] = new Cell(this, type, row, column);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.