Flood-it
By Omar Essilfie-Quaye
Game Settings
The Game
The game is simple select a color and watch it spread out from the top left corner of the board. Figure out how to make the entire board fill up with one color before you run out of clicks. This project is inspired by unixpapa. Good Luck!!!
Flood Fill Algorithm
The flood fill algorithm starts from a seed location and spreads to find all the areas connected to the starting point. The algorithm takes three parameters: the starting point, a target color and a replacement color. The algorithm makes the following steps:
// JS Pseudo Code for the flood fill algorithm
function floodFill(startNode, targetColor, newColor) {
if(startNode.color != targetColor) { return; }
let frontierNodes = [startNode];
while(frontierNodes.length > 0) {
// using the array as a queue and getting the first element of the array
// makes the flood fill act like a breadth first search
//
// using the array as a stack and getting the last element of the array
// makes the flood fill act like a depth first search
let nextNode = frontierNodes.shift(); // Gets first element (BFS)
if(nextNode.color == targetColor) {
nextNode.color = newColor;
frontierNodes.push(nextNode.neighbors);
}
}
};