Skip to content
Snippets Groups Projects
Commit 83c2ffe6 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Fix check looped snake

parent e351f1af
No related branches found
No related tags found
1 merge request!23Resolve "Allow move to last current cell"
Pipeline #6986 passed
Fix collision detection.
Correction sur détection de collision.
import 'dart:math';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:snake/models/activity/board.dart';
......@@ -158,8 +160,11 @@ class Activity {
return false;
}
// first snake cell to check (end of tail), after next move
final int start = max(1, snake.cells.length - snake.size);
// check head is not looped on snake body
for (int i = 0; i < snake.cells.length - 1; i++) {
for (int i = start; i < snake.cells.length - 1; i++) {
if (head.col == snake.cells[i].col && head.row == snake.cells[i].row) {
return false;
}
......
......@@ -3,7 +3,7 @@ description: snake game
publish_to: "none"
version: 0.5.3+23
version: 0.5.4+24
environment:
sdk: "^3.0.0"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment