|
|
|
@ -3,12 +3,22 @@ package com.student.mathquiz.question;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
public class HighQuestionGenerator implements QuestionGenerator {
|
|
|
|
public class HighQuestionGenerator implements QuestionGenerator {
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
|
|
|
|
|
|
|
private static final Random RANDOM = new Random();
|
|
|
|
private static final Random RANDOM = new Random();
|
|
|
|
private static final String[] TRIG_FUNCTIONS = {"sin", "cos", "tan"};
|
|
|
|
private static final String[] TRIG_FUNCTIONS = {"sin", "cos", "tan"};
|
|
|
|
private static final Map<String, String> TRIG_VALUES = new HashMap<>();
|
|
|
|
private static final Map<String, String> TRIG_VALUES = new HashMap<>();
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
>>>>>>> develop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Random RANDOM = new Random();
|
|
|
|
|
|
|
|
private static final String[] FUNCTIONS = {"sin", "cos", "tan"};
|
|
|
|
|
|
|
|
private static final Map<String, String> TRIG_EXACT_VALUES = new HashMap<>();
|
|
|
|
|
|
|
|
private final Set<String> seenQuestions = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 静态初始化三角函数精确值表(特殊角)
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
TRIG_VALUES.put("sin30", "1/2");
|
|
|
|
TRIG_VALUES.put("sin30", "1/2");
|
|
|
|
TRIG_VALUES.put("sin45", "√2/2");
|
|
|
|
TRIG_VALUES.put("sin45", "√2/2");
|
|
|
|
TRIG_VALUES.put("sin60", "√3/2");
|
|
|
|
TRIG_VALUES.put("sin60", "√3/2");
|
|
|
|
@ -18,33 +28,113 @@ public class HighQuestionGenerator implements QuestionGenerator {
|
|
|
|
TRIG_VALUES.put("tan30", "√3/3");
|
|
|
|
TRIG_VALUES.put("tan30", "√3/3");
|
|
|
|
TRIG_VALUES.put("tan45", "1");
|
|
|
|
TRIG_VALUES.put("tan45", "1");
|
|
|
|
TRIG_VALUES.put("tan60", "√3");
|
|
|
|
TRIG_VALUES.put("tan60", "√3");
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
// 0°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin0", "0");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos0", "1");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan0", "0");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 15°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin15", "(√6-√2)/4");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos15", "(√6+√2)/4");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan15", "2-√3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 30°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin30", "1/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos30", "√3/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan30", "√3/3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 45°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin45", "√2/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos45", "√2/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan45", "1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 60°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin60", "√3/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos60", "1/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan60", "√3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 75°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin75", "(√6+√2)/4");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos75", "(√6-√2)/4");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan75", "2+√3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 90°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin90", "1");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos90", "0");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan90", null); // 无定义
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 105°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin105", "(√6+√2)/4");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos105", "-(√6-√2)/4");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan105", "-2-√3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 120°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin120", "√3/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos120", "-1/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan120", "-√3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 135°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin135", "√2/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos135", "-√2/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan135", "-1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 150°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin150", "1/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos150", "-√3/2");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan150", "-√3/3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 165°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin165", "(√6-√2)/4");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos165", "-(√6+√2)/4");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan165", "-2+√3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 180°
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("sin180", "0");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("cos180", "-1");
|
|
|
|
|
|
|
|
TRIG_EXACT_VALUES.put("tan180", "0");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 其他角度可以继续补充...
|
|
|
|
|
|
|
|
>>>>>>> develop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Question generateQuestion() {
|
|
|
|
public Question generateQuestion() {
|
|
|
|
return generateTrigQuestion();
|
|
|
|
while (true) {
|
|
|
|
}
|
|
|
|
String func = FUNCTIONS[RANDOM.nextInt(FUNCTIONS.length)];
|
|
|
|
|
|
|
|
int angle = 15 * RANDOM.nextInt(201); // 0° ~ 3000°,步长15°
|
|
|
|
|
|
|
|
int normalizedAngle = angle % 360;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String key = func + normalizedAngle;
|
|
|
|
|
|
|
|
String correctAnswer = TRIG_EXACT_VALUES.get(key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 跳过无定义的角度(如 tan90°)
|
|
|
|
|
|
|
|
if (correctAnswer == null) continue;
|
|
|
|
|
|
|
|
|
|
|
|
private Question generateTrigQuestion() {
|
|
|
|
String content = func + "(" + angle + "°) = ?";
|
|
|
|
String func = TRIG_FUNCTIONS[RANDOM.nextInt(TRIG_FUNCTIONS.length)];
|
|
|
|
if (seenQuestions.contains(content)) continue;
|
|
|
|
String[] angles = {"30", "45", "60"};
|
|
|
|
seenQuestions.add(content);
|
|
|
|
String angle = angles[RANDOM.nextInt(angles.length)];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String content = func + "(" + angle + "°) = ?";
|
|
|
|
List<String> options = generateOptions(correctAnswer);
|
|
|
|
String correctAnswer = TRIG_VALUES.get(func + angle);
|
|
|
|
int correctIndex = shuffleOptions(options, correctAnswer);
|
|
|
|
|
|
|
|
|
|
|
|
List<String> options = generateOptions(correctAnswer);
|
|
|
|
return new Question(content, correctAnswer, options, correctIndex);
|
|
|
|
int correctIndex = shuffleOptions(options, correctAnswer);
|
|
|
|
}
|
|
|
|
return new Question(content, correctAnswer, options, correctIndex);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 生成3个干扰项 + 1个正确答案
|
|
|
|
|
|
|
|
*/
|
|
|
|
private List<String> generateOptions(String correctAnswer) {
|
|
|
|
private List<String> generateOptions(String correctAnswer) {
|
|
|
|
Set<String> options = new HashSet<>();
|
|
|
|
Set<String> options = new HashSet<>();
|
|
|
|
options.add(correctAnswer);
|
|
|
|
options.add(correctAnswer);
|
|
|
|
List<String> allValues = new ArrayList<>(TRIG_VALUES.values());
|
|
|
|
|
|
|
|
|
|
|
|
List<String> allValues = new ArrayList<>(TRIG_EXACT_VALUES.values());
|
|
|
|
while (options.size() < 4) {
|
|
|
|
while (options.size() < 4) {
|
|
|
|
options.add(allValues.get(RANDOM.nextInt(allValues.size())));
|
|
|
|
String wrong = allValues.get(RANDOM.nextInt(allValues.size()));
|
|
|
|
|
|
|
|
if (wrong != null) options.add(wrong);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new ArrayList<>(options);
|
|
|
|
return new ArrayList<>(options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -52,4 +142,15 @@ public class HighQuestionGenerator implements QuestionGenerator {
|
|
|
|
Collections.shuffle(options);
|
|
|
|
Collections.shuffle(options);
|
|
|
|
return options.indexOf(correctAnswer);
|
|
|
|
return options.indexOf(correctAnswer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 一次性生成指定数量的题目
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public List<Question> generateQuestions(int count) {
|
|
|
|
|
|
|
|
List<Question> questions = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
|
|
|
questions.add(generateQuestion());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return questions;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|