Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions endgame/negamax/transposition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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")

Expand Down
8 changes: 6 additions & 2 deletions shell/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
11 changes: 11 additions & 0 deletions shell/helptext/set.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ set challenge <rule> - Set the current challenge rule
Valid options are void, 5pt, 10pt, double and single

See `help challengerule` for more detail.

set ttable-mem-fraction <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.
41 changes: 41 additions & 0 deletions shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
Loading