Skip to content

Commit

Permalink
Stockfish v stockfish and beginnings of minimax
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshochadel committed Jan 26, 2021
0 parents commit 70968ac
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/jameshochadel/chess-bot

go 1.15

require github.com/notnil/chess v1.5.0
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/notnil/chess v1.5.0 h1:BcdmSGqZYhoqHsAqNpVTtPwRMOA4Sj8iZY1ZuPW4Umg=
github.com/notnil/chess v1.5.0/go.mod h1:cRuJUIBFq9Xki05TWHJxHYkC+fFpq45IWwk94DdlCrA=
71 changes: 71 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"fmt"
"strings"
"time"

"github.com/notnil/chess"
"github.com/notnil/chess/uci"
)

func main() {
eng, err := uci.New("stockfish")
if err != nil {
panic(err)
}
defer eng.Close()

if err := eng.Run(uci.CmdUCI, uci.CmdIsReady, uci.CmdUCINewGame); err != nil {
panic(err)
}

game := chess.NewGame()
for game.Outcome() == chess.NoOutcome {
cmdPos := uci.CmdPosition{Position: game.Position()}
cmdGo := uci.CmdGo{MoveTime: time.Second / 100}
if err = eng.Run(cmdPos, cmdGo); err != nil {
panic(err)
}
move := eng.SearchResults().BestMove
if err := game.Move(move); err != nil {
panic(err)
}
}

fmt.Println(game.String())
}

func minimax(pos chess.Position, depth int, maxPlayer bool) (bestMove chess.Move, posValue float32) {
/*
if depth == 0 or len(game.ValidMoves) == 0,
return evaluatePosition(pos)
if maxPlayer {
} else {
}
*/
return chess.Move{}, 0
}

var pieceVals = map[string]float32 {
"p": 1,
"n": 3,
"b": 3,
"r": 6,
"q": 9,
}

func evaluatePosition(pos chess.Position) float32 {
str := pos.String()

var acc float32

for piece, value := range pieceVals {
acc += float32(strings.Count(str, piece)) * value
}
strings.Count(str, "q")
// count number of each piece
return 0.0
}

0 comments on commit 70968ac

Please sign in to comment.