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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:47:44+00:00 2026-05-20T21:47:44+00:00

Undoubtedly this question has been asked before, except I completely lack the knowledge to

  • 0

Undoubtedly this question has been asked before, except I completely lack the knowledge to find it.

I’m trying to write the classic snake (aka Nibbles) game and the logic is pretty straight forward. Direction is expressed by a delta coordinate pair. North is -1, 0; east is 0, 1; south is 1,0; and west is 0, -1.

It’s been a decade since I took a math course so I’m not exactly sure how to convert those pairs into something where North = 0 degree’s; east = 45, south = 90; and west = 135 in which case the problem is drastically simple and becomes a case of clock arithmetic then conversion back to delta pairs.

Also, this is not academic homework but self-education

Edit:
Got a working prototype thanks to the selected answer below.
http://ominian.com/examples/js/pinglib/snakes.html

  • 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-20T21:47:45+00:00Added an answer on May 20, 2026 at 9:47 pm
    1. If you really mean degrees then you want increments of 90 degrees rather than 45.

    2. You need the atan2 function (which exists in various forms in many languages). Something like angle = 180/pi * atan2(dy,dx) — the 180/pi is because atan2 returns a value in radians. There will be numerous small mismatches between what this does and what you want: dy will be taken to increase upwards rather than downwards, 0 will be east rather than north, and atan2 typically returns values between -pi and +pi rather than between 0 and 2pi. Untangling all these is left as an exercise for the reader :-).

    3. If you only need the 4 special cases you described then you could do something ugly and ad hoc. For instance, angle = 180*(dy-dx>0)+90*(dx!=0) will do the job because S,W share the property that dy-dx>0 and E,W share the property that dx!=0.

    4. You may well find it better to work with dx,dy values everywhere and not use angles explicitly at all. For instance, rotation through 90 degrees is just (dx,dy)=(-dy,dx) (or (dy,-dx) for the other direction).

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

Sidebar

Related Questions

This is undoubtedly a simple question. I used to do this before, but it's
This question will undoubtedly be difficult to answer and ask in a way that
I have what is undoubtedly a simple question, but I can't seem to find
Anyone who has tried to implement RoutedCommands in WPF using M-V-VM has undoubtedly run
As described here http://www.ddj.com/cpp/184401688 I do not have time to write this from scratch.
I need to write a unit test for a method that will print a
It's no question that we should code our applications to protect themselves against malicious,
Migrations are undoubtedly better than just firing up phpMyAdmin and changing the schema willy-nilly
I need to replicate a sequence/counter across an eight node cluster. This means that
I've read all the SO questions, the Coding Horror articles, and Googled my brains

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.