Skip to content

Commit

Permalink
everywhere: don't pass by reference to search
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ff committed Dec 6, 2023
1 parent 149cbe0 commit d415dbd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/rosaline/interfaces/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ func (i cliInterface) Loop() {
}
}

bestMove := i.searcher.Search(&position, depth, false)
bestMove := i.searcher.Search(position, depth, false)
fmt.Println("best move:", bestMove)
} else if cmd == "evaluate" {
score := i.evaluator.Evaluate(&position)
fmt.Println("score:", score)
} else if cmd == "play" {
bestMove := i.searcher.Search(&position, DefaultDepth, false)
bestMove := i.searcher.Search(position, DefaultDepth, false)
position.MakeMove(bestMove)
fmt.Println("played:", bestMove)
} else if cmd == "fen" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/rosaline/interfaces/uci.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ loop:
break
case "go":
go func() {
bestMove := i.searcher.Search(&position, DefaultDepth, true)
bestMove := i.searcher.Search(position, DefaultDepth, true)
position.MakeMove(bestMove)
fmt.Println("bestmove", bestMove)
}()
Expand Down
12 changes: 6 additions & 6 deletions internal/search/negamax.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewNegamaxSearcher(evaluator evaluation.Evaluator) NegamaxSearcher {
}
}

func (s *NegamaxSearcher) Search(position *chess.Position, depth int, print bool) chess.Move {
func (s *NegamaxSearcher) Search(position chess.Position, depth int, print bool) chess.Move {
s.ClearPreviousSearch()

bestMove := chess.NullMove
Expand Down Expand Up @@ -106,7 +106,7 @@ func (s NegamaxSearcher) getPV() string {
return builder.String()
}

func (s NegamaxSearcher) scoreMove(position *chess.Position, move chess.Move, ply int) int {
func (s NegamaxSearcher) scoreMove(position chess.Position, move chess.Move, ply int) int {
turn := position.Turn()

if s.pvtable[0][ply] == move {
Expand All @@ -120,7 +120,7 @@ func (s NegamaxSearcher) scoreMove(position *chess.Position, move chess.Move, pl
return 0
}

func (s *NegamaxSearcher) doSearch(position *chess.Position, alpha int, beta int, depth int, ply int, extensions int) int {
func (s *NegamaxSearcher) doSearch(position chess.Position, alpha int, beta int, depth int, ply int, extensions int) int {
s.pvlength[ply] = ply

if s.stop {
Expand Down Expand Up @@ -154,7 +154,7 @@ func (s *NegamaxSearcher) doSearch(position *chess.Position, alpha int, beta int

if depth == 0 {
if inCheck { // don't go in quiescence search when in check
return s.evaluator.AbsoluteEvaluation(position)
return s.evaluator.AbsoluteEvaluation(&position)
} else {
return s.quiescence(position, alpha, beta)
}
Expand Down Expand Up @@ -272,8 +272,8 @@ func (s *NegamaxSearcher) doSearch(position *chess.Position, alpha int, beta int
return bestScore
}

func (s NegamaxSearcher) quiescence(position *chess.Position, alpha int, beta int) int {
evaluation := s.evaluator.AbsoluteEvaluation(position)
func (s NegamaxSearcher) quiescence(position chess.Position, alpha int, beta int) int {
evaluation := s.evaluator.AbsoluteEvaluation(&position)
if evaluation >= beta {
return beta
}
Expand Down
2 changes: 1 addition & 1 deletion internal/search/negamax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ func BenchmarkNegamax(b *testing.B) {
searcher := NewNegamaxSearcher(evaluator)

for i := 0; i < b.N; i++ {
searcher.Search(&position, 4, false)
searcher.Search(position, 4, false)
}
}

0 comments on commit d415dbd

Please sign in to comment.