Skip to content

Commit

Permalink
Use floats for repeat weights
Browse files Browse the repository at this point in the history
  • Loading branch information
jvc56 committed Jan 14, 2025
1 parent d8fc405 commit 77cd8a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/pair/cop/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func TestCompare(t *testing.T) {
is := is.New(t)
ctx := context.Background()

tourneyName := "2024-10-18-LakeGeorge-CSW-ME"
tourneyName := "2024-12-29-Albany-NWL-ME"

// URLs and filepaths
tfileURL := fmt.Sprintf("https://scrabbleplayers.org/directors/AA003954/%s/a.t", tourneyName)
Expand Down
21 changes: 3 additions & 18 deletions pkg/pair/cop/cop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cop
import (
"context"
"fmt"
"math"

"golang.org/x/exp/rand"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -249,7 +250,7 @@ var weightPolicies = []weightPolicy{
if casherDiff < 0 {
casherDiff *= -1
}
return int64(intPow(casherDiff, 3) * 2)
return int64(math.Pow(float64(casherDiff), 3) * 2)
}
return majorPenalty
},
Expand Down Expand Up @@ -286,7 +287,7 @@ var weightPolicies = []weightPolicy{
pj := pargs.playerNodes[rj]
pairingKey := copdatapkg.GetPairingKey(pi, pj)
timesPlayed := pargs.copdata.PairingCounts[pairingKey]
return int64(timesPlayed * 2 * intPow(pargs.copdata.Standings.GetNumPlayers()/3, 3))
return int64(timesPlayed * 2 * int(math.Pow(float64(pargs.copdata.Standings.GetNumPlayers())/3.0, 3)))
},
},
{
Expand Down Expand Up @@ -725,19 +726,3 @@ func setDisallowPairs(disallowedPairs map[string]string, playerIdx int, oppIdx i
func getRankPairingKey(playerRankIdx int, oppRankIdx int) string {
return fmt.Sprintf("%d:%d", playerRankIdx, oppRankIdx)
}

func intPow(base, exp int) int {
result := 1
for {
if exp&1 == 1 {
result *= base
}
exp >>= 1
if exp == 0 {
break
}
base *= base
}

return result
}

0 comments on commit 77cd8a7

Please sign in to comment.