Skip to content
Snippets Groups Projects
Commit a4c270c6 authored by Balthazar Wilson's avatar Balthazar Wilson
Browse files

Merge branch 'fix/options_handling' of gitlab.utc.fr:gvandevi/ia04binome2a into baltha_server

parents 8857b68f 5c276e50
No related branches found
No related tags found
1 merge request!7Partie serveur
......@@ -62,6 +62,47 @@ func SWFFactory(swf func(Profile) (Count, error), tb func([]Alternative) (Altern
}
}
func SWFFactoryWithOptions(
swf func(Profile, []int) (Count, error),
tb func([]Alternative) (Alternative, error),
) func(Profile, []int) ([]Alternative, error) {
return func(p Profile, o []int) ([]Alternative, error) {
//récupération du décompte
count, errSWF := swf(p, o)
if errSWF != nil {
return nil, errSWF
}
//préparation de la sortie
var sortedAlts []Alternative
//PARCOURS DU DECOMPTE
for len(count) > 0 {
//On prend les meilleures alternatives (avant tie break)
bestAlts := maxCount(count)
//On supprime les meilleures alternatives du décompte
for alt := range bestAlts {
delete(count, Alternative(alt))
}
//Départage
for len(bestAlts) > 0 {
bestAlt, errTB := tb(bestAlts)
if errTB != nil {
return nil, errTB
}
//ajout de la meilleure alternative post-tie break
sortedAlts = append(sortedAlts, bestAlt)
//suppression de l'alternative dans bestAlts
indice := rank(bestAlt, bestAlts)
bestAlts = append(bestAlts[:indice], bestAlts[indice+1:]...)
//suppression de l'alternativ dans le compte
delete(count, Alternative(bestAlt))
}
}
return sortedAlts, nil
}
}
func Test_sWFFactory() {
//Définition de l'Ordre strict
orderedAlts := []Alternative{8, 9, 6, 1, 3, 2}
......@@ -94,6 +135,23 @@ func SCFFactory(scf func(p Profile) ([]Alternative, error), tb func([]Alternativ
return bestAlt, errTB
}
}
func SCFFactoryWithOptions(
scf func(Profile, []int) ([]Alternative, error),
tb func([]Alternative) (Alternative, error),
) func(Profile, []int) (Alternative, error) {
return func(p Profile, o []int) (Alternative, error) {
//récupération des meilleures alternatives
bestAlts, errSCF := scf(p, o)
if errSCF != nil {
return Alternative(0), errSCF
}
//récupération de la meilleure alternative
bestAlt, errTB := tb(bestAlts)
return bestAlt, errTB
}
}
func Test_sCFFactory() {
//Définition de l'Ordre strict
orderedAlts := []Alternative{8, 9, 6, 1, 3, 2}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment