MCPcopy
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / getRandomGrid

Function getRandomGrid

assets/js/15puzzle.js:69–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67};
68
69const getRandomGrid = () => {
70 let grid = [
71 [1, 2, 3, 4],
72 [5, 6, 7, 8],
73 [9, 10, 11, 12],
74 [13, 14, 15, 0],
75 ];
76
77 //Shuffle
78 let blankBox = new Box(3, 3);
79 for (let i = 0; i < 1000; i++) {
80 const randomNextdoorBox = blankBox.getRandomNextdoorBox();
81 swapBoxes(grid, blankBox, randomNextdoorBox);
82 blankBox = randomNextdoorBox;
83 }
84
85 if (isSolved(grid)) return getRandomGrid();
86 return grid;
87};
88
89class State {
90 constructor(grid, move, time, status) {

Callers 1

startMethod · 0.85

Calls 3

getRandomNextdoorBoxMethod · 0.95
swapBoxesFunction · 0.85
isSolvedFunction · 0.85

Tested by

no test coverage detected