repochecker: Ensure hint and choice_cost are not higher than gain

This commit is contained in:
nemunaire 2024-03-17 18:10:21 +01:00
parent 09c1111135
commit 7fbe2f3f8e
2 changed files with 20 additions and 6 deletions

View file

@ -555,13 +555,19 @@ func CheckExerciceFlags(i Importer, exercice *fic.Exercice, files []string, exce
}
}
// Check dependency to flag optional flag
if fk, ok := flag.Flag.(*fic.FlagKey); ok && fk.BonusGain == 0 {
for _, nf := range flag.FlagsDeps {
if fk2, ok := flags[nf].Flag.(*fic.FlagKey); ok && fk2.BonusGain != 0 {
errs = multierr.Append(errs, NewFlagError(exercice, nil, flag.Line, fmt.Errorf("flag is not optional but depend on flag id=%d which is optional", nf)))
if fk, ok := flag.Flag.(*fic.FlagKey); ok {
// Check dependency to flag optional flag
if fk.BonusGain == 0 {
for _, nf := range flag.FlagsDeps {
if fk2, ok := flags[nf].Flag.(*fic.FlagKey); ok && fk2.BonusGain != 0 {
errs = multierr.Append(errs, NewFlagError(exercice, nil, flag.Line, fmt.Errorf("flag is not optional but depend on flag id=%d which is optional", nf)))
}
}
}
if int64(fk.ChoicesCost) >= exercice.Gain {
errs = multierr.Append(errs, NewFlagError(exercice, nil, flag.Line, fmt.Errorf("flag's choice_cost is higher than exercice gain")))
}
}
// Check dependency loop