diff --git a/README.md b/README.md index 0f86edb..6375b1f 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ command-line tool with interactive prompts to enable easy configuration. ## Features - [x] Game Engine installer and version manager. -- [ ] Tournament and Testing system using UXI protocols. +- [x] Tournament and Testing system using UXI protocols. ## Installation **Requirements:** [Go 1.20 or greater](https://go.dev/doc/install) ```sh -go install laptudirm.com/x/arbiter/cmd/arbiter@latest +go install laptudirm.com/x/arbiter@latest # add ~/arbiter/bin to your PATH to make the installed engines available globally ``` diff --git a/internal/arbiter/cmd/root.go b/internal/arbiter/cmd/root.go index e8e8f79..4232316 100644 --- a/internal/arbiter/cmd/root.go +++ b/internal/arbiter/cmd/root.go @@ -40,7 +40,7 @@ func Root() *cobra.Command { root.PersistentFlags().BoolP("trace", "t", false, "Show Trace Information") // TODO: properly set version - versionStr := "v0.2.0\n" + versionStr := "v0.2.1\n" root.SetVersionTemplate(versionStr) root.Version = versionStr diff --git a/cmd/arbiter/main.go b/main.go similarity index 100% rename from cmd/arbiter/main.go rename to main.go diff --git a/pkg/eve/match/game.go b/pkg/eve/match/game.go index d015523..f2a74b9 100644 --- a/pkg/eve/match/game.go +++ b/pkg/eve/match/game.go @@ -57,58 +57,60 @@ func Run(config *Config) (Result, string) { } moves := "" - sideToMove := 0 + // : EngineIndex + whiteEngine := uint8(oracle.SideToMove()) + engineToMove := 0 for { - engine := engines[sideToMove] + engine := engines[engineToMove] if err := engine.Write("position fen %s moves%s", config.PositionFEN, moves); err != nil { - return GameLostBy[sideToMove], err.Error() + return GameLostBy[engineToMove], err.Error() } if err := engine.Synchronize(); err != nil { - return GameLostBy[sideToMove], err.Error() + return GameLostBy[engineToMove], err.Error() } if err := engine.Write( "go wtime %d btime %d winc %d binc %d", - remaining_time[0].Base.Milliseconds(), - remaining_time[1].Base.Milliseconds(), - remaining_time[0].Inc.Milliseconds(), - remaining_time[1].Inc.Milliseconds(), + remaining_time[whiteEngine].Base.Milliseconds(), + remaining_time[1^whiteEngine].Base.Milliseconds(), + remaining_time[whiteEngine].Inc.Milliseconds(), + remaining_time[1^whiteEngine].Inc.Milliseconds(), ); err != nil { - return GameLostBy[sideToMove], err.Error() + return GameLostBy[engineToMove], err.Error() } startTime := time.Now() line, err := engine.Await( "bestmove .*", - remaining_time[sideToMove].Base, + remaining_time[engineToMove].Base, ) timeSpent := time.Since(startTime) - remaining_time[sideToMove].Base -= timeSpent - remaining_time[sideToMove].Base += remaining_time[sideToMove].Inc + remaining_time[engineToMove].Base -= timeSpent + remaining_time[engineToMove].Base += remaining_time[engineToMove].Inc if err != nil { - return GameLostBy[sideToMove], err.Error() + return GameLostBy[engineToMove], err.Error() } bestmove := strings.Fields(line)[1] moves += " " + bestmove - sideToMove ^= 1 + engineToMove ^= 1 if oracle != nil { err := oracle.MakeMove(bestmove) if err != nil { - return GameLostBy[sideToMove], err.Error() + return GameLostBy[engineToMove], err.Error() } result, reason := oracle.GameResult() switch result { case games.StmWins: - return Win - Result(2*sideToMove), reason + return Win - Result(2*engineToMove), reason case games.XtmWins: - return Loss + Result(2*sideToMove), reason + return Loss + Result(2*engineToMove), reason case games.Draw: return Draw, reason } diff --git a/pkg/eve/match/games/ataxx.go b/pkg/eve/match/games/ataxx.go index 41e0b58..2be0b90 100644 --- a/pkg/eve/match/games/ataxx.go +++ b/pkg/eve/match/games/ataxx.go @@ -16,6 +16,10 @@ func (oracle *AtaxxOracle) Initialize(fenstr string) { oracle.position.SetFen(fenstr) } +func (oracle *AtaxxOracle) SideToMove() Color { + return Color(oracle.position.turn) +} + func (oracle *AtaxxOracle) MakeMove(movstr string) error { move, err := NewMove(movstr) if err != nil { diff --git a/pkg/eve/match/games/chess.go b/pkg/eve/match/games/chess.go index 05dd567..a36ab62 100644 --- a/pkg/eve/match/games/chess.go +++ b/pkg/eve/match/games/chess.go @@ -19,6 +19,10 @@ func (oracle *ChessOracle) Initialize(fenstr string) { oracle.moves = oracle.board.GenerateMoves(false) } +func (oracle *ChessOracle) SideToMove() Color { + return Color(oracle.SideToMove()) +} + func (oracle *ChessOracle) MakeMove(mov_str string) error { found, index := false, 0 for i, mov := range oracle.moves { diff --git a/pkg/eve/match/games/common.go b/pkg/eve/match/games/common.go index f82efb6..5eb5105 100644 --- a/pkg/eve/match/games/common.go +++ b/pkg/eve/match/games/common.go @@ -13,12 +13,20 @@ func GetOracle(name string) Oracle { type Oracle interface { Initialize(fen string) + SideToMove() Color MakeMove(mov string) error FEN() string GameResult() (Result, string) ZeroMoves() bool } +type Color uint8 + +const ( + White Color = iota + Black = iota +) + type Result uint8 const (