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

@ -6,8 +6,8 @@ import (
"time"
)
// UnlockedChallenges disables dependancy requirement between challenges.
var UnlockedChallenges bool
// UnlockedChallengeDepth is the number of challenges to unlock ahead (0: only the next one, -1: all)
var UnlockedChallengeDepth int
// WchoiceCoefficient is the current coefficient applied on the cost of changing flag into choices
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.
func (t Team) HasAccess(e Exercice) bool {
if e.Depend == nil || UnlockedChallenges {
if UnlockedChallengeDepth < 0 {
return true
} else {
}
for i := UnlockedChallengeDepth; i >= 0; i-- {
// An exercice without dependency is accessible
if e.Depend == nil {
return true
}
ed := Exercice{}
ed.Id = *e.Depend
s, _ := t.HasSolved(ed)
return s
if 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.