Skip to content

Comments

Change in boundary condition (line 87).#1

Open
jainayush362 wants to merge 1 commit intocoding-blocks-archives:masterfrom
jainayush362:patch-1
Open

Change in boundary condition (line 87).#1
jainayush362 wants to merge 1 commit intocoding-blocks-archives:masterfrom
jainayush362:patch-1

Conversation

@jainayush362
Copy link

The last two OR ( || ) cases of 'if' condition at line 87 should have '>=" comparison instead of just '>' comparison. This is because, suppose the length of our snake is 5 boxes and we hit right boundary then as per '>' comparison then game gets over only when 1 box out of snake length (i.e. 5 boxes) crosses that boundary. But if we put '>=' comparison then the game gets over as soon as the snake touches the boundary. Similar case is with the bottom boundary.

You can see it here: Snake represented by - ooooo ( length is 5)

Case 1: If we use '>' Comparison

OOOO|O

This is how the game gets over using '>' comparison.

Case 2: If we use '>=' comparison

OOOOO|

Same thing happens with bottom boundary.

Please check it out because the snake can even change its direction near the boundary with '>' comparison.

The last two OR ( || ) cases of 'if' condition at line 87 should have '>=" comparison instead of just '>' comparison. This is because, suppose the length of our snake is 5 boxes and we hit right boundary then as per '>' comparison then game gets over only when 1 box out of snake length (i.e. 5 boxes) crosses that boundary. But if we put '>=' comparison then the game gets over as soon as the snake touches the boundary. Similar case is with the bottom boundary.

You can see it here:  Snake represented by - ooooo ( length is 5)

Case 1: If we use '>' Comparison
|--------------|
|            oooo|o
|                    |
|_____________|
This is how the game gets over using '>' comparison.

Case 2: If we use '>=' comparison
|-------------|
|        ooooo|
|                   |
| ____________|

Same thing happens with bottom boundary.

Please check it out because the snake can even change its direction near the boundary with '>' comparison.
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

Successfully merging this pull request may close these issues.

1 participant