Skip to content

Commit

Permalink
rosaline: implement iterative deepening
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ff committed Nov 26, 2023
1 parent 6829953 commit 3d78df7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cmd/rosaline/interfaces/uci.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package interfaces
import (
"bufio"
"fmt"
"math"
"os"
"rosaline/internal/chess"
"rosaline/internal/evaluation"
Expand Down Expand Up @@ -52,9 +53,26 @@ loop:
break
case "go":
go func() {
results := i.searcher.Search(position, DefaultDepth)
position.MakeMove(results.BestMove)
fmt.Println("bestmove", results.BestMove)
var bestMove chess.Move
var bestScore int = math.MinInt

for depth := 1; depth <= 4; depth++ {
results := i.searcher.Search(position, depth)

if i.searcher.Stopped() {
break
}

if results.Score > bestScore {
bestMove = results.BestMove
bestScore = results.Score
}

fmt.Printf("info depth %d score cp %d nodes %d nps %d time %d\n", depth, results.Score, results.Nodes, results.NPS, results.Time.Milliseconds())
}

position.MakeMove(bestMove)
fmt.Println("bestmove", bestMove)
}()
break
case "stop":
Expand Down
4 changes: 4 additions & 0 deletions internal/search/negamax.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (s *NegamaxSearcher) Stop() {
s.stop = true
}

func (s NegamaxSearcher) Stopped() bool {
return s.stop
}

// Reset clears any information about searched positions.
func (s *NegamaxSearcher) Reset() {
s.drawTable.Clear()
Expand Down

0 comments on commit 3d78df7

Please sign in to comment.