From 984403142fb6f2f78233b3865d4d2fbc10dc9cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Del=20Solar?= Date: Thu, 26 Feb 2026 21:57:30 -0500 Subject: [PATCH] set ttable fraction --- endgame/negamax/transposition_table.go | 12 +++++--- shell/api.go | 8 +++-- shell/helptext/set.txt | 11 +++++++ shell/shell.go | 41 ++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/endgame/negamax/transposition_table.go b/endgame/negamax/transposition_table.go index 9f5b2932..63928215 100644 --- a/endgame/negamax/transposition_table.go +++ b/endgame/negamax/transposition_table.go @@ -12,6 +12,8 @@ import ( "github.com/domino14/macondo/zobrist" "github.com/pbnjay/memory" "github.com/rs/zerolog/log" + "golang.org/x/text/language" + "golang.org/x/text/message" ) const ( @@ -231,10 +233,12 @@ func (t *TranspositionTable) Reset(fractionOfMemory float64, boardDim int) { } } - log.Info().Int("num-elems", numElems). - Float64("desired-num-elems", desiredNElems). - Int("estimated-total-memory-bytes", numElems*entrySize). - Uint64("mem-limit", totalMem). + p := message.NewPrinter(language.English) + log.Info(). + Str("num-elems", p.Sprintf("%d", numElems)). + Str("desired-num-elems", p.Sprintf("%.0f", desiredNElems)). + Str("estimated-total-memory-bytes", p.Sprintf("%d", numElems*entrySize)). + Str("mem-limit", p.Sprintf("%d", totalMem)). Bool("reset", reset). Msg("transposition-table-size") diff --git a/shell/api.go b/shell/api.go index 477a6448..c385d261 100644 --- a/shell/api.go +++ b/shell/api.go @@ -110,11 +110,15 @@ func msg(message string) *Response { func (sc *ShellController) set(cmd *shellcmd) (*Response, error) { if cmd.args == nil { - return msg(sc.options.ToDisplayText()), nil + return msg(sc.ToDisplayTextWithConfig()), nil } opt := cmd.args[0] if len(cmd.args) == 1 { - _, val := sc.options.Show(opt) + ok, val := sc.options.Show(opt) + if !ok { + // Try showing config option + ok, val = sc.ShowConfig(opt) + } return msg(val), nil } values := cmd.args[1:] diff --git a/shell/helptext/set.txt b/shell/helptext/set.txt index ecd54be9..1c6d2f6e 100644 --- a/shell/helptext/set.txt +++ b/shell/helptext/set.txt @@ -11,3 +11,14 @@ set challenge - Set the current challenge rule Valid options are void, 5pt, 10pt, double and single See `help challengerule` for more detail. + +set ttable-mem-fraction - Set transposition table memory fraction + + Sets the fraction of system memory to use for the transposition table + in the endgame solver. Must be between 0 and 1. Default is 0.25 (25%). + + Example: + set ttable-mem-fraction 0.5 # Use 50% of memory + set ttable-mem-fraction 0.1 # Use 10% of memory + + Note: Changes take effect the next time the endgame solver is run. diff --git a/shell/shell.go b/shell/shell.go index 71da6587..b39e952c 100644 --- a/shell/shell.go +++ b/shell/shell.go @@ -93,6 +93,17 @@ func (opts *ShellOptions) Show(key string) (bool, string) { } } +// ShowConfig shows a config value from the shell controller +func (sc *ShellController) ShowConfig(key string) (bool, string) { + switch key { + case "ttable-mem-fraction": + val := sc.config.GetFloat64(config.ConfigTtableMemFraction) + return true, fmt.Sprintf("%.2f (%.0f%% of memory)", val, val*100) + default: + return false, "No such config option: " + key + } +} + func (opts *ShellOptions) ToDisplayText() string { keys := []string{"lexicon", "challenge", "lower", "board"} out := strings.Builder{} @@ -105,6 +116,21 @@ func (opts *ShellOptions) ToDisplayText() string { return out.String() } +// ToDisplayTextWithConfig includes both options and config settings +func (sc *ShellController) ToDisplayTextWithConfig() string { + out := strings.Builder{} + out.WriteString(sc.options.ToDisplayText()) + + // Add config settings + configKeys := []string{"ttable-mem-fraction"} + for _, key := range configKeys { + _, val := sc.ShowConfig(key) + out.WriteString(" " + key + ": ") + out.WriteString(val + "\n") + } + return out.String() +} + // VariationNode represents a position in the variation tree. // The tree structure allows exploring different move sequences from the same position. type VariationNode struct { @@ -367,6 +393,21 @@ func (sc *ShellController) Set(key string, args []string) (string, error) { } else { err = errors.New("Valid options: 'true', 'false'") } + case "ttable-mem-fraction": + val, err := strconv.ParseFloat(args[0], 64) + if err != nil { + err = errors.New("ttable-mem-fraction must be a number between 0 and 1") + } else if val <= 0 || val > 1 { + err = errors.New("ttable-mem-fraction must be between 0 and 1 (e.g., 0.25 for 25% of memory)") + } else { + sc.config.Set(config.ConfigTtableMemFraction, val) + err = sc.config.Write() + if err != nil { + log.Err(err).Msg("error-writing-config") + } else { + ret = fmt.Sprintf("%.2f (%.0f%% of memory)", val, val*100) + } + } default: err = errors.New("No such option: " + key) }