<commit_before>package beans;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * Class that represents a point ("tento") of the game.
 * @author <NAME> @lucaspin
 * @author <NAME> @bleandro
 * @author <NAME> @daltonbr
 */
public class Point {
    private boolean ended = false;
    private List<Round> rounds = new ArrayList<>();
    private Player dealer;
    private Player winner;
    private PointValue pointValue;

    /**
     * Constructor of the class
     */
    public Point(List<Player> playersInOrder) {
        this.setDealer(playersInOrder.get(0));
        this.setPointValue(PointValue.ONE);
        this.initPoint(playersInOrder);
    }

    /**
     * Init a point flow
     * @param playersInOrder {List<Player>}
     */
    private void initPoint(List<Player> playersInOrder) {
        this.createRounds();

        while (!this.isEnded()) {
            ListIterator<Round> it = this.rounds.listIterator();

            // TODO: add logic to treat tie cases and others
            while (it.hasNext() && !this.isEnded()) {
                /* We order the players in the order they should play in the next round.
                   In order to do this, we must get the winner from the last round,
                   and set it as the first one of the list. For the first round, we just
                   pass the players as they come. Also, we just do this reordering if the round
                   is not the first one.
                 */
                if (it.nextIndex() != 0) {
                    int previousIndex = it.previousIndex();
                    Round previousRound = this.rounds.get(previousIndex);
                    playersInOrder = this.orderPlayers(playersInOrder, previousRound.getWinner());
                }

                Round nextRound = it.next();
                nextRound.setPlayersInOrder(playersInOrder);
                nextRound.initRound();

                Player nextRoundWinner = nextRound.getWinner();

                /* Check if some player's has won this point by
                   winning two rounds in a row */
                if (nextRoundWinner.getRoundScore() == GameController.EARLY_WIN_ROUND_SCORE) {
                    nextRoundWinner.increaseGameScore(this.pointValue.getValue());
                    this.setWinner(nextRoundWinner);
                    this.setEnded(true);
                }
            }

            // We end the point when all round has been played
            this.setEnded(true);
        }
    }

    /**
     * Order the players setting the last round winner as the
     * start player of the next round.
     * @param players {List<Player>}
     * @param firstPlayer {Player}
     * @return {List<Player>}
     */
    private List<Player> orderPlayers(List<Player> players, Player firstPlayer) {
        List<Player> newPlayers = new ArrayList<>();
        newPlayers.add(firstPlayer);
        ListIterator<Player> it = players.listIterator();

        if (it.hasNext()) {
            Player nextPlayer = it.next();
            if (nextPlayer.getName().equals(firstPlayer.getName())) {
                it.remove();
            } else {
                newPlayers.add(nextPlayer);
            }
        }

        return newPlayers;
    }
<commit_msg>Fix ordering of players before start another round<commit_after>package beans;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * Class that represents a point ("tento") of the game.
 * @author <NAME> @lucaspin
 * @author <NAME> @bleandro
 * @author <NAME> @daltonbr
 */
public class Point {
    private boolean ended = false;
    private List<Round> rounds = new ArrayList<>();
    private Player dealer;
    private Player winner;
    private PointValue pointValue;

    /**
     * Constructor of the class
     */
    public Point(List<Player> playersInOrder) {
        this.setDealer(playersInOrder.get(0));
        this.setPointValue(PointValue.ONE);
        this.initPoint(playersInOrder);
    }

    /**
     * Init a point flow
     * @param playersInOrder {List<Player>}
     */
    private void initPoint(List<Player> playersInOrder) {
        this.createRounds();

        while (!this.isEnded()) {
            ListIterator<Round> it = this.rounds.listIterator();

            // TODO: add logic to treat tie cases and others
            while (it.hasNext() && !this.isEnded()) {
                /* We order the players in the order they should play in the next round.
                   In order to do this, we must get the winner from the last round,
                   and set it as the first one of the list. For the first round, we just
                   pass the players as they come. Also, we just do this reordering if the round
                   is not the first one.
                 */
                if (it.nextIndex() != 0) {
                    int previousIndex = it.previousIndex();
                    Round previousRound = this.rounds.get(previousIndex);
                    playersInOrder = this.orderPlayers(playersInOrder, previousRound.getWinner());
                }

                Round nextRound = it.next();
                nextRound.setPlayersInOrder(playersInOrder);
                nextRound.initRound();

                Player nextRoundWinner = nextRound.getWinner();

                /* Check if some player's has won this point by
                   winning two rounds in a row */
                if (nextRoundWinner.getRoundScore() == GameController.EARLY_WIN_ROUND_SCORE) {
                    nextRoundWinner.increaseGameScore(this.pointValue.getValue());
                    this.setWinner(nextRoundWinner);
                    this.setEnded(true);
                }
            }

            // We end the point when all round has been played
            this.setEnded(true);
        }
    }

    /**
     * Order the players setting the last round winner as the
     * start player of the next round.
     * @param players {List<Player>}
     * @param firstPlayer {Player}
     * @return {List<Player>}
     */
    private List<Player> orderPlayers(List<Player> players, Player firstPlayer) {
        List<Player> newPlayers = new ArrayList<>();
        newPlayers.add(firstPlayer);

        for (Player player : players) {
            if (!player.getName().equals(firstPlayer.getName())) {
                newPlayers.add(player);
            }
        }

        return newPlayers;
    }

{'fraction_non_alphanumeric': 0.09566814633399663, 'fraction_numerical': 0.0006122761365375785, 'mean_word_length': 1.9027099067081297, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5692218', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1664, 'n_words': 509}