Unfortunately, I failed this game jam duo to time restrictions, but I will upload my project when it is finished.
GameJam Johnny
Creator of
Recent community posts
Good job!! As for certain starting positions not working, Warnsdorff's rule doesn't promise they will all work. However, you can fix that using backtracking, which really kicked my ass yesterday to understand how to implement in recursion...
I solved it by using a list of possible moves, with each object containing the coordinates and accessibility, sorting according to accessibility, and trying to solve the tour recursively from each object of the list.
private bool FinishTour(int x, int y, int moveCount) { if (moveCount == N * N) { return true; } List<(int x, int y, int accessibility)> moves = new List<(int, int, int)>(); int nextX; int nextY; int accessibility; for (int i = 0; i < N; i++) { nextX = x + xMove[i]; nextY = y + yMove[i]; if (IsInLimits(nextX, nextY) && IsEmpty(nextX, nextY)) { accessibility = GetAccesibility(nextX, nextY); moves.Add((nextX, nextY, accessibility)); } } moves.Sort((a, b) => a.accessibility.CompareTo(b.accessibility)); foreach (var move in moves) { board[move.x, move.y] = moveCount; if (FinishTour(move.x, move.y, moveCount + 1)) { return true; } else { board[move.x, move.y] = 0; } } return false; }
Honestly, I am still not sure this is a proper use of backtracking, but it works for now...
Let me know if you want an extra set of eyes on your code :)
To research different sorting algorithms - bubble sort, merge sort, etc. and create a game about them / that encompasses them / that has anything to do with the subject. Only if sorting algorithms is something you wish to learn!
If you don't wish to research and incorporate sorting algorithms into your game, it's totally okay. You can take the theme at face value as "sorting" and create a game around what it means to you :)