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 7716085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:32:54+00:00 2026-06-01T02:32:54+00:00

I have a Java HashMap containing 5 entries. Mapped to each entry is an

  • 0

I have a Java HashMap containing 5 entries. Mapped to each entry is an object containing:

  • an x value
  • a y value
  • a length
  • an orientation (either “horizontal” or “vertical”)

Think of the game battleship with a 10 x 10 board. The x / y coordinates in each entry corresponds to the top left corner of a ship on the board, and the length and orientation correspond, as one would expect, to the ships length and orientation from that point.

I’m trying to think of a way to rip through the 5 ships and check if there are any “overlapping ships”, known as conflicts, on the board. I can’t figure out how to do this. Any help would be much appreciated.

  • 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-06-01T02:32:55+00:00Added an answer on June 1, 2026 at 2:32 am

    One way to do it is:

    1) assign each cell in your board a number, 1-100 (or 0-99).

    2) Add a method to the things in your hashmap that returns a List of the unique cell ids that are covered. So if x == 1, y==1, length == 3, orientation == horizontal, you would return the three 1-100 values that represent the cell over which your submarine resides.

    You will be able to calculate the first unique id by doing something like rowNumber*10 + columnNumber. You might have to tweak it depending on if you are 0 or 1 based, and or if your range is likewise 0 or 1 based..From there, if horizontal you just add 1 for each unit of length. Or you add 10 for each unique id if your piece is vertical.

    3) Now you can have a collision detector class with a static method, that takes two pieces. It can call the method you created in step 2, get the two lists, and if there are any overlaps, you would find the same number in both lists.

    I don’t know if this is the best way to do it, but it is one way.

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

Sidebar

Related Questions

I have a java.util.HashMap object m (a return value from a call to Java
Suppose I have a Java method that returns a HashMap object. Because a LinkedHashMap
I have a java properties file containing a key/value pair of country names and
I have a java class that sets an servlet attribute to a HashMap object:
I have a Java HashMap whose keys are instances of java.lang.Object, that is: the
I have a Java HashMap with Float keys and String values. now given a
So I have a java hashmap like below: hMap.put(1, One); hMap.put(2, Two); hMap.put(3, Two);
So I have two questions about HashMap s in Java: What is the correct
Is there any reason that I would be missing the java.util.HashMap package? I have
I have been trying to understand the internal implementation of java.util.HashMap and java.util.HashSet .

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.