Skip to content

Manhattan distance (see Wikipedia) #3

Open

Description

@degski

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).

Activity

  1. greerviau commented on Aug 15, 2019

    @greerviau
    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.

  2. degski commented on Aug 16, 2019

    @degski
    Author

    @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.

  3. greerviau commented on Aug 16, 2019

    @greerviau
    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.

  4. degski commented on Aug 16, 2019

    @degski
    Author

    @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.

  5. Aazeu commented on Sep 4, 2019

    @Aazeu

    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)

  6. avin-kavish commented on Jun 19, 2020

    @avin-kavish

    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.

  7. Aazeu commented on Jun 23, 2020

    @Aazeu

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions