mirror of
https://github.com/jaysavsani07/math-metrix.git
synced 2025-08-06 15:11:40 +08:00
Picture puzzle data generation alog change
This commit is contained in:
@ -12,13 +12,13 @@ class PicturePuzzleQandSDataProvider {
|
|||||||
while (list.length < 5) {
|
while (list.length < 5) {
|
||||||
List<PicturePuzzle> puzzleList = List();
|
List<PicturePuzzle> puzzleList = List();
|
||||||
|
|
||||||
List<List<String>> matrix = generateMatrix(level, list.length);
|
// List<List<String>> matrix = generateMatrix(level, list.length);
|
||||||
while (matrix[0][5] == matrix[1][5]) {
|
// while (matrix[0][5] == matrix[1][5]) {
|
||||||
matrix = generateMatrix(level, list.length);
|
// matrix = generateMatrix(level, list.length);
|
||||||
}
|
// }
|
||||||
|
|
||||||
List<PicturePuzzleData> picturePuzzleDataList =
|
List<PicturePuzzleData> picturePuzzleDataList =
|
||||||
getPicturePuzzleData(matrix);
|
generateMatrix1(level, list.length);
|
||||||
picturePuzzleDataList
|
picturePuzzleDataList
|
||||||
.asMap()
|
.asMap()
|
||||||
.forEach((int i, PicturePuzzleData picturePuzzleData) {
|
.forEach((int i, PicturePuzzleData picturePuzzleData) {
|
||||||
@ -87,13 +87,202 @@ class PicturePuzzleQandSDataProvider {
|
|||||||
return picturePuzzleData;
|
return picturePuzzleData;
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<List<String>> generateMatrix(int level, int index) {
|
static List<List<PicturePuzzleShapeType>> getShapeMatrix() {
|
||||||
|
List<List<PicturePuzzleShapeType>> list = List();
|
||||||
|
var shapeList = [
|
||||||
|
PicturePuzzleShapeType.CIRCLE,
|
||||||
|
PicturePuzzleShapeType.SQUARE,
|
||||||
|
PicturePuzzleShapeType.TRIANGLE
|
||||||
|
]..shuffle();
|
||||||
|
list.add([shapeList[0], shapeList[0], shapeList[0]]);
|
||||||
|
shapeList.removeAt(0);
|
||||||
|
while (list.length < 3) {
|
||||||
|
shapeList.shuffle();
|
||||||
|
if (list.length == 1)
|
||||||
|
list.add([shapeList[0], list[0][0], shapeList[0]]..shuffle());
|
||||||
|
else {
|
||||||
|
list.add([shapeList[0], shapeList[1], shapeList[1]]..shuffle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.add([list[0][0], shapeList[0], shapeList[1]]..shuffle());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<PicturePuzzleData> generateMatrix1(int level, int index) {
|
||||||
|
List<List<PicturePuzzleShapeType>> listShape = getShapeMatrix();
|
||||||
|
List<PicturePuzzleData> picturePuzzleData = List();
|
||||||
|
Map<PicturePuzzleShapeType, String> map = Map();
|
||||||
|
|
||||||
|
if (level == 1) {
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
List<String> listDigit = MathUtil.generateRandomNumber(1, 10, 3);
|
||||||
|
|
||||||
|
listShape.forEach((list) {
|
||||||
|
list.asMap().forEach((i, subList) {
|
||||||
|
if (!map.containsKey(subList)) {
|
||||||
|
map[subList] = map.length == 0
|
||||||
|
? listDigit[0]
|
||||||
|
: (map.length == 1 ? listDigit[1] : listDigit[2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
listShape.forEach((list) {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
"+",
|
||||||
|
list[1],
|
||||||
|
"+",
|
||||||
|
list[2],
|
||||||
|
getResult(map[list[0]], "+", map[list[1]], "+", map[list[2]])));
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
List<String> listDigit = MathUtil.generateRandomNumber(1, 10, 3);
|
||||||
|
List<String> listSign = ["+", "-", "*"]
|
||||||
|
..shuffle()
|
||||||
|
..removeAt(1);
|
||||||
|
|
||||||
|
listShape.forEach((list) {
|
||||||
|
list.asMap().forEach((i, subList) {
|
||||||
|
if (!map.containsKey(subList)) {
|
||||||
|
map[subList] = map.length == 0
|
||||||
|
? listDigit[0]
|
||||||
|
: (map.length == 1 ? listDigit[1] : listDigit[2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
listShape.forEach((list) {
|
||||||
|
if (list[0] == list[1] &&
|
||||||
|
list[1] == list[2] &&
|
||||||
|
list[2] == list[1]) {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
"+",
|
||||||
|
list[1],
|
||||||
|
"+",
|
||||||
|
list[2],
|
||||||
|
getResult(
|
||||||
|
map[list[0]], "+", map[list[1]], "+", map[list[2]])));
|
||||||
|
} else if (list[0] != list[1] &&
|
||||||
|
list[1] != list[2] &&
|
||||||
|
list[2] != list[1]) {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
"+",
|
||||||
|
list[1],
|
||||||
|
"+",
|
||||||
|
list[2],
|
||||||
|
getResult(
|
||||||
|
map[list[0]], "+", map[list[1]], "+", map[list[2]])));
|
||||||
|
} else if (listSign.length == 2) {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
listSign[0],
|
||||||
|
list[1],
|
||||||
|
"+",
|
||||||
|
list[2],
|
||||||
|
getResult(map[list[0]], listSign[0], map[list[1]], "+",
|
||||||
|
map[list[2]])));
|
||||||
|
listSign.removeAt(0);
|
||||||
|
} else {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
listSign[0],
|
||||||
|
list[1],
|
||||||
|
"-",
|
||||||
|
list[2],
|
||||||
|
getResult(map[list[0]], listSign[0], map[list[1]], "-",
|
||||||
|
map[list[2]])));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
List<String> listDigit = List();
|
||||||
|
while (listDigit.length < 3) {
|
||||||
|
MathUtil.generateRandomNumber(level, 10 + level, 3).forEach((digit) {
|
||||||
|
if (!listDigit.contains(digit)) {
|
||||||
|
listDigit.add(digit);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> listSign = ["+", "-", "*"]..shuffle();
|
||||||
|
|
||||||
|
listShape.forEach((list) {
|
||||||
|
list.asMap().forEach((i, subList) {
|
||||||
|
if (!map.containsKey(subList)) {
|
||||||
|
map[subList] = map.length == 0
|
||||||
|
? listDigit[0]
|
||||||
|
: (map.length == 1 ? listDigit[1] : listDigit[2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
listShape.forEach((list) {
|
||||||
|
if (list[0] == list[1] && list[1] == list[2] && list[2] == list[1]) {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
listSign[0],
|
||||||
|
list[1],
|
||||||
|
listSign[2],
|
||||||
|
list[2],
|
||||||
|
getResult(map[list[0]], listSign[0], map[list[1]], listSign[2],
|
||||||
|
map[list[2]])));
|
||||||
|
} else if (list[0] != list[1] &&
|
||||||
|
list[1] != list[2] &&
|
||||||
|
list[2] != list[1]) {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
listSign[0],
|
||||||
|
list[1],
|
||||||
|
listSign[1],
|
||||||
|
list[2],
|
||||||
|
getResult(map[list[0]], listSign[0], map[list[1]], listSign[1],
|
||||||
|
map[list[2]])));
|
||||||
|
} else if (listSign.length == 3) {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
listSign[0],
|
||||||
|
list[1],
|
||||||
|
"+",
|
||||||
|
list[2],
|
||||||
|
getResult(
|
||||||
|
map[list[0]], listSign[0], map[list[1]], "+", map[list[2]])));
|
||||||
|
listSign.removeAt(0);
|
||||||
|
} else {
|
||||||
|
picturePuzzleData.add(PicturePuzzleData(
|
||||||
|
list[0],
|
||||||
|
listSign[0],
|
||||||
|
list[1],
|
||||||
|
"-",
|
||||||
|
list[2],
|
||||||
|
getResult(
|
||||||
|
map[list[0]], listSign[0], map[list[1]], "-", map[list[2]])));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return picturePuzzleData;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getResult(
|
||||||
|
String op1, String sign1, String op2, String sign2, String op3) {
|
||||||
|
return "${(MathUtil.getPrecedence(sign1) >= MathUtil.getPrecedence(sign2)) ? (MathUtil.evaluate(MathUtil.evaluate(int.parse(op1), sign1, int.parse(op2)), sign2, int.parse(op3))) : (MathUtil.evaluate(int.parse(op1), sign1, MathUtil.evaluate(int.parse(op2), sign2, int.parse(op3))))}";
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<List<String>> generateMatrix(int level, int index) {
|
||||||
|
List<List<PicturePuzzleShapeType>> listShape = getShapeMatrix();
|
||||||
if (level == 1) {
|
if (level == 1) {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
List<String> listDigit = MathUtil.generateRandomNumber(1, 10, 3);
|
List<String> listDigit = MathUtil.generateRandomNumber(1, 10, 3);
|
||||||
List<String> listSign = MathUtil.generateRandomSign1(2);
|
|
||||||
|
|
||||||
var tempList = [
|
var tempList = [
|
||||||
listDigit[0],
|
listDigit[0],
|
||||||
@ -259,18 +448,11 @@ class PicturePuzzleQandSDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
for (int j = 1; j < 5; j++) {
|
for (int j = 1; j < 3; j++) {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
List<List<String>> matrix =
|
var matrix = PicturePuzzleQandSDataProvider.generateMatrix1(j, i);
|
||||||
PicturePuzzleQandSDataProvider.generateMatrix(j, i);
|
|
||||||
while (matrix[0][5] == matrix[1][5] ||
|
|
||||||
matrix[0][5] == matrix[2][5] ||
|
|
||||||
matrix[1][5] == matrix[2][5]) {
|
|
||||||
matrix = PicturePuzzleQandSDataProvider.generateMatrix(j, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
print(matrix);
|
print(matrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// print(PicturePuzzleQandSDataProvider.getPicturePuzzleDataList(1));
|
// print(PicturePuzzleQandSDataProvider.getShapeMatrix());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user