Skip to content

Commit

Permalink
chore: merge theme fix branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tmountain committed Jan 15, 2021
1 parent 8be1f6f commit e2fa3dc
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.exe~
*.dll
*.so
*.swp
*.dylib
.vscode
.DS_Store
Expand All @@ -13,9 +14,10 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Build directories
# Build directories and binaries
bin/
dist/
cmd/uchess/uchess

# Dependency directories (remove the comment below to include it)
arch/
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tidy:
$(GO_BIN) mod tidy -v

build: tidy
pkger -o ./cmd/uchess
cd ./cmd/uchess && $(GO_BIN) build -v .
make tidy

Expand Down
59 changes: 55 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,79 @@ An example of a board snapshot:

## Installation

**uchess** can be installed using "go get".
The easiest way to get **uchess** is via an
[official release](https://github.com/tmountain/uchess/releases).

**uchess** can also be installed using "go get".
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default.

```bash
$ go get github.com/tmountain/uchess/cmd/uchess
```

## Build

**uchess** includes a Makefile which will build a binary
for your native architecture. Building uchess requires the
[pkger](https://github.com/markbates/pkger) binary, which
is also installed via "go get".

```bash
$ go get github.com/markbates/pkger/cmd/pkger
$ make build
$ cmd/uchess/uchess
```

You can also cross compile via `make release_test`.

```bash
go get github.com/tmountain/uchess/cmd/uchess
$ make release_test
$ tree dist
dist
├── uchess_darwin_amd64
│   └── uchess
├── uchess_linux_amd64
│   └── uchess
├── uchess_linux_arm_5
│   └── uchess
└── uchess_windows_amd64
└── uchess.exe
```

## Usage

### Generate a **uchess** config and edit it accordingly.

Mac and Linux

```bash
$ uchess -tmpl > uchess.json
```

Windows

```
# Avoid BOM in config file
> .\uchess.exe -tpl | set-content uchess.json -Encoding Ascii
```

Run **uchess** on the config.

Mac and Linux

```bash
$ uchess -cfg uchess.json
```

With zero configuration, uchess will attempt to invoke stockfish
via /usr/local/bin/stockfish with difficulty level 20.
Windows

```
> .\uchess.exe -cfg uchess.json
```

With zero configuration, uchess will attempt to locate stockfish
on your system and run it with difficulty level 20.

### Commands

Expand Down
12 changes: 12 additions & 0 deletions cmd/uchess/pkged.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 39 additions & 10 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"

"github.com/markbates/pkger"
)
Expand All @@ -24,6 +25,9 @@ type Config struct {
BlackName string `json:"blackName"`
}

var winStockfish = "C:\\stockfish\\stockfish.exe"
var defStockfish = "/usr/local/bin/stockfish"

// HasTheme returns a bool indicating whether the config
// contains a theme of the name provided
func HasTheme(name string, themes []ThemeHex) bool {
Expand All @@ -35,22 +39,43 @@ func HasTheme(name string, themes []ThemeHex) bool {
return false
}

// DefaultUCIPath makes an attempt to find a viable UCI engine
func DefaultUCIPath() string {
if runtime.GOOS == "windows" {
return winStockfish
}

// Places to look for stockfish on Linux/Mac
stockfishPaths := []string{
"/usr/bin/stockfish",
"/usr/games/stockfish",
}

for _, path := range stockfishPaths {
if FileExists(path) {
return path
}
}

return defStockfish
}

// DefaultOptions defines any default UCI options
var DefaultOptions = []Option{
{"skill level", "20"}, // stockfish skill level
}

var uciEngines = []UCIEngine{
{
"stockfish", // Name
"/usr/games/stockfish", // Path
128, // Hash
false, // Ponder
false, // OwnBook
4, // MultiPV
0, // Depth
"", // SearchMoves
3000, // MoveTime
"stockfish", // Name
DefaultUCIPath(), // Path
128, // Hash
false, // Ponder
false, // OwnBook
4, // MultiPV
0, // Depth
"", // SearchMoves
3000, // MoveTime
DefaultOptions,
},
}
Expand Down Expand Up @@ -89,7 +114,7 @@ var DefaultConfig = Config{
uciEngines, // UCIEngine
defaultFEN, // FEN
"basic", // ActiveTheme
ReadThemes(), // Themes
[]ThemeHex{}, // Themes
"human", // WhitePiece
"cpu", // BlackPiece
"", // WhiteName
Expand All @@ -98,6 +123,10 @@ var DefaultConfig = Config{

// ConfigJSON returns the JSON encoded representation of the config
func ConfigJSON() string {
config := DefaultConfig
// Just include the basic theme in the default config as a reference
config.Themes = []ThemeHex{ThemeBasic.Hex()}

c, err := json.MarshalIndent(&DefaultConfig, "", " ")
if err != nil {
panic(err)
Expand Down
3 changes: 2 additions & 1 deletion flags.go → init.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func setWhitePieceName(c *Config) {
}
}

// Init sets up the app config from flags
// Init sets up the app config
func Init() Config {
var config Config
tmpl := flag.Bool("tmpl", false, "generate config template with defaults")
Expand Down Expand Up @@ -80,6 +80,7 @@ func Init() Config {
} else {
// Zero configuration config (hopefully)
config = DefaultConfig
config.Themes = ReadThemes()
}

config.WhitePiece = *white
Expand Down
13 changes: 13 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package uchess
import (
"fmt"
"math"
"os"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -212,3 +214,14 @@ func EmojiForPlayer(playerType string) string {
}
return "👤"
}

// IsWindows returns a boolean indicating whether windows is the OS
func IsWindows() bool {
return runtime.GOOS == "windows"
}

// FileExists returns a bool indicating whether the specified file exists
func FileExists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}

0 comments on commit e2fa3dc

Please sign in to comment.