This code will check the number of snake body parts are present in particular coordinates.
If more than 1 exists then it means snake bites itself and it will end the game.
CHANGES MADE:
Added arr[x][y]++; which will tells the number of body parts of snake present in particular coordinates
Added a condition that to check if arr[x][y]>1 it means snake bites itself .
It will work with O(1) complexity
previously added: added an array which will store 1 when the snake exists at particular coordinates else 0
video : 1) checking to go in opposite direction
2) checking to bite the snake body
4
This code will check the number of snake body parts are present in particular coordinates. If more than 1 exists then it means snake bites itself and it will end the game.
CHANGES MADE: Added arr[x][y]++; which will tells the number of body parts of snake present in particular coordinates Added a condition that to check if arr[x][y]>1 it means snake bites itself . It will work with O(1) complexity
previously added: added an array which will store 1 when the snake exists at particular coordinates else 0 video : 1) checking to go in opposite direction 2) checking to bite the snake body
https://github.com/iiitl/snake-game-js/assets/143714210/c275b6a8-ab54-4af3-9cc3-92e388274a83