-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cria funcionalidade que permite adicionar goleiros #25
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No geral foi topster, só alguns detalhes mesmo
} | ||
|
||
companion object { | ||
private val IS_GOAL_KEEPER_TOOL_TIP_VISIBLE = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pode ser top level tbm, não precisa ser uma companion, mesmo sendo private.
.filter { it.isGoalKeeper } | ||
.shuffled() | ||
.toMutableList() | ||
val onlyPlayers = if (isBalancedTeam) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Da pra deixar em uma call só
players.filter { !it.isGoalKeeper }
.run {
if (isBalanced) {
this.sortedByDescending { it.level }
} else {
this.shuffled()
}
}.toMutableList()
} | ||
val totalOfGoalKeepers = onlyGoalKeepers.size | ||
val totalOfTeams: Int = players.size / playersPerTeam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
É necessário fazer o ajuste para que considere times que não todos os jogadores, como é o caso do ceil(players.size / playersPerTeam.toFloat()).toInt()
. Sem isso, casos como: 16 jogadores com 6 jogadores por time, vai indicar que só vai ter 2 times sendo que precisa ser 3, 2 times com 6 e 1 time com 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fiz dessa forma para caso não haja uma quantidade suficiente de goleiros, jogadores possam ser adicionados nos times incompletos.
Caso eu arrendode a quantidades de times para cima, todos os jogadores da lista serão consumidos, impossibilitando-os de serem adicionados nos times incompletos.
No final do método verifico se ainda há jogadores restantes e os adiciono para um novo time.
val totalOfTeams: Int = players.size / playersPerTeam | ||
val teams: MutableList<MutableList<Player>> = | ||
MutableList(totalOfTeams) { mutableListOf() } | ||
var firstTeamWithoutGoalKeeper = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare a variável apenas quando for usar. Se for o caso, extraia esse código para uma função responsável apenas para criar os times sem goleiro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A variável firstTeamWithoutGoalKeeper é utilizado no momento da criação dos times para saber qual vai ser o primeiro time sem goleiro e então adicionar um jogador para completar o time.
teamsWithBestPlayersIncluded.forEach { | ||
if (sortedPlayers.isEmpty()) { | ||
return@forEach | ||
// add players to the teams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remova o comentário, deixe comentários apenas para documentar código ou para explicação de código complexo
return@forEach | ||
// add players to the teams | ||
if (teams.isNotEmpty()) { | ||
for (current in 0 until playersPerTeam - 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
para não ter que lidar com isso, to pensando em colocar deixar a compreensão da quantidade de jogadores apenas para jogadores e os goleiros entra como um jogador que não conta... O que acha? Pq vai ficar estranho os times com '5 jogadores' sendo que só tem 4 kkkkkk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Irei fazer essa modificação, tinha considerado que no momento de definição da quantidade de jogadores em um time, estivesse contando com o goleiro.
} | ||
} | ||
|
||
// when the player list has only one goalkeeper, add the remaining players to the teams without goalkeepers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remover aqui
if (onlyGoalKeepers.isNotEmpty()) { | ||
teams.last().add(0, onlyGoalKeepers.removeFirst()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entendi, você faz as etapas depois... São mais passos que estão sendo executados, mas é uma solução válida! Acho que daria pra fazer tudo no código anterior que comentei. Sugestão para evitar os comentários que fez é extrair para funções privadas
val playersPerTeam = 4 | ||
var drawnTeams = | ||
teamDrawer.drawRandomTeams(players = players, playersPerTeam = playersPerTeam) | ||
drawnTeams.last().size shouldNotBeEqualTo playersPerTeam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nesse caso aqui não deveria ser 3 times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considerando que um jogador será inserido como goleiro (já que não há goleiros na lista), ficaria um time com 5 jogadores e outro com 4.
players = generatePlayers(11) | ||
drawnTeams = | ||
teamDrawer.drawBalancedTeams(players = players, playersPerTeam = playersPerTeam) | ||
drawnTeams.last().size shouldNotBeEqualTo playersPerTeam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aqui deveria ser 3 times tbm, não?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mesmo caso do teste acima.
No description provided.