Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use kwg for word graph #240

Merged
merged 55 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a317969
use kwg for word graph
domino14 Mar 10, 2023
34e10f9
sort letterdistribution csvs by desired order
domino14 Mar 10, 2023
ddd7738
fix a reference
domino14 Mar 10, 2023
45c7b71
part of a large refactor; moving towards different-indexed machinelet…
domino14 Mar 11, 2023
3cdce71
some movegen optimizations
domino14 Mar 11, 2023
cf994d2
fix a comment
domino14 Mar 11, 2023
1e85ada
add another optimization
domino14 Mar 11, 2023
b6a8df0
a tiny optimization
domino14 Mar 11, 2023
d3d547a
add more passing tests
domino14 Mar 11, 2023
fdb6969
add klv files
domino14 Mar 11, 2023
d37b2f5
implement Kurnia Leave Values and algorithms
domino14 Mar 12, 2023
4b7a452
tweak, addl test
domino14 Mar 12, 2023
b048640
fix kwg anagrammer and word finder
domino14 Mar 13, 2023
2e358d1
update benchmark
domino14 Mar 13, 2023
7523e97
fix a few more tests
domino14 Mar 13, 2023
0af1ff3
fix klv load function. name all files leaves.klv for macondo usage
domino14 Mar 13, 2023
fa7ebb9
fix more tests
domino14 Mar 13, 2023
9ee4fae
fix display bug
domino14 Mar 14, 2023
69de854
disallow 1-tile plays from kwgs that have these (norwegian)
domino14 Mar 14, 2023
4a791b8
delete a ton of files, tests pass at least locally
domino14 Mar 14, 2023
c437784
rename letterdist files since not compatible with old liwords/macondo
domino14 Mar 14, 2023
8627a91
try to fix circle tests
domino14 Mar 15, 2023
88b5a50
fix wolges docker invocation
domino14 Mar 15, 2023
0877834
try to figure out whats happening
domino14 Mar 15, 2023
e24fe3b
put ls in the wrong place
domino14 Mar 15, 2023
9600cbc
more logging
domino14 Mar 15, 2023
8968c47
avoid mounting
andy-k Mar 15, 2023
7b2df6c
golang closures allocate
domino14 Mar 15, 2023
8dcd94b
add new simming bot type with more plies
domino14 Mar 15, 2023
22fd2bc
avoid unneeded allocation
domino14 Mar 16, 2023
2307392
get simSingleIteration to 0 allocs/op
domino14 Mar 16, 2023
abdaff6
try machine executor
domino14 Mar 16, 2023
07f354e
circleci dammit
domino14 Mar 16, 2023
17f2855
more sim tweaks
domino14 Mar 16, 2023
a2b437e
sim speed tweak
domino14 Mar 17, 2023
c5f6e85
game runner alternate firsts
domino14 Mar 17, 2023
332b99f
5 ply for now
domino14 Mar 17, 2023
35abc23
refactoring rune -> string in tilemapping. almost done; infer fails
domino14 Mar 18, 2023
f1aa88b
add catalan support - it works!
domino14 Mar 18, 2023
c4a1dbf
add catalan leave values
domino14 Mar 18, 2023
7a80b88
programmable per-bot min sim count
domino14 Mar 18, 2023
85a78d3
use bash
domino14 Mar 18, 2023
7958896
re-add lexicon path env var for bash script
domino14 Mar 18, 2023
c00bdcd
try another strategy
domino14 Mar 18, 2023
4ce4ffc
please work already ffs
domino14 Mar 18, 2023
ba5c7c0
try again. circleci sucks
domino14 Mar 18, 2023
8e87013
fix cgp load test
domino14 Mar 18, 2023
a74845e
force lex files to upper case
domino14 Mar 18, 2023
f756c0d
add norwegian for a failing test
domino14 Mar 18, 2023
bdf98da
if this test doesn't pass so help me god
domino14 Mar 19, 2023
881c997
fix a test
domino14 Mar 19, 2023
cd782ea
fix more failing tests
domino14 Mar 19, 2023
febe347
move to klv2
domino14 Mar 19, 2023
13079e4
fix benchmark
domino14 Mar 19, 2023
7ec99e3
allow reading of catalan gcg
domino14 Mar 19, 2023
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
65 changes: 34 additions & 31 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,48 @@ orbs:
jobs:
build:
environment:
LEXICON_PATH: /opt/lexica/
STRATEGY_PARAMS_PATH: /opt/data/strategy
LETTER_DISTRIBUTION_PATH: /opt/data/letterdistributions
AUTH_KEY: abcdef
docker:
- image: golang:alpine
working_directory: /opt/macondo
LEXICON_PATH: /home/circleci/lexica
machine: # executor type
image: ubuntu-2004:current
docker_layer_caching: true
working_directory: ~/macondo
steps:
- checkout
- add_ssh_keys:
fingerprints:
- "bf:37:1b:e1:b2:b0:ec:20:92:43:20:86:40:7c:c4:e0"
- run:
name: Install git, ssh, build-base, bash (for tests)
command: apk update && apk upgrade && apk add git openssh build-base bash curl
- run:
name: Install ssl
command: apk add --update ca-certificates openssl && update-ca-certificates
- run: if [ ! -n "$(grep "^github.com " ~/.ssh/known_hosts)" ]; then ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null; fi
- run:
name: Clone lexicon repo
command: git clone git@github.com:domino14/word-game-lexica /opt/word-game-lexica
- run: mkdir $LEXICON_PATH
- run: mkdir $LEXICON_PATH/gaddag
- run: mkdir $LEXICON_PATH/dawg
- run: mv /opt/word-game-lexica/*.txt $LEXICON_PATH
- run: cp -r /opt/macondo/data /opt/data
- run: go build cmd/shell/main.go
# build GADDAGs
- restore_cache:
keys:
- gaddag-cache
- run: cd testcommon && go generate
- run: cd /opt/macondo && go test $(go list ./... | grep -v wasm)
- save_cache:
key: gaddag-cache
paths:
- /opt/lexica/gaddag
- /opt/lexica/dawg
command: git clone git@github.com:domino14/word-game-lexica ~/word-game-lexica
- run:
name: Clone wolges
command: git clone https://github.com/andy-k/wolges ~/wolges
- run: mkdir ~/lexica
- run: mkdir ~/lexica/gaddag
- run: mv ~/word-game-lexica/*.txt ~/lexica
- run: cp -r ~/macondo/data ~/data
- run: docker build -t macondo -f Dockerfile-dev .
- run: docker run --rm macondo make
# # build GADDAGs
# - restore_cache:
# keys:
# - kwg-cache
- run: cp Dockerfile-kbuilder ~/wolges
- run: cd ~/wolges && docker build -t kbuilder -f Dockerfile-kbuilder .
- run: cd ~/macondo/.circleci && ./create_lexicon_files.sh
- run: >
docker run --rm -e LEXICON_PATH=/opt/lexica
-e STRATEGY_PARAMS_PATH=/opt/data/strategy
-e DATA_PATH=/opt/data
-e LETTER_DISTRIBUTION_PATH=/opt/data/letterdistributions
-v ~/data:/opt/data
-v ~/lexica:/opt/lexica
macondo go test $(go list ./... | grep -v wasm)
# - save_cache:
# key: kwg-cache
# paths:
# - /opt/lexica/gaddag
- discord/status: &discord-webhook-setting
webhook: "${DISCORD_WEBHOOK}"
success_message: ":tada: A $CIRCLE_JOB job has succeeded! (Branch: $CIRCLE_BRANCH)"
Expand Down
70 changes: 70 additions & 0 deletions .circleci/create_lexicon_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

set -euo pipefail

ls $LEXICON_PATH

for lex in "NWL20" "NWL18" "America" "CSW21" "CSW19" "ECWL"
do
awk '{print $1}' "$LEXICON_PATH/$lex.txt" > "$LEXICON_PATH/$lex-stripped.txt"
awk '{print toupper($0)}' "$LEXICON_PATH/$lex-stripped.txt" > "$LEXICON_PATH/$lex-toupper.txt"
echo "lex $lex"

CONTAINER_ID="$(docker create kbuilder -- english-kwg /home/in.txt /home/out.kwg )"
trap "docker rm $CONTAINER_ID" EXIT
echo "$CONTAINER_ID"

docker cp "$LEXICON_PATH/$lex-toupper.txt" "$CONTAINER_ID:/home/in.txt"
docker start "$CONTAINER_ID"
docker attach "$CONTAINER_ID" || true
docker cp "$CONTAINER_ID:/home/out.kwg" "$LEXICON_PATH/gaddag/$lex.kwg"

docker rm "$CONTAINER_ID"
trap "" EXIT

echo "after $lex"
done

for lex in "OSPS44"
do
awk '{print $1}' "$LEXICON_PATH/$lex.txt" > "$LEXICON_PATH/$lex-stripped.txt"
echo "lex $lex"

CONTAINER_ID="$(docker create kbuilder -- polish-kwg /home/in.txt /home/out.kwg )"
trap "docker rm $CONTAINER_ID" EXIT
echo "$CONTAINER_ID"

docker cp "$LEXICON_PATH/$lex-stripped.txt" "$CONTAINER_ID:/home/in.txt"
docker start "$CONTAINER_ID"
docker attach "$CONTAINER_ID" || true
docker cp "$CONTAINER_ID:/home/out.kwg" "$LEXICON_PATH/gaddag/$lex.kwg"

docker rm "$CONTAINER_ID"
trap "" EXIT

echo "after $lex"
done


for lex in "NSF22"
do
awk '{print $1}' "$LEXICON_PATH/$lex.txt" > "$LEXICON_PATH/$lex-stripped.txt"
awk '{print toupper($0)}' "$LEXICON_PATH/$lex-stripped.txt" > "$LEXICON_PATH/$lex-toupper.txt"
echo "lex $lex"

CONTAINER_ID="$(docker create kbuilder -- norwegian-kwg /home/in.txt /home/out.kwg )"
trap "docker rm $CONTAINER_ID" EXIT
echo "$CONTAINER_ID"

docker cp "$LEXICON_PATH/$lex-toupper.txt" "$CONTAINER_ID:/home/in.txt"
docker start "$CONTAINER_ID"
docker attach "$CONTAINER_ID" || true
docker cp "$CONTAINER_ID:/home/out.kwg" "$LEXICON_PATH/gaddag/$lex.kwg"

docker rm "$CONTAINER_ID"
trap "" EXIT

echo "after $lex"
done

echo "done creating kwgs"
5 changes: 3 additions & 2 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM golang:alpine

RUN apk add --update make
ENV GOPATH=/go
ADD . /go/src/github.com/domino14/macondo
WORKDIR /go/src/github.com/domino14/macondo

EXPOSE 8088
CMD go run main.go -dawgpath=/dawgs/
EXPOSE 8088
7 changes: 7 additions & 0 deletions Dockerfile-kbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Dockerfile for Kurnia files (KWG, KLV)
# See github.com/andy-k/wolges
FROM rust:1.68.0
ADD . /workdir
WORKDIR /workdir
RUN ["cargo", "build", "--release", "--bin", "buildlex"]
ENTRYPOINT ["cargo", "run", "--release", "--bin", "buildlex"]
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
everything: all wasm

all: macondo_shell macondo_bot bot_shell gaddag_maker make_leaves_structure analyze
all: macondo_shell macondo_bot bot_shell analyze

.PHONY: wasm

Expand All @@ -19,11 +19,11 @@ macondo_bot:
bot_shell:
go build -trimpath -o bin/bot_shell cmd/bot_shell/main.go

gaddag_maker:
go build -trimpath -o bin/make_gaddag cmd/make_gaddag/main.go
# gaddag_maker:
# go build -trimpath -o bin/make_gaddag cmd/make_gaddag/main.go

make_leaves_structure:
go build -trimpath -o bin/make_leaves_structure cmd/make_leaves_structure/main.go
# make_leaves_structure:
# go build -trimpath -o bin/make_leaves_structure cmd/make_leaves_structure/main.go

wasm:
GOOS=js GOARCH=wasm go build -trimpath -o ../liwords/liwords-ui/public/wasm/macondo.wasm wasm/*.go
Expand Down
11 changes: 10 additions & 1 deletion ai/bot/bot_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type BotConfig struct {
config.Config
PEGAdjustmentFile string
LeavesFile string
MinSimPlies int
}

type BotTurnPlayer struct {
Expand All @@ -29,6 +30,7 @@ type BotTurnPlayer struct {
simmer *montecarlo.Simmer
simmerCalcs []equity.EquityCalculator
simThreads int
minSimPlies int

inferencer *rangefinder.RangeFinder
}
Expand Down Expand Up @@ -87,12 +89,15 @@ func addBotFields(p *turnplayer.BaseTurnPlayer, conf *BotConfig, botType pb.BotR
// If it is a simming bot, add more fields.
if hasSimming(botType) {
c, err := equity.NewCombinedStaticCalculator(
p.LexiconName(), p.Config(), equity.LeaveFilename, equity.PEGAdjustmentFilename)
p.LexiconName(), p.Config(), "", equity.PEGAdjustmentFilename)
if err != nil {
return nil, err
}
btp.simmer = &montecarlo.Simmer{}
btp.simmerCalcs = []equity.EquityCalculator{c}
if conf.MinSimPlies > 0 {
btp.SetMinSimPlies(conf.MinSimPlies)
}
}
if hasEndgame(botType) {
btp.endgamer = &alphabeta.Solver{}
Expand Down Expand Up @@ -146,3 +151,7 @@ func (p *BotTurnPlayer) SetBotType(b pb.BotRequest_BotCode) {
func (p *BotTurnPlayer) SetSimThreads(t int) {
p.simThreads = t
}

func (p *BotTurnPlayer) SetMinSimPlies(t int) {
p.minSimPlies = t
}
14 changes: 9 additions & 5 deletions ai/bot/elite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (

"github.com/rs/zerolog/log"

"github.com/domino14/macondo/alphabet"
"github.com/domino14/macondo/equity"
"github.com/domino14/macondo/gaddag"
"github.com/domino14/macondo/game"
"github.com/domino14/macondo/kwg"
"github.com/domino14/macondo/montecarlo"
"github.com/domino14/macondo/move"
"github.com/domino14/macondo/movegen"
"github.com/domino14/macondo/tilemapping"
)

const InferencesSimLimit = 400
Expand Down Expand Up @@ -42,7 +42,7 @@ func eliteBestPlay(ctx context.Context, p *BotTurnPlayer) (*move.Move, error) {
if tr > 0 {
log.Debug().Msg("assigning all unseen to opp")
// bag is actually empty. Assign all of unseen to the opponent.
mls := make([]alphabet.MachineLetter, tr)
mls := make([]tilemapping.MachineLetter, tr)
err := p.Game.Bag().Draw(tr, mls)
if err != nil {
return nil, err
Expand All @@ -60,7 +60,11 @@ func eliteBestPlay(ctx context.Context, p *BotTurnPlayer) (*move.Move, error) {
simPlies = unseen
} else {
moves = p.GenerateMoves(40)
simPlies = 2
if p.minSimPlies > 2 {
simPlies = p.minSimPlies
} else {
simPlies = 2
}
}
log.Debug().Int("simPlies", simPlies).
Int("simThreads", p.simThreads).
Expand All @@ -82,7 +86,7 @@ func endGameBest(ctx context.Context, p *BotTurnPlayer, endgamePlies int) (*move
// Just return the static best play if we don't have an endgame engine.
return p.GenerateMoves(1)[0], nil
}
gd, err := gaddag.Get(p.Game.Config(), p.Game.LexiconName())
gd, err := kwg.Get(p.Game.Config(), p.Game.LexiconName())
if err != nil {
return nil, err
}
Expand Down
Loading