Highlight available moves using both dice

Resolves #7.
This commit is contained in:
Trevor Slocum 2023-11-15 17:42:24 -08:00
parent a7b870fe2f
commit c5c807d8d0
5 changed files with 33 additions and 10 deletions

View file

@ -1,3 +1,6 @@
1.1.3:
- Highlight available moves using both dice
1.1.2:
- Support moving checkers by clicking instead of dragging
- Show match score during matches worth more than 1 point

View file

@ -901,12 +901,32 @@ func (b *board) Draw(screen *ebiten.Image) {
if b.highlightAvailable && b.draggingSpace != -1 {
for _, move := range b.gameState.Available {
if move[0] == b.draggingSpace {
x, y, _, _ := b.spaceRect(move[1])
x, y = b.offsetPosition(x, y)
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(x), float64(y))
op.ColorScale.Scale(0.2, 0.2, 0.2, 0.2)
screen.DrawImage(b.spaceHighlight, op)
var availableMoves func(in *bgammon.Game, from int, to int) []int
availableMoves = func(in *bgammon.Game, from int, to int) []int {
gc := in.Copy()
ok, _ := gc.AddMoves([][]int{{from, to}}, true)
if !ok {
log.Panicf("failed to add move %+v to game %+v", move, in)
}
moves := []int{to}
var found = make(map[int]bool)
found[to] = true
for _, m := range gc.LegalMoves(true) {
if m[0] == to && !found[m[1]] {
moves = append(moves, availableMoves(gc, m[0], m[1])...)
}
}
return moves
}
for _, m := range availableMoves(b.gameState.Game, move[0], move[1]) {
x, y, _, _ := b.spaceRect(m)
x, y = b.offsetPosition(x, y)
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(x), float64(y))
op.ColorScale.Scale(0.2, 0.2, 0.2, 0.2)
screen.DrawImage(b.spaceHighlight, op)
}
}
}
}

View file

@ -36,7 +36,7 @@ import (
"golang.org/x/text/language"
)
const version = "v1.1.2"
const version = "v1.1.2p2"
const MaxDebug = 2

2
go.mod
View file

@ -3,7 +3,7 @@ module code.rocket9labs.com/tslocum/boxcars
go 1.17
require (
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231115224156-c3db42daee79
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231115225155-2493c76bdfd4
code.rocket9labs.com/tslocum/etk v0.0.0-20231111061733-ffdef73ac8fb
code.rocketnine.space/tslocum/kibodo v1.0.2
code.rocketnine.space/tslocum/messeji v1.0.6-0.20231108225635-7a691903039e

4
go.sum
View file

@ -1,5 +1,5 @@
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231115224156-c3db42daee79 h1:T4poe55V1BUZqC5fT2x9NQRRdZ5xG6XW/Y6l05ljRrM=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231115224156-c3db42daee79/go.mod h1:NIwLSiHvXFJPJ6loPWJWb3esPaZT8Qk27hO6Tzassb4=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231115225155-2493c76bdfd4 h1:UG7sA9veENnBqi56fgIjLzMbVJg4EOm+3iJfU3xcCGI=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231115225155-2493c76bdfd4/go.mod h1:NIwLSiHvXFJPJ6loPWJWb3esPaZT8Qk27hO6Tzassb4=
code.rocket9labs.com/tslocum/etk v0.0.0-20231111061733-ffdef73ac8fb h1:CJgcS7SZi9ICZNCs1Hz6+YpajvCHmzyqY38xl+2z8h8=
code.rocket9labs.com/tslocum/etk v0.0.0-20231111061733-ffdef73ac8fb/go.mod h1:mwrZqZLdxJhtbWKcuX3Ym06fFr1yqWH8FMXG5wHJ/KU=
code.rocketnine.space/tslocum/kibodo v1.0.2 h1:0RfvVz+IUku8MFx9wvDb+p8byns5gAjQLUo4ZenWP44=