-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
movegen, perft and play random moves
- Loading branch information
Showing
53 changed files
with
2,590 additions
and
2,422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
template: | | ||
## What's Changed | ||
$CHANGES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
name: Release | ||
|
||
jobs: | ||
create_draft_release: | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: release-drafter/release-drafter@v5 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag: ${{ github.ref_name }} | ||
version: ${{ github.ref_name }} | ||
|
||
# release: | ||
# strategy: | ||
# matrix: | ||
# include: | ||
# - os: ubuntu-latest | ||
# artifact_file: hifumi-linux-amd64.tgz | ||
# runs-on: ${{ matrix.os }} | ||
# steps: | ||
# - name: Checkout code | ||
# uses: actions/checkout@v4 | ||
# with: | ||
# fetch-depth: 0 | ||
# - name: Setup Go | ||
# uses: actions/setup-go@v4 | ||
# with: | ||
# go-version-file: './go.mod' | ||
# - name: Build release | ||
# run: | | ||
# go build -o hifumi cmd/hifumi/main.go |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/hifumi | ||
*.prof | ||
coverage.out | ||
/tests_perft.test | ||
*.pprof | ||
*.out | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
SHELL := /usr/bin/env bash -o pipefail | ||
|
||
EXE_NAME=hifumi | ||
|
||
## help: print this help message | ||
help: | ||
@echo 'Usage:' | ||
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' | ||
.PHONY: help | ||
|
||
## build: build the application | ||
build: | ||
go build -o ${EXE_NAME} cmd/hifumi/main.go | ||
.PHONY: build | ||
|
||
## run: run the application | ||
run: build | ||
@./hifumi | ||
.PHONY: run | ||
|
||
## test: run all tests | ||
test: | ||
go test ./... | ||
.PHONY: test | ||
|
||
## test/perft: run perft tests | ||
test/perft: | ||
go test ./shogi ./tests_perft -covermode=count -coverpkg=github.com/vinymeuh/hifumi/shogi | ||
.PHONY: test/perft | ||
|
||
## bench/perft: run perft benchmarks | ||
bench/perft: | ||
go test ./tests_perft -bench=. -run=^# -benchmem -memprofile memprofile.out -cpuprofile profile.out | ||
.PHONY: bench/perft | ||
|
||
## bench/perft/cpu: run perft benchmarks then pprof cpu usage | ||
bench/perft/cpu: bench/perft | ||
go tool pprof profile.out | ||
.PHONY: bench/perft/cpu | ||
|
||
## bench/perft/mem: run perft benchmarks then pprof memory usage | ||
bench/perft/mem: bench/perft | ||
go tool pprof memprofile.out | ||
.PHONY: bench/perft/mem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-FileCopyrightText: 2023 VinyMeuh | ||
// SPDX-License-Identifier: MIT | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"runtime/pprof" | ||
|
||
"github.com/vinymeuh/hifumi/shogi" | ||
"github.com/vinymeuh/hifumi/shogi/movegen" | ||
) | ||
|
||
type findPieceMagicFunc func(sq uint8) uint64 | ||
|
||
func findMagic(fn findPieceMagicFunc) { | ||
for sq := uint8(0); sq < shogi.SQUARES; sq++ { | ||
magic := fn(sq) | ||
if magic > 0 { | ||
if sq%9 == 0 && sq != 0 { | ||
fmt.Println() | ||
} | ||
fmt.Printf(" 0x%0X,", magic) | ||
} else { | ||
fmt.Fprintf(os.Stderr, "unable to find magic number") | ||
return | ||
} | ||
} | ||
} | ||
|
||
func usage() { | ||
fmt.Println("Usage: findmagic blacklance|whitelance|bishop|rook-h|rook-v") | ||
} | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
usage() | ||
os.Exit(1) | ||
} | ||
|
||
f, err := os.Create("./findmagic.prof") | ||
if err == nil { | ||
pprof.StartCPUProfile(f) | ||
defer pprof.StopCPUProfile() | ||
} | ||
|
||
switch os.Args[1] { | ||
case "blacklance": | ||
fmt.Println("var blackLanceMagics = [shogi.SQUARES]uint64{") | ||
findMagic(movegen.FindBlackLanceMagic) | ||
case "whitelance": | ||
fmt.Println("var whiteLanceMagics = [shogi.SQUARES]uint64{") | ||
findMagic(movegen.FindWhiteLanceMagic) | ||
case "bishop": | ||
fmt.Println("var bishopMagics = [shogi.SQUARES]uint64{") | ||
findMagic(movegen.FindBishopMagic) | ||
case "rook-h": | ||
fmt.Println("var rookHMagics = [shogi.SQUARES]uint64{") | ||
findMagic(movegen.FindRookHMagic) | ||
case "rook-v": | ||
fmt.Println("var rookVMagics = [shogi.SQUARES]uint64{") | ||
findMagic(movegen.FindRookVMagic) | ||
default: | ||
usage() | ||
defer os.Exit(1) | ||
} | ||
fmt.Printf("\n}\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-FileCopyrightText: 2023 VinyMeuh | ||
// SPDX-License-Identifier: MIT | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"runtime" | ||
"runtime/pprof" | ||
"time" | ||
|
||
"github.com/vinymeuh/hifumi/engine" | ||
) | ||
|
||
func main() { | ||
prefix := fmt.Sprintf("%s-%s-%s-", engine.EngineName, engine.EngineVersion, time.Now().Format("2006-01-02T150405")) | ||
if _, ok := os.LookupEnv("HIFUMI_PPROF"); ok { | ||
f, err := os.Create(prefix + "cpu.pprof") | ||
if err != nil { | ||
log.Fatal("could not create CPU profile file:", err) | ||
} | ||
defer f.Close() | ||
if err := pprof.StartCPUProfile(f); err != nil { | ||
log.Fatal("could not start CPU profile:", err) | ||
} | ||
defer pprof.StopCPUProfile() | ||
} | ||
|
||
engine.UsiLoop() | ||
|
||
if _, ok := os.LookupEnv("HIFUMI_PPROF"); ok { | ||
runtime.GC() | ||
f, err := os.Create(prefix + "mem.pprof") | ||
if err != nil { | ||
log.Fatal("could not create Heap profile file:", err) | ||
} | ||
defer f.Close() | ||
runtime.MemProfileRate = 2048 | ||
if err := pprof.WriteHeapProfile(f); err != nil { | ||
log.Fatal("could not write Heap profile:", err) | ||
} | ||
} | ||
} |
Oops, something went wrong.