Older Contests
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP ContestsOlder Contests

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 22nd, 2004, 01:18 PM
keithgabryelski keithgabryelski is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Boston, MA 02108
Posts: 1 keithgabryelski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to keithgabryelski Send a message via Yahoo to keithgabryelski
[appleeaters]Distance Formula

The distance formula used in the library and in sample code is incorrect...

Although the following is the standard distance formula (represented by "sqrt((x1-x2)^2 + (y1-y2)^2)") it does not take in to account that diagonal moves are the same distances (number of moves) as verticle and horizontal moves... (you are using the pythagorean theorem to compute distanced walked which assigns a value of 1 to each horizontal moves and a value of sqrt(2) for each diagonal move).

that is: it fails to show the distance beteen
"(1,1) (1,2)" is the same distance as "(1,1) (2,2)".

Here is the line used in question:

$distance = sqrt(pow($robot[0]-$this->game["player"][0],2)+pow($robot[1]-$this->game["player"][1],2));

Instead, try max(abs(x1-x2), abs(y1-x2)) which assumes one will walk diagonal when it makes sense... or:

$distance =
max(abs($robot[0]-$game["player"][0]),
abs($robot[1]-$game["player"][1]));

it's fast and cheap too!

Pax, Keith

Reply With Quote
  #2  
Old May 23rd, 2004, 03:29 AM
Jeff321 Jeff321 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Near Chicago, IL, USA
Posts: 45 Jeff321 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Jeff321
[appleeaters]RE: Distance Formula

You're right, that does make more sense. However, the distance calculation that the library does should not affect any distance calculations that your script does. You can't use that calculation that the library does anyway since it's not mentioned in the rules.

Anyway, you're right the library should probably be updated.

BTW: Mind if I use your formula in my script?

Reply With Quote
  #3  
Old May 23rd, 2004, 05:48 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
[appleeaters]RE: Distance Formula

Thanks for pointing that out, Keith!

Yes, it would be nice if the library was updated so that it reports the distance to the closest robot/apple correctly.

- Chris B, chris@mretc.net

Reply With Quote
  #4  
Old May 23rd, 2004, 06:22 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
[appleeaters]RE: Distance Formula

hehe... or I could just update my own copy of the library and be happy 8-)

- Chris B

Reply With Quote
  #5  
Old May 23rd, 2004, 06:05 PM
Jeff321 Jeff321 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Near Chicago, IL, USA
Posts: 45 Jeff321 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Jeff321
[appleeaters]RE: Distance Formula

That's what I did

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP ContestsOlder Contests > [appleeaters]Distance Formula


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway