Skip to content

Commit

Permalink
Check thar game works correctly and added the monument to the game
Browse files Browse the repository at this point in the history
  • Loading branch information
UO277274 committed Apr 6, 2024
1 parent 2c87c92 commit a5898f5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
28 changes: 19 additions & 9 deletions game/qgservice/QGController.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { generateQuestionPopulation, generateQuestionCapital, generateQuestionChemical } = require('./generatorLogic/questiongenerator');
const { generateQuestionPopulation, generateQuestionCapital, generateQuestionChemical, generateQuestionMonument } = require('./generatorLogic/questiongenerator');
const Question4Answers = require('./Question4Answers');
const { executeSparqlQuery } = require('./generatorLogic/SparqlQuery')
const { bindCapitalsResults, bindPopulationResults } = require('./generatorLogic/BindResults')
const { spainCapitalQuery, worldCapitalQuery, worldPopulationQuery, chemicalElementQuery } = require('./generatorLogic/queries')
const { bindCapitalsResults, bindPopulationResults, bindChemicalResults, bindMonumentResults } = require('./generatorLogic/BindResults')
const { spainCapitalQuery, worldCapitalQuery, worldPopulationQuery, chemicalElementQuery, monumentQuery } = require('./generatorLogic/queries')
const { createMathQuestions } = require('./generatorLogic/MathQuestions')

let QGController = {
Expand All @@ -12,7 +12,7 @@ let QGController = {
const questions = [];

// spain capitals
nQuestions = 2;
nQuestions = 3;
const spainQueryResult = await executeSparqlQuery(spainCapitalQuery);
const spainCapitals = bindCapitalsResults(spainQueryResult)

Expand All @@ -22,7 +22,7 @@ let QGController = {
}

// world capitals
nQuestions = 3;
nQuestions = 2;
const worldQueryResult = await executeSparqlQuery(worldCapitalQuery);
const worldCapitals = bindCapitalsResults(worldQueryResult)

Expand All @@ -42,17 +42,27 @@ let QGController = {
}

// chemical elements
nQuestions = 3;
const chemicalResult = await executeSparqlQuery(chemicalElementQueryQuery);
const chemicalElement = bindCapitalsResults(chemicalResult)
nQuestions = 2;
const chemicalResult = await executeSparqlQuery(chemicalElementQuery);
const chemicalElement = bindChemicalResults(chemicalResult)

for (let i = 0; i < nQuestions; i++) {
const question = generateQuestionChemical(chemicalElement);
questions.push(question);
}

// monuments
nQuestions = 2;
const monumentResult = await executeSparqlQuery(monumentQuery);
const monument = bindMonumentResults(monumentResult)

for (let i = 0; i < nQuestions; i++) {
const question = generateQuestionMonument(monument);
questions.push(question);
}

// math questions
const mathquestions = await createMathQuestions(5)
const mathquestions = await createMathQuestions(3)
questions.push(...mathquestions)

res.json(questions);
Expand Down
4 changes: 2 additions & 2 deletions game/qgservice/generatorLogic/BindResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function bindChemicalResults(queryResult){

queryResult.results.bindings.forEach(entry => {
const elementLabel = entry.elementLabel.value;
const symbol = parseFloat(entry.symbol.value);
const symbol = entry.symbol.value;
chemicalElementMap.set(symbol, elementLabel);
});

Expand All @@ -41,7 +41,7 @@ function bindMonumentResults(queryResult){

queryResult.results.bindings.forEach(entry => {
const monumentLabel = entry.monumentLabel.value;
const countryLabel = parseFloat(entry.countryLabel.value);
const countryLabel = entry.countryLabel.value;
monumentMap.set(monumentLabel, countryLabel);
});

Expand Down
2 changes: 1 addition & 1 deletion game/qgservice/generatorLogic/questiongenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function generateQuestionMonument(monumentMap) {
const randomMonument = monumentArray[Math.floor(Math.random() * monumentArray.length)];
const [randomMonumentLabel, randomCountry] = randomMonument;
if (randomMonumentLabel !== monumentLabel && !incorrectAnswers.includes(randomCountry)) {
incorrectAnswers.push(random);
incorrectAnswers.push(randomCountry);
}
}

Expand Down

0 comments on commit a5898f5

Please sign in to comment.