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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:22:36+00:00 2026-06-14T02:22:36+00:00

I am doing a tile based game. I try make a method that return

  • 0

I am doing a tile based game. I try make a method that return an array that my character can move based on x,y coordinate and move limit.

For example, if I input currentPosition:(3,3) moveLimit:1

then it should give me back ((3,2),(3,2),(3,4),(4,3))

and if I input currentPosition:(3,3) moveLimit:2

then it should back ((3,1),(2,2),(3,2),(4,2),(1,3),(2,3),(4,3),(5,3),(2,4),(3,4),(4,4),(3,5))

I planning to use recursive method by making all possible of -1 and +1 on both x and y. but it is quite inefficient, since a lot of repeated case may occur such as +1 then -1 compared to -1 then +1.

Anyone know if there is any good pattern for this?

Thank you a lot.

  • 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-14T02:22:37+00:00Added an answer on June 14, 2026 at 2:22 am

    Let’s first define the question and what you are looking for formally:

    Denote k as the distance and (x,y) as the origin point (source).

    f((x,y),k) = { (a,b) | abs(x-a) + abs(y-b) <= k } 
    

    This means, a set with all points (a,b) such that: abs(x-a) + abs(y-b) <= k (which is the distance restriction)

    Now, to get all the relevant elements you can do:

    moves((x,y),k):
      for i=0 to k+1: //number of steps in the x axis, some number between 0 to k inclusive
         //number of steps in the y axis, some number between 0 to k-i inclusive:
         for j=0 to k-i+1: 
            if (x-i,y-j) is in range: output (x-i,y-j)
            if (x+i,y-j) is in range: output (x+i,y-j)
            if (x-i,y+j) is in range: output (x-i,y+j)
            if (x+i,y+j) is in range: output (x+i,y+j)
    

    Note:

    1. This guarantees the condition because you check all possible steps in both axises with the limitation of abs(a-x) + abs(b-x) <= k
    2. In here “is in range” is a sanity check, make sure you don’t get out of bound (for example, get an x value of -1, assuming you need to get a positive value only.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a 3d tile-based strategy game and have read that implementing
I'm starting to learn how to use XNA to make a simple tile-based game,
I want to make an html5-based webpage for mobile devices that shows a map
I wasn't sure what to call this. I'm building a tile based game where
I am working on a tile based, top-down 2D game with dinamically generated terrain,
I'm creating a map editor for a little game project that I'm doing. Considering
I have written a program in Python that generates a 10,000 tile coordinate plane
I've been trying various ways of creating a two-dimensional tile-based game for a few
I decided to make a isometric game using c++ and cocos2d-x. Each isometric tile
Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'

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.