修改高中出题逻辑

develop2
梁晨旭 2 months ago
parent 580270ef9f
commit 287b6c7855

@ -120,27 +120,201 @@ public class ChoiceQuestionGenerator {
*
*/
private Question generateSeniorQuestion(int questionNumber) {
int angle = random.nextInt(360);
// 使用常见角度: 0°, 30°, 45°, 60°, 90°, 120°, 135°, 150°, 180°, 210°, 225°, 270°, 300°, 315°, 330°
int[] commonAngles = {0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 270, 300, 315, 330};
int angle = commonAngles[random.nextInt(commonAngles.length)];
String[] functions = {"sin", "cos", "tan"};
String function = functions[random.nextInt(functions.length)];
String questionText = String.format("%s(%d°) = ?", function, angle);
double result = calculateTrigFunction(function, angle);
int correctAnswer = (int) Math.round(result * 100) / 100; // 保留两位小数
List<Integer> options = generateWrongOptions(correctAnswer);
options.add(correctAnswer);
// 生成选项
List<String> options = generateTrigOptions(result);
// 使用格式化后的值作为正确答案,确保与选项一致
String correctAnswer = formatTrigValue(result);
// 随机打乱选项
Collections.shuffle(options);
return new Question(questionText,
String.valueOf(options.get(0)),
String.valueOf(options.get(1)),
String.valueOf(options.get(2)),
String.valueOf(options.get(3)),
String.valueOf(correctAnswer),
options.get(0),
options.get(1),
options.get(2),
options.get(3),
correctAnswer,
questionNumber);
}
/**
*
*/
private List<String> generateTrigOptions(double correctAnswer) {
List<String> options = new ArrayList<>();
Set<String> usedOptions = new HashSet<>();
// 格式化正确答案,保留适当的小数位数
String formattedCorrectAnswer = formatTrigValue(correctAnswer);
options.add(formattedCorrectAnswer);
usedOptions.add(formattedCorrectAnswer);
// 添加常见三角函数值作为错误选项
String[] commonValues = {"0", "0.5", "0.71", "0.87", "1", "1.73", "-0.5", "-0.71", "-0.87", "-1", "-1.73", "undefined"};
List<String> commonValuesList = new ArrayList<>(Arrays.asList(commonValues));
// 打乱常见值列表
Collections.shuffle(commonValuesList);
// 添加错误选项
int wrongOptionsNeeded = 3;
for (String value : commonValuesList) {
if (wrongOptionsNeeded <= 0) break;
// 确保不添加与正确答案相同的选项
if (!usedOptions.contains(value) && !value.equals(formattedCorrectAnswer)) {
options.add(value);
usedOptions.add(value);
wrongOptionsNeeded--;
}
}
// 如果还需要更多选项,则生成接近正确答案的选项
while (options.size() < 4) {
String wrongOption = generateNearbyValue(correctAnswer, usedOptions);
// 确保新生成的选项不重复且不与正确答案相同
if (!usedOptions.contains(wrongOption) && !wrongOption.equals(formattedCorrectAnswer)) {
options.add(wrongOption);
usedOptions.add(wrongOption);
}
}
return options;
}
/**
*
*/
private String formatTrigValue(double value) {
// 对于特殊值进行精确表示
if (Math.abs(value) < 1e-10) return "0"; // 接近0的值
if (Math.abs(value - 1.0) < 1e-10) return "1";
if (Math.abs(value + 1.0) < 1e-10) return "-1";
if (Math.abs(value - 0.5) < 1e-10) return "0.5";
if (Math.abs(value + 0.5) < 1e-10) return "-0.5";
if (Math.abs(value - Math.sqrt(2)/2) < 1e-10) return "0.71"; // √2/2 ≈ 0.707
if (Math.abs(value + Math.sqrt(2)/2) < 1e-10) return "-0.71";
if (Math.abs(value - Math.sqrt(3)/2) < 1e-10) return "0.87"; // √3/2 ≈ 0.866
if (Math.abs(value + Math.sqrt(3)/2) < 1e-10) return "-0.87";
if (Math.abs(value - Math.sqrt(3)) < 1e-10) return "1.73"; // √3 ≈ 1.732
if (Math.abs(value + Math.sqrt(3)) < 1e-10) return "-1.73";
// 对于tan(90°)等未定义值
if (Double.isInfinite(value) || Double.isNaN(value)) {
return "undefined";
}
// 其他值保留两位小数
return String.format("%.2f", value);
}
/**
*
*/
private String generateNearbyValue(double correctAnswer, Set<String> usedOptions) {
// 对于特殊值直接返回简单值
if (Double.isInfinite(correctAnswer) || Double.isNaN(correctAnswer)) {
return "0";
}
// 生成在正确答案附近的值
double variation = (random.nextDouble() - 0.5) * 2; // -1 到 1 之间的随机数
double wrongAnswer = correctAnswer + variation;
// 格式化生成的值
String formatted = formatTrigValue(wrongAnswer);
// 确保不会生成与已使用选项相同的值最多尝试10次
int attempts = 0;
while (usedOptions.contains(formatted) && attempts < 10) {
variation = (random.nextDouble() - 0.5) * 2;
wrongAnswer = correctAnswer + variation;
formatted = formatTrigValue(wrongAnswer);
attempts++;
}
return formatted;
}
/**
*
*/
private double calculateTrigFunction(String function, int angle) {
double radians = Math.toRadians(angle);
switch (function) {
case "sin":
// 对特定角度返回精确值
switch (angle) {
case 0: return 0;
case 30: return 0.5;
case 45: return Math.sqrt(2)/2;
case 60: return Math.sqrt(3)/2;
case 90: return 1;
case 120: return Math.sqrt(3)/2;
case 135: return Math.sqrt(2)/2;
case 150: return 0.5;
case 180: return 0;
case 210: return -0.5;
case 225: return -Math.sqrt(2)/2;
case 270: return -1;
case 300: return -Math.sqrt(3)/2;
case 315: return -Math.sqrt(2)/2;
case 330: return -0.5;
default: return Math.sin(radians);
}
case "cos":
// 对特定角度返回精确值
switch (angle) {
case 0: return 1;
case 30: return Math.sqrt(3)/2;
case 45: return Math.sqrt(2)/2;
case 60: return 0.5;
case 90: return 0;
case 120: return -0.5;
case 135: return -Math.sqrt(2)/2;
case 150: return -Math.sqrt(3)/2;
case 180: return -1;
case 210: return -Math.sqrt(3)/2;
case 225: return -Math.sqrt(2)/2;
case 270: return 0;
case 300: return 0.5;
case 315: return Math.sqrt(2)/2;
case 330: return Math.sqrt(3)/2;
default: return Math.cos(radians);
}
case "tan":
// 对特定角度返回精确值或未定义
switch (angle) {
case 0: return 0;
case 30: return Math.sqrt(3)/3;
case 45: return 1;
case 60: return Math.sqrt(3);
case 90: return Double.POSITIVE_INFINITY; // 未定义
case 120: return -Math.sqrt(3);
case 135: return -1;
case 150: return -Math.sqrt(3)/3;
case 180: return 0;
case 210: return Math.sqrt(3)/3;
case 225: return 1;
case 270: return Double.POSITIVE_INFINITY; // 未定义
case 300: return -Math.sqrt(3);
case 315: return -1;
case 330: return -Math.sqrt(3)/3;
default: return Math.tan(radians);
}
default: return 0;
}
}
/**
*
*/
@ -181,18 +355,6 @@ public class ChoiceQuestionGenerator {
}
}
/**
*
*/
private double calculateTrigFunction(String function, int angle) {
double radians = Math.toRadians(angle);
switch (function) {
case "sin": return Math.sin(radians);
case "cos": return Math.cos(radians);
case "tan": return Math.tan(radians);
default: return 0;
}
}
/**
*

@ -0,0 +1,2 @@
wgll|123456|ymhlovesLQX@163.com|小学|1760162416490
666|123456789|252436951@qq.com|小学|1760166999971
Loading…
Cancel
Save