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

  • SEARCH
  • Home
  • 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 3948598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:23:38+00:00 2026-05-20T01:23:38+00:00

First off, this isn’t homework ;). I’m trying to create a wordsearch game from

  • 0

First off, this isn’t homework ;). I’m trying to create a wordsearch game from scratch and have hit a barrier I need some guidance on.

I’m using a 2d array of chars to for the grid of a wordsearch. I’m quite comfortable with placing words in these arrays horizontally, but I’m really stuck for ideas on how to do this vertically.

This is what I have so far, you should just be able to copy/paste it and run it

import java.util.ArrayList;
import java.util.List;

public class WordGame
{
    private static List<String> words = new ArrayList<String>();
    private static int longestWordLength = 0;
    private static int padSize = 4;
    private static char[][] grid = null;

    public static void main(String[] args)
    {
        initialiseWords();
        workOutLongestWord();
        setupGrid();
        printIt();
    }

    private static void printIt()
    {
        for (int i = 0; i < grid.length; i++)
        {
            for (int j = 0; j < grid.length; j++)
            {
                System.out.print(grid[i][j]);
            }
            System.out.print("\n");
        }
    }

    private static void setupGrid()
    {
        grid = new char[longestWordLength + padSize][longestWordLength + padSize];

        for (int i = 0; i < grid.length; i++)
        {
            String w = (i >= words.size()) ? "?" : words.get(i);
            for (int j = 0; j < grid.length; j++)
            {
                grid[i][j] = (j >= w.length()) ? '?' : w.charAt(j);
            }
        }
    }

    private static void workOutLongestWord()
    {
        for (String word : words)
        {
            if (word.length() > longestWordLength)
            {
                longestWordLength = word.length();
            }
        }
    }

    private static void initialiseWords()
    {
        words.add("monkey");
        words.add("cow");
        words.add("elephant");
        words.add("kangaroo");
    }
}

Which prints out something like …

monkey??????
cow?????????
elephant????
kangaroo????
????????????
????????????
????????????
????????????
????????????
????????????
????????????
????????????

I need to randomly pad them out on the left/right hand side, but I can do that myself.

Question : What is an effective way of attempting to place words vertically into a 2d array like the above? My initial thought was to count downwards for the required word length, breaking if anything other than a ? is found, and to keep doing this until I can find a space for the word. However this doesn’t get pretty once I take into account word overlapping.

Any pointers?

  • 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-20T01:23:39+00:00Added an answer on May 20, 2026 at 1:23 am

    I did a similar problem in C when implementing “Battleship”. Different ships were different sizes and you couldn’t have them intersect.

    Once you have vertical words you will need to check if your horizontal words hit them as well.

    I suggest making a “Word” class which is a thin class around String. You just need to keep track of the following.

    1. x,y position / index in the world
    2. What the word is
    3. the length of the word ( given to you by String in Java )
    4. The orientation of the word ( up down left right )

    You then make a method, that validates the word placement. E.G, The whole word has to be on the board, and there isn’t a collision. You can model word collision by a series of line segments. This could be done by using rect to rect collision algorithms, where one dimension is almost 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, this question is ripped out from this question. I did it because
First off: I know that this isn't reliable for actually checking if I can
First off, this isn't exactly the ideal way of setting up a page, however
Sorry this is my first time trying to create a plugin, so I might
First off, I am cross-posting this from Server Fault because I did not receive
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS
First off, let me preface this question by stating that I'm really a pretty
First off, there's a bit of background to this issue available on my blog:
First off, I am using Windows XP. I have multiple hard drives and it
First off I am using the Codeigniter Framework so this issue is a workaround

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.