Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manhattan distance (see Wikipedia) #3

Open
degski opened this issue Jun 2, 2019 · 7 comments
Open

Manhattan distance (see Wikipedia) #3

degski opened this issue Jun 2, 2019 · 7 comments

Comments

@degski
Copy link

degski commented Jun 2, 2019

For the diagonal directions, it seems your distance calculation is wrong, it might be the correct distance as the crow flies, but you cannot walk like that in Manhattan (nor in Snake). The distance is the sum of the absolute differences of the x's and the y's (whether you go zig-zag or not makes no difference).

@greerviau
Copy link
Owner

I'm never using Manhattan distance for the diagonal directions. I'm just creating a PVector from the snakes head and moving it in a certain angular direction until it reaches either the food, snake body or a wall. Once it reaches any of those obstacles I just record how many places it moved to reach it. There's no difference in how this distance is calculated for diagonal directions versus horizontal or vertical, the code is the same all that changes is the angular direction to move the vector.

@degski
Copy link
Author

degski commented Aug 16, 2019

@greerviau Yes, I understood that. The point is that the snake is not allowed to move that way, so the distance is understated. Let's suppose there are 100 x 100 meter city-blocks in Manhattan, getting to the opposite corner [of a block] will take you 200 m to walk (as you cannot go through the city block), for a bird it will (if the skyscraper is not too high ;-) ) be 141 meter.

@greerviau
Copy link
Owner

I know the difference between Manhattan and euclidean distance, I still don't understand your point. The snake isn't limited on how it can move, it may seem that way because the evolution in the video didn't tend to attack the food from diagonals but that's just an evolutionary behavior, I've trained other versions that use a diagonal strategy.

@degski
Copy link
Author

degski commented Aug 16, 2019

@greerviau Sure, I did not realize [and did not observe that in the video/gif] that you considered changing the 'rules' of snake (don't see what it has to do with evolution, though, classic snake does not move diagonally IIRC), in that case you're obviously right.

@Aazeu
Copy link

Aazeu commented Sep 4, 2019

There is a clear difference in probability that the snake approaches the food vertically or horizontally or diagonally.

I think this difference is not due to how the distance is calculated. The diagonal distance, even if it is wrong, will still influence the snake. On the other hand, the snake can move towards its prey without leaving it from sight only in the horizontal and verticals. Diagonally, it is impossible for him to keep an eye on his food during the trip.If he wants the apple he sees in a diagonal, he is obliged to move horizontally or vertically and therefore loses the food of The solution is, I think to calculate the distance and the direction of the food even if it is not aligned. Two input neurons would then be enough instead of eight in the current version. (distance and heading)

@avin-kavish
Copy link

avin-kavish commented Jun 19, 2020

Two input neurons wouldn't be enough because the distance to the walls are also important for survival. But yes, I do agree that the location of the food should always be available as distance and bearing/heading.

@Aazeu
Copy link

Aazeu commented Jun 23, 2020

I'm talking about 2 neurons to find food, distance and bearing/heading instead of 8 (north, northeast, East, Southeast, South, southwest, west and northwest). Obviously the other neurons must remain, as well the 8 nessaire for the detection of the walls as well as the 8 for the detection of the tail of the oath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants