Skip to content

Commit

Permalink
Improve package naming and add interface for engines to implement
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshochadel committed Mar 13, 2021
1 parent abb41fe commit 1941525
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions engines/engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package engines

import (
"github.com/notnil/chess"
)

type Engine interface {
SuggestedMove(pos *chess.Position, maxPlayer bool) *chess.Move
}
6 changes: 4 additions & 2 deletions engine/minimax.go → engines/minimax.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package engine
package engines

import (
"fmt"
Expand All @@ -10,9 +10,11 @@ import (
"github.com/notnil/chess"
)

type MinimaxEngine struct {}

// SuggestedMove calculates the most advantageous move for the player. It currently works
// synchronously, but can probably be made concurrent with goroutines.
func SuggestedMove(pos *chess.Position, maxPlayer bool) *chess.Move {
func (e *MinimaxEngine) SuggestedMove(pos *chess.Position, maxPlayer bool) *chess.Move {
startingDepth := 3
return minimax(pos, startingDepth, maxPlayer).move
}
Expand Down
2 changes: 1 addition & 1 deletion engine/minimax_test.go → engines/minimax_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package engine
package engines

import (
"fmt"
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (

"github.com/notnil/chess"

"github.com/jameshochadel/chess-bot/engine"
"github.com/jameshochadel/chess-bot/engines"
)

func main() {
game := chess.NewGame()
engine := engines.MinimaxEngine{}

for game.Outcome() == chess.NoOutcome {
// how to do context with timeout? basically want to go as far as possible until timeout.
Expand Down

0 comments on commit 1941525

Please sign in to comment.