Skip to content
Draft
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
5 changes: 5 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/Vadman97/GolangChessAI/pkg/api/api_handlers"
"github.com/Vadman97/GolangChessAI/pkg/chessai/competition"
"github.com/Vadman97/GolangChessAI/pkg/chessai/server"
"github.com/gorilla/mux"
"log"
"math/rand"
Expand All @@ -23,6 +24,10 @@ func main() {
comp := competition.NewCompetition()
comp.RunAIAnalysis()
return
} else if os.Args[1] == "lichess" {
c := server.ConnectLichess()
c.Run()
return
}
}
rand.Seed(time.Now().UnixNano())
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module github.com/Vadman97/ChessAI3
module github.com/Vadman97/GolangChessAI

go 1.14

require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/bitly/go-simplejson v0.5.0
github.com/davecgh/go-spew v1.1.1
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/gorilla/mux v1.7.1
github.com/gorilla/websocket v1.4.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/pmezard/go-difflib v1.0.0
github.com/kr/pretty v0.3.0 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3
github.com/stretchr/testify v1.3.0
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
)
42 changes: 42 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU=
github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.3-0.20181224173747-660f15d67dbb/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
2 changes: 1 addition & 1 deletion pkg/chessai/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var cfg *Configuration

func Get() *Configuration {
if cfg == nil {
dir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "Vadman97", "GolangChessAI", FilePath)
dir := path.Join(os.Getenv("CHESS_AI"), FilePath)
file, _ := os.Open(dir)
defer func() { _ = file.Close() }()
decoder := json.NewDecoder(file)
Expand Down
10 changes: 8 additions & 2 deletions pkg/chessai/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (g *Game) GetGameOutcome() (outcome Outcome) {
*/

func (g *Game) PlayTurn() bool {
return g.PlayTurnMove(nil)
}

func (g *Game) PlayTurnMove(m *location.Move) bool {
if g.GameStatus != Active {
log.Println("Game is not active!")
return false
Expand All @@ -77,10 +81,12 @@ func (g *Game) PlayTurn() bool {
// print think time for slow players, regardless of what's going on
go g.periodicUpdates(quitTimeUpdates, start)

var move *location.Move
var move *location.Move = m
switch p := g.Players[g.CurrentTurnColor].(type) {
case *player.HumanPlayer:
move = p.WaitForMove()
if m == nil {
move = p.WaitForMove()
}
case *ai.AIPlayer:
move = p.GetBestMove(g.CurrentBoard, g.PreviousMove, g.PerformanceLogger)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/chessai/game_config/game_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var cfg *GameConfiguration

func Get() *GameConfiguration {
if cfg == nil {
dir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "Vadman97", "GolangChessAI", FilePath)
dir := path.Join(os.Getenv("CHESS_AI"), FilePath)
file, _ := os.Open(dir)
defer func() { _ = file.Close() }()
decoder := json.NewDecoder(file)
Expand Down
11 changes: 11 additions & 0 deletions pkg/chessai/location/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var LeftDownMove = RelativeLocation{1, -1}
var LeftMove = RelativeLocation{0, -1}
var LeftUpMove = RelativeLocation{-1, -1}

var Cols = []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}

type Location struct {
// row stored in 3 bits, col stored in 3 bits
// 2 bits store pawn promotion piece
Expand Down Expand Up @@ -72,6 +74,11 @@ func (l Location) GetRow() (row CoordinateType) {
return
}

func (l Location) GetColLetter() rune {
_, col := l.Get()
return Cols[col]
}

func (l Location) GetCol() (col CoordinateType) {
_, col = l.Get()
return
Expand Down Expand Up @@ -134,3 +141,7 @@ func (m *Move) Equals(v *Move) bool {
func (m Move) String() string {
return fmt.Sprintf("move from %s to %s", m.Start.String(), m.End.String())
}

func (m Move) UCIString() string {
return fmt.Sprintf("%c%d%c%d", m.Start.GetColLetter(), m.Start.GetRow()+1, m.End.GetColLetter(), m.End.GetRow()+1)
}
Loading