settings: add coefficient to hint and wchoices

This commit is contained in:
nemunaire 2019-01-17 12:03:18 +01:00
commit c5f8288f39
10 changed files with 43 additions and 13 deletions

View file

@ -314,6 +314,7 @@ CREATE TABLE IF NOT EXISTS team_hints(
id_team INTEGER,
id_hint INTEGER,
time TIMESTAMP NOT NULL,
coefficient FLOAT NOT NULL DEFAULT 1.0,
CONSTRAINT uc_displayed UNIQUE (id_team,id_hint),
FOREIGN KEY(id_hint) REFERENCES exercice_hints(id_hint),
FOREIGN KEY(id_team) REFERENCES teams(id_team)
@ -326,6 +327,7 @@ CREATE TABLE IF NOT EXISTS team_wchoices(
id_team INTEGER,
id_flag INTEGER,
time TIMESTAMP NOT NULL,
coefficient FLOAT NOT NULL DEFAULT 1.0,
CONSTRAINT uc_displayed UNIQUE (id_team,id_flag),
FOREIGN KEY(id_flag) REFERENCES exercice_flags(id_flag),
FOREIGN KEY(id_team) REFERENCES teams(id_team)

View file

@ -5,6 +5,9 @@ import (
"strings"
)
// HintCoefficient is the current coefficient applied on its cost lost per showing
var HintCoefficient = 1.0
// EHint represents a challenge hint.
type EHint struct {
Id int64 `json:"id"`

View file

@ -30,8 +30,8 @@ func exoptsQuery(whereExo string) string {
func teamptsQuery() string {
return exoptsQuery("") + ` UNION ALL
SELECT D.id_team, D.time, H.cost AS points, -1.0 AS coeff, "Hint" AS reason, H.id_exercice FROM team_hints D INNER JOIN exercice_hints H ON H.id_hint = D.id_hint HAVING points != 0 UNION ALL
SELECT W.id_team, W.time, F.choices_cost AS points, -1.0 AS coeff, "Display choices" AS reason, F.id_exercice FROM team_wchoices W INNER JOIN exercice_flags F ON F.id_flag = W.id_flag HAVING points != 0`
SELECT D.id_team, D.time, H.cost AS points, D.coefficient * -1 AS coeff, "Hint" AS reason, H.id_exercice FROM team_hints D INNER JOIN exercice_hints H ON H.id_hint = D.id_hint HAVING points != 0 UNION ALL
SELECT W.id_team, W.time, F.choices_cost AS points, W.coefficient * -1 AS coeff, "Display choices" AS reason, F.id_exercice FROM team_wchoices W INNER JOIN exercice_flags F ON F.id_flag = W.id_flag HAVING points != 0`
}
func rankQuery(whereTeam string) string {

View file

@ -2,12 +2,16 @@ package fic
import (
"log"
"math"
"time"
)
// UnlockedChallenges disables dependancy requirement between challenges.
var UnlockedChallenges bool
// WchoiceCoefficient is the current coefficient applied on the cost of changing flag into choices
var WChoiceCoefficient = 1.0
// Team represents a group of players, come to solve our challenges.
type Team struct {
Id int64 `json:"id"`
@ -174,7 +178,7 @@ func (t Team) HasHint(h EHint) (bool) {
// OpenHint registers to the database that the Team has now revealed.
func (t Team) OpenHint(h EHint) (error) {
_, err := DBExec("INSERT INTO team_hints (id_team, id_hint, time) VALUES (?, ?, ?)", t.Id, h.Id, time.Now())
_, err := DBExec("INSERT INTO team_hints (id_team, id_hint, time, coefficient) VALUES (?, ?, ?, ?)", t.Id, h.Id, time.Now(), math.Max(HintCoefficient, 0.0))
return err
}
@ -187,7 +191,7 @@ func (t Team) SeeChoices(k FlagKey) (bool) {
// DisplayChoices registers to the database that the Team has now revealed.
func (t Team) DisplayChoices(k FlagKey) (error) {
_, err := DBExec("INSERT INTO team_wchoices (id_team, id_flag, time) VALUES (?, ?, ?)", t.Id, k.Id, time.Now())
_, err := DBExec("INSERT INTO team_wchoices (id_team, id_flag, time, coefficient) VALUES (?, ?, ?, ?)", t.Id, k.Id, time.Now(), math.Max(WChoiceCoefficient, 0.0))
return err
}

View file

@ -161,7 +161,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
return nil, err
} else {
for _, h := range hints {
if t == nil || t.HasHint(h) {
if t == nil || HintCoefficient < 0 || t.HasHint(h) {
exercice.Hints = append(exercice.Hints, myTeamHint{h.Id, h.Title, h.Content, h.File, h.Cost})
} else {
exercice.Hints = append(exercice.Hints, myTeamHint{h.Id, h.Title, "", "", h.Cost})
@ -210,7 +210,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
flag.Help = k.Help
if choices, err := k.GetChoices(); err != nil {
return nil, err
} else if t == nil || k.ChoicesCost == 0 || t.SeeChoices(k) {
} else if t == nil || WChoiceCoefficient < 0 || k.ChoicesCost == 0 || t.SeeChoices(k) {
flag.Choices = map[string]string{}
for _, c := range choices {
flag.Choices[c.Value] = c.Label