Skip to content

Commit

Permalink
v0.2.1: patch version; fix time reporting (#7)
Browse files Browse the repository at this point in the history
* chore: fix time reporting
* chore: move main to front
* god I suck at this
* chore: update readme stuff
  • Loading branch information
raklaptudirm committed Jun 5, 2024
1 parent 6566cff commit 1a491dc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion internal/arbiter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
36 changes: 19 additions & 17 deletions pkg/eve/match/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/eve/match/games/ataxx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/eve/match/games/chess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions pkg/eve/match/games/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 1a491dc

Please sign in to comment.