Package com.music.web.websocket.dto

Examples of com.music.web.websocket.dto.PossibleAnswers


        Piece piece = pieceService.getPiece(pieceId);
        pieces.add(piece);
        currentPieceId = pieceId;
        fillCurrentCorrectAnswer(piece);

        PossibleAnswers possibleAnswers = generatePossibleAnswers(piece);
        possibleAnswersHistory.put(piece, possibleAnswers);

        for (Player player : players.values()) {
            player.sendNextPiece(pieceId, possibleAnswers, SECONDS);
        }
View Full Code Here


            }
        }
    }

    private PossibleAnswers generatePossibleAnswers(Piece piece) {
        PossibleAnswers answers = new PossibleAnswers();

        // first select the instrument distractors
        int instrument = piece.getMainInstrument();
        List<Instrument> instruments = new ArrayList<>(ANSWERS_PER_QUESTION);
        instruments.add(new Instrument(instrument, InstrumentNameExtractor.getInstrumentName(instrument)));
        while (instruments.size() < ANSWERS_PER_QUESTION) {
            int[] set = random.nextBoolean() ? InstrumentGroups.MAIN_PART_INSTRUMENTS : InstrumentGroups.MAIN_PART_ONLY_INSTRUMENTS;
            int selectedId = set[random.nextInt(set.length)];
            Instrument newInstrument = new Instrument(selectedId, InstrumentNameExtractor.getInstrumentName(selectedId));
            if (selectedId != instrument && !instruments.contains(newInstrument)) {
                instruments.add(newInstrument);
            }
        }
        Collections.shuffle(instruments, random);

        answers.setInstruments(instruments);

        // fill the metre distractors
        List<Metre> metres = new ArrayList<>(ANSWERS_PER_QUESTION);
        metres.add(new Metre(piece.getMetreNumerator(), piece.getMetreDenominator()));
        while (metres.size() < ANSWERS_PER_QUESTION) {
            int[] metre = MetreConfigurer.getRandomMetre(random);
            // disallow metres that have the same ratios as the correct answer
            Metre newMetre = new Metre(metre[0], metre[1]);
            if (!metres.contains(newMetre) && isNotDerivedMetre(piece, metre)) {
                metres.add(newMetre);
            }
        }
        Collections.shuffle(metres, random);

        answers.setMetres(metres);
        return answers;
    }
View Full Code Here

TOP

Related Classes of com.music.web.websocket.dto.PossibleAnswers

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.