Skip to content

Commit 9844031

Browse files
committed
set ttable fraction
1 parent 072e1df commit 9844031

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

endgame/negamax/transposition_table.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/domino14/macondo/zobrist"
1313
"github.com/pbnjay/memory"
1414
"github.com/rs/zerolog/log"
15+
"golang.org/x/text/language"
16+
"golang.org/x/text/message"
1517
)
1618

1719
const (
@@ -231,10 +233,12 @@ func (t *TranspositionTable) Reset(fractionOfMemory float64, boardDim int) {
231233
}
232234
}
233235

234-
log.Info().Int("num-elems", numElems).
235-
Float64("desired-num-elems", desiredNElems).
236-
Int("estimated-total-memory-bytes", numElems*entrySize).
237-
Uint64("mem-limit", totalMem).
236+
p := message.NewPrinter(language.English)
237+
log.Info().
238+
Str("num-elems", p.Sprintf("%d", numElems)).
239+
Str("desired-num-elems", p.Sprintf("%.0f", desiredNElems)).
240+
Str("estimated-total-memory-bytes", p.Sprintf("%d", numElems*entrySize)).
241+
Str("mem-limit", p.Sprintf("%d", totalMem)).
238242
Bool("reset", reset).
239243
Msg("transposition-table-size")
240244

shell/api.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ func msg(message string) *Response {
110110

111111
func (sc *ShellController) set(cmd *shellcmd) (*Response, error) {
112112
if cmd.args == nil {
113-
return msg(sc.options.ToDisplayText()), nil
113+
return msg(sc.ToDisplayTextWithConfig()), nil
114114
}
115115
opt := cmd.args[0]
116116
if len(cmd.args) == 1 {
117-
_, val := sc.options.Show(opt)
117+
ok, val := sc.options.Show(opt)
118+
if !ok {
119+
// Try showing config option
120+
ok, val = sc.ShowConfig(opt)
121+
}
118122
return msg(val), nil
119123
}
120124
values := cmd.args[1:]

shell/helptext/set.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ set challenge <rule> - Set the current challenge rule
1111
Valid options are void, 5pt, 10pt, double and single
1212

1313
See `help challengerule` for more detail.
14+
15+
set ttable-mem-fraction <fraction> - Set transposition table memory fraction
16+
17+
Sets the fraction of system memory to use for the transposition table
18+
in the endgame solver. Must be between 0 and 1. Default is 0.25 (25%).
19+
20+
Example:
21+
set ttable-mem-fraction 0.5 # Use 50% of memory
22+
set ttable-mem-fraction 0.1 # Use 10% of memory
23+
24+
Note: Changes take effect the next time the endgame solver is run.

shell/shell.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ func (opts *ShellOptions) Show(key string) (bool, string) {
9393
}
9494
}
9595

96+
// ShowConfig shows a config value from the shell controller
97+
func (sc *ShellController) ShowConfig(key string) (bool, string) {
98+
switch key {
99+
case "ttable-mem-fraction":
100+
val := sc.config.GetFloat64(config.ConfigTtableMemFraction)
101+
return true, fmt.Sprintf("%.2f (%.0f%% of memory)", val, val*100)
102+
default:
103+
return false, "No such config option: " + key
104+
}
105+
}
106+
96107
func (opts *ShellOptions) ToDisplayText() string {
97108
keys := []string{"lexicon", "challenge", "lower", "board"}
98109
out := strings.Builder{}
@@ -105,6 +116,21 @@ func (opts *ShellOptions) ToDisplayText() string {
105116
return out.String()
106117
}
107118

119+
// ToDisplayTextWithConfig includes both options and config settings
120+
func (sc *ShellController) ToDisplayTextWithConfig() string {
121+
out := strings.Builder{}
122+
out.WriteString(sc.options.ToDisplayText())
123+
124+
// Add config settings
125+
configKeys := []string{"ttable-mem-fraction"}
126+
for _, key := range configKeys {
127+
_, val := sc.ShowConfig(key)
128+
out.WriteString(" " + key + ": ")
129+
out.WriteString(val + "\n")
130+
}
131+
return out.String()
132+
}
133+
108134
// VariationNode represents a position in the variation tree.
109135
// The tree structure allows exploring different move sequences from the same position.
110136
type VariationNode struct {
@@ -367,6 +393,21 @@ func (sc *ShellController) Set(key string, args []string) (string, error) {
367393
} else {
368394
err = errors.New("Valid options: 'true', 'false'")
369395
}
396+
case "ttable-mem-fraction":
397+
val, err := strconv.ParseFloat(args[0], 64)
398+
if err != nil {
399+
err = errors.New("ttable-mem-fraction must be a number between 0 and 1")
400+
} else if val <= 0 || val > 1 {
401+
err = errors.New("ttable-mem-fraction must be between 0 and 1 (e.g., 0.25 for 25% of memory)")
402+
} else {
403+
sc.config.Set(config.ConfigTtableMemFraction, val)
404+
err = sc.config.Write()
405+
if err != nil {
406+
log.Err(err).Msg("error-writing-config")
407+
} else {
408+
ret = fmt.Sprintf("%.2f (%.0f%% of memory)", val, val*100)
409+
}
410+
}
370411
default:
371412
err = errors.New("No such option: " + key)
372413
}

0 commit comments

Comments
 (0)