libfic: new way to handle exercice dependancies

This commit is contained in:
nemunaire 2019-01-17 12:03:56 +01:00
parent c5f8288f39
commit 8e6b8829ea
3 changed files with 33 additions and 8 deletions

View file

@ -51,7 +51,11 @@ func saveSettings(_ httprouter.Params, body []byte) (interface{}, error) {
func ApplySettings(config settings.FICSettings) { func ApplySettings(config settings.FICSettings) {
fic.PartialValidation = config.PartialValidation fic.PartialValidation = config.PartialValidation
fic.UnlockedChallenges = !config.EnableExerciceDepend if config.EnableExerciceDepend {
fic.UnlockedChallengeDepth = 0
} else {
fic.UnlockedChallengeDepth = -1
}
fic.FirstBlood = config.FirstBlood fic.FirstBlood = config.FirstBlood
fic.SubmissionCostBase = config.SubmissionCostBase fic.SubmissionCostBase = config.SubmissionCostBase
fic.HintCoefficient = config.HintCurCoefficient fic.HintCoefficient = config.HintCurCoefficient

View file

@ -49,9 +49,13 @@ var skipInitialGeneration = false
func reloadSettings(config settings.FICSettings) { func reloadSettings(config settings.FICSettings) {
fic.HintCoefficient = config.HintCurCoefficient fic.HintCoefficient = config.HintCurCoefficient
fic.WChoiceCoefficient = config.WChoiceCurCoefficient fic.WChoiceCoefficient = config.WChoiceCurCoefficient
if lastRegeneration != config.Generation || fic.PartialValidation != config.PartialValidation || fic.UnlockedChallenges != !config.EnableExerciceDepend || fic.FirstBlood != config.FirstBlood || fic.SubmissionCostBase != config.SubmissionCostBase || fic.SubmissionUniqueness != config.SubmissionUniqueness { if lastRegeneration != config.Generation || fic.PartialValidation != config.PartialValidation || fic.FirstBlood != config.FirstBlood || fic.SubmissionCostBase != config.SubmissionCostBase || fic.SubmissionUniqueness != config.SubmissionUniqueness {
fic.PartialValidation = config.PartialValidation fic.PartialValidation = config.PartialValidation
fic.UnlockedChallenges = !config.EnableExerciceDepend if config.EnableExerciceDepend {
fic.UnlockedChallengeDepth = 0
} else {
fic.UnlockedChallengeDepth = -1
}
fic.FirstBlood = config.FirstBlood fic.FirstBlood = config.FirstBlood
fic.SubmissionCostBase = config.SubmissionCostBase fic.SubmissionCostBase = config.SubmissionCostBase

View file

@ -6,8 +6,8 @@ import (
"time" "time"
) )
// UnlockedChallenges disables dependancy requirement between challenges. // UnlockedChallengeDepth is the number of challenges to unlock ahead (0: only the next one, -1: all)
var UnlockedChallenges bool var UnlockedChallengeDepth int
// WchoiceCoefficient is the current coefficient applied on the cost of changing flag into choices // WchoiceCoefficient is the current coefficient applied on the cost of changing flag into choices
var WChoiceCoefficient = 1.0 var WChoiceCoefficient = 1.0
@ -99,14 +99,31 @@ func (t Team) Delete() (int64, error) {
// HasAccess checks if the Team has access to the given challenge. // HasAccess checks if the Team has access to the given challenge.
func (t Team) HasAccess(e Exercice) bool { func (t Team) HasAccess(e Exercice) bool {
if e.Depend == nil || UnlockedChallenges { if UnlockedChallengeDepth < 0 {
return true return true
} else { }
for i := UnlockedChallengeDepth; i >= 0; i-- {
// An exercice without dependency is accessible
if e.Depend == nil {
return true
}
ed := Exercice{} ed := Exercice{}
ed.Id = *e.Depend ed.Id = *e.Depend
s, _ := t.HasSolved(ed) s, _ := t.HasSolved(ed)
if s {
return s return s
} }
// Prepare next iteration
var err error
e, err = GetExercice(ed.Id)
if err != nil {
return false
}
}
return false
} }
// CanDownload checks if the Team has access to the given file. // CanDownload checks if the Team has access to the given file.