Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 17 additions & 17 deletions cmd/enumerate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"

. "github.com/fogleman/rush"
"github.com/fogleman/rush"
)

const (
Expand All @@ -26,18 +26,18 @@ const (
)

type Enumerator struct {
Board *Board
Board *rush.Board
Seen map[string]bool
Memo *Memo
Solver *Solver
HardestSolution Solution
HardestBoard *Board
Memo *rush.Memo
Solver *rush.Solver
HardestSolution rush.Solution
HardestBoard *rush.Board
Canonical bool
CanonicalKey MemoKey
CanonicalKey rush.MemoKey
Count int
}

func NewEnumerator(board *Board) *Enumerator {
func NewEnumerator(board *rush.Board) *Enumerator {
e := &Enumerator{}
e.Board = board
e.Seen = make(map[string]bool)
Expand Down Expand Up @@ -69,8 +69,8 @@ func (e *Enumerator) hardestSearch(previousPiece int) {
}

func (e *Enumerator) HardestSearch() {
e.Memo = NewMemo()
e.Solver = NewSolver(e.Board)
e.Memo = rush.NewMemo()
e.Solver = rush.NewSolver(e.Board)
e.HardestBoard = e.Board.Copy()
e.HardestSolution = e.Solver.Solve()
e.hardestSearch(-1)
Expand Down Expand Up @@ -107,7 +107,7 @@ func (e *Enumerator) canonicalSearch(previousPiece int) {
}

func (e *Enumerator) CanonicalSearch() {
e.Memo = NewMemo()
e.Memo = rush.NewMemo()
e.Canonical = true
e.CanonicalKey = *e.Board.MemoKey()
e.canonicalSearch(-1)
Expand Down Expand Up @@ -148,25 +148,25 @@ func (e *Enumerator) place(after int) {
h := board.Height
i := len(board.Pieces)

for o := Horizontal; o <= Vertical; o++ {
for o := rush.Horizontal; o <= rush.Vertical; o++ {
for s := 2; s <= 3; s++ {
xx := w
yy := h
if o == Horizontal {
if o == rush.Horizontal {
xx = W - s + 1
} else {
yy = H - s + 1
}
for y := 0; y < yy; y++ {
if o == Horizontal && y == Py {
if o == rush.Horizontal && y == Py {
continue
}
for x := 0; x < xx; x++ {
p := y*W + x
if p <= after {
continue
}
if board.AddPiece(Piece{p, s, o}) {
if board.AddPiece(rush.Piece{Position: p, Size: s, Orientation: o}) {
e.place(p)
board.RemovePiece(i)
}
Expand All @@ -181,8 +181,8 @@ func (e *Enumerator) Enumerate() {
}

func main() {
board := NewEmptyBoard(W, H)
board.AddPiece(Piece{P, 2, Horizontal})
board := rush.NewEmptyBoard(W, H)
board.AddPiece(rush.Piece{Position: P, Size: 2, Orientation: rush.Horizontal})
e := NewEnumerator(board)
e.Enumerate()
fmt.Println(len(e.Seen), e.Count)
Expand Down
4 changes: 2 additions & 2 deletions cmd/universe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (pg *PositionGenerator) precomputeRow(y, x int, pieces []Piece) {
continue
}
p := y*w + x
pieces = append(pieces, Piece{p, s, Horizontal})
pieces = append(pieces, Piece{Position: p, Size: s, Orientation: Horizontal})
pg.precomputeRow(y, x+s, pieces)
pieces = pieces[:len(pieces)-1]
}
Expand All @@ -218,7 +218,7 @@ func (pg *PositionGenerator) precomputeCol(x, y int, pieces []Piece) {
continue
}
p := y*w + x
pieces = append(pieces, Piece{p, s, Vertical})
pieces = append(pieces, Piece{Position: p, Size: s, Orientation: Vertical})
pg.precomputeCol(x, y+s, pieces)
pieces = pieces[:len(pieces)-1]
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/unsolver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
fmt.Println()

unsolver := rush.NewUnsolver(board)
unsolved := unsolver.Unsolve()
unsolved, _ := unsolver.Unsolve()
solution := unsolved.Solve()

fmt.Println(unsolved)
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/fogleman/rush

go 1.19

require github.com/fogleman/gg v1.3.0

require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
golang.org/x/image v0.20.0 // indirect
)
32 changes: 32 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.2.0 h1:/DcQ0w3VHKCC5p0/P2B0JpAZ9Z++V2KOo2fyU89CXBQ=
golang.org/x/image v0.2.0/go.mod h1:la7oBXb9w3YFjBqaAwtynVioc1ZvOnNteUNrifGNmAI=
golang.org/x/image v0.20.0 h1:7cVCUjQwfL18gyBJOmYvptfSHS8Fb3YUDtfLIZ7Nbpw=
golang.org/x/image v0.20.0/go.mod h1:0a88To4CYVBAHp5FXJm8o7QbUl37Vd85ply1vyD8auM=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
8 changes: 4 additions & 4 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (move Move) AbsSteps() int {
}

func (move Move) Label() string {
return string('A' + move.Piece)
return indexToLabelString(move.Piece)
}

func (move Move) String() string {
Expand Down Expand Up @@ -186,7 +186,7 @@ func (board *Board) String() string {
grid[i] = "x"
}
for i, piece := range board.Pieces {
label := string('A' + i)
label := indexToLabelString(i)
idx := piece.Position
stride := piece.Stride(w)
for j := 0; j < piece.Size; j++ {
Expand All @@ -213,7 +213,7 @@ func (board *Board) Hash() string {
grid[i] = 'x'
}
for i, piece := range board.Pieces {
label := rune('A' + i)
label := indexToLabelRune(i)
idx := piece.Position
stride := 1
if piece.Orientation == Vertical {
Expand Down Expand Up @@ -323,7 +323,7 @@ func (board *Board) Validate() error {
// validate pieces
primaryRow := pieces[0].Row(w)
for i, piece := range pieces {
label := string('A' + i)
label := indexToLabelString(i)
row := piece.Row(w)
col := piece.Col(w)

Expand Down
2 changes: 1 addition & 1 deletion render.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func renderBoard(board *Board) image.Image {
tx := px + pw/2
ty := py + ph/2
dc.SetHexColor(labelColor)
dc.DrawStringAnchored(string('A'+i), tx, ty, 0.5, 0.5)
dc.DrawStringAnchored(indexToLabelString(i), tx, ty, 0.5, 0.5)
}
}

Expand Down
8 changes: 8 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ func maxInt(a, b int) int {
}
return b
}

func indexToLabelRune(i int) rune {
return 'A' + rune(i)
}

func indexToLabelString(i int) string {
return string(indexToLabelRune(i))
}