I have a 2 dimensional array that stores pattern information. The data may look something like this:
var testGrid = [["blank", "red", "blank"],
/* row 2 */ ["blank", "yellow", "green"],
/* row 3 */ ["blank", "blue", "blank"]];
The max pattern size is a 3 by 3 grid, however, not all spaces have to be used. Since blanks basically mean that there is no information there, I regularly encounter scenarios where two patterns are structured differently, but are functionally the same. Like this:
[["red", "red" "blank"],
["red", "red", "blank"],
["blank", "blank", "blank"]
[["blank", "blank", "blank"],
["blank", "red", "red"],
["blank", "red", "red"]]
All patterns would have 4 possible representations due to orientation. However, some patterns like this one below:
[["blank", "blank", "blank"],
["blank", "yellow", "green"],
["blank", "blue", "blank"]]
would have 8 possible representations in a 3 by 3 grid.
So I have a few questions:
-
What would be the best way to store this data? I was thinking I could store the more simple patterns as a 2 by 2 grid, which would reduce the amount of checks I would have to do on those to the normal 4.
-
What is the best way to check against patterns already in the database? Just loop through a function that compares the newly created pattern to every other entry in the database? (I'm using a mongoDB by the way).
Aucun commentaire:
Enregistrer un commentaire