Algorithm Game Introduction
The primary goal of this site is efficiency, aiming for readers to quickly master algorithms and succeed in interviews and written tests.
On this basis, I also hope to make the learning process as interesting as possible. Simply practicing problems for interview preparation can be somewhat dull.
If readers can intuitively feel the charm of algorithms and genuinely view learning algorithms as an exploratory process, it can generate intrinsic motivation, not only improving learning efficiency but also adding a bit of fun.
Finding a job these days can be quite exhausting, and algorithm challenges have become almost a requirement for all technical positions, so why not make it more enjoyable?
After research, I believe combining algorithm learning with gaming is a great approach. Not only is it interesting, but it also allows readers to understand the application of algorithms in real-world scenarios, achieving two goals with one effort.
Gamification vs. Visualization
With the Visualization Dashboard, why still need algorithm games?
I have thought about this question and believe it's necessary because they solve different problems.
The algorithm visualization dashboard answers questions like: What is the execution process of this code? Why should this variable n
be incremented by +1 instead of +2?
Algorithm games answer questions like: In which real-world scenarios can this algorithm be considered? How to use it?
Therefore, in the game scenarios I design, it's not simply about visualizing algorithms, but combining them with game scenarios, requiring players to flexibly combine data structures and algorithms to complete tasks, highlighting the role of algorithms in the game.
Below is a brief introduction on how to use the game's dashboard on this site.
How to Use the Game Dashboard
In the top-right corner of the dashboard, there is a full-screen
The left side of the panel is the game interface, the upper right is the problem description, and the lower right is the code editor. You need to write code in the editor to meet the problem requirements, then click the "Submit" button to run the code with the game engine. You can interact with the game to check if it meets expectations.
Below is a "Snake" game panel. After clicking the "Begin" button to start the game, the snake will not move because this problem examines the practical application of doubly linked lists, requiring you to complete the snake's movement logic.
You need to write the correct algorithm in the code editor to move the snake, click the "Submit" button to submit the code to the game engine, and finally click the "Begin" button; the game will run normally, thus creating a playable mini-game:
Snake Game Demo
Reference Solution:
var move = function(snake, direction, foodPosition) {
const currentHead = snake.getFirst()
// Calculate new head position
const newHeadPos = new Point(currentHead.x, currentHead.y)
switch (direction) {
case 'right':
newHeadPos.x += 1
break
case 'left':
newHeadPos.x -= 1
break
case 'up':
newHeadPos.y += 1
break
case 'down':
newHeadPos.y -= 1
break
default:
throw new Error('Invalid direction')
}
// Add new head node
snake.addFirst(newHeadPos)
if (!newHeadPos.equals(foodPosition)) {
// Remove tail node if not eating food
snake.removeLast()
}
}
Game Collection
Game chapters are scattered throughout the site (marked with
Game features are still in beta. I have many interesting ideas, but only some are online now. More fun games are coming soon.
Snake Game
Tests practical application of doubly linked lists. For details, see Implementing the Snake Game:
Snake Game
Huarong Road
The Huarong Road puzzle is a more advanced problem of the BFS Algorithm Framework. It is very interesting, and you are encouraged to turn on the game BGM while solving it. For solution details, see Implementing Huarong Road Game:
Huarong Road Game
Connect Two
The Connect Two game tests your understanding of the BFS algorithm. For details, see Implementing Connect Two Game:
Connect Two Game
Minesweeper Game
The Minesweeper game involves several algorithms.
First, it requires knowledge of random algorithms, including shuffle and reservoir sampling. For details, see Implementing Minesweeper Game:
Minesweeper Game
Monte Carlo methods are commonly used to test the uniformity of random algorithms. The site provides a Monte Carlo validator, where you can test the random algorithm used to generate the minesweeper map:
Monte Carlo Validator
Minesweeper can also be used to practice DFS algorithms. For details, see Implementing Minesweeper II:
Minesweeper II
You can also think about how to write an algorithm to solve Minesweeper automatically, creating a "Minesweeper Solver":
Minesweeper Solver
Sudoku Game
Use backtracking algorithms to solve Sudoku puzzles of any difficulty. For details, see Implementing Sudoku Game: