Fix scoring blots
This commit is contained in:
parent
1703a504b5
commit
d71f37392c
3 changed files with 34 additions and 43 deletions
|
@ -27,8 +27,8 @@ score = pips*pipsWeight
|
|||
All scoring calculations use pseudopips.
|
||||
|
||||
Space value is defined as what the term 'pips' would normally refer to for a
|
||||
given space. The value of a space isthe same as the space number as it would
|
||||
appear to the player being scored.
|
||||
given space. The value of a space is the same as the space number as it appears
|
||||
to the player being scored.
|
||||
|
||||
Base value is 12 for spaces within the home board of the player being scored.
|
||||
All other spaces have a base value of 36. The base values incentivize
|
||||
|
|
31
board.go
31
board.go
|
@ -80,9 +80,9 @@ func (b Board) Move(from int, to int, player int) Board {
|
|||
if (player == 1 && b[to] == -1) || (player == 2 && b[to] == 1) {
|
||||
b[to] = 0
|
||||
if player == 1 {
|
||||
b[SpaceBarOpponent] -= 1
|
||||
b[SpaceBarOpponent]--
|
||||
} else {
|
||||
b[SpaceBarPlayer] += 1
|
||||
b[SpaceBarPlayer]++
|
||||
}
|
||||
} else if (player == 1 && b[to] < 0) || (player == 2 && b[to] > 0) {
|
||||
b.Print()
|
||||
|
@ -258,8 +258,7 @@ func (b Board) Available(player int) [][]int {
|
|||
return moves
|
||||
}
|
||||
|
||||
// TODO no player argument needed
|
||||
func (b Board) Past(player int) bool {
|
||||
func (b Board) Past() bool {
|
||||
if b[SpaceBarPlayer] != 0 || b[SpaceBarOpponent] != 0 {
|
||||
return false
|
||||
}
|
||||
|
@ -269,24 +268,16 @@ func (b Board) Past(player int) bool {
|
|||
if v == 0 {
|
||||
continue
|
||||
} else if v > 0 {
|
||||
if player == 1 && space > playerFirst {
|
||||
if space > playerFirst {
|
||||
playerFirst = space
|
||||
} else if player == 2 && space > opponentLast {
|
||||
opponentLast = space
|
||||
}
|
||||
} else {
|
||||
if player == 1 && opponentLast == 0 {
|
||||
if opponentLast == 0 {
|
||||
opponentLast = space
|
||||
} else if player == 2 && playerFirst == 0 {
|
||||
playerFirst = space
|
||||
}
|
||||
}
|
||||
}
|
||||
if player == 1 {
|
||||
return playerFirst < opponentLast
|
||||
} else {
|
||||
return playerFirst > opponentLast
|
||||
}
|
||||
return playerFirst < opponentLast
|
||||
}
|
||||
|
||||
func (b Board) Pips(player int) int {
|
||||
|
@ -320,7 +311,7 @@ func (b Board) evaluate(player int, hitScore int, a *Analysis) {
|
|||
score := float64(pips)
|
||||
var blots int
|
||||
if !a.Past {
|
||||
blots := b.Blots(player)
|
||||
blots = b.Blots(player)
|
||||
score += float64(blots)*WeightBlot + float64(hitScore)*WeightHit
|
||||
}
|
||||
a.Pips = pips
|
||||
|
@ -331,11 +322,10 @@ func (b Board) evaluate(player int, hitScore int, a *Analysis) {
|
|||
}
|
||||
|
||||
func (b Board) Evaluation(player int, hitScore int, moves [][]int) *Analysis {
|
||||
past := b.Past(player)
|
||||
a := &Analysis{
|
||||
Board: b,
|
||||
Moves: moves,
|
||||
Past: past,
|
||||
Past: b.Past(),
|
||||
}
|
||||
b.evaluate(player, hitScore, a)
|
||||
return a
|
||||
|
@ -397,7 +387,7 @@ func (b Board) Analyze(player int, available [][]int) []*Analysis {
|
|||
resultMutex := &sync.Mutex{}
|
||||
|
||||
a := &Analysis{
|
||||
Past: b.Past(player),
|
||||
Past: b.Past(),
|
||||
}
|
||||
b.evaluate(player, 0, a)
|
||||
|
||||
|
@ -489,9 +479,8 @@ func (b Board) Print() {
|
|||
func opponent(player int) int {
|
||||
if player == 1 {
|
||||
return 2
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
func spaceValue(player int, space int) int {
|
||||
|
|
|
@ -38,41 +38,25 @@ func TestMove(t *testing.T) {
|
|||
|
||||
func TestPast(t *testing.T) {
|
||||
b := NewBoard()
|
||||
got, expected := b.Past(1), false
|
||||
if got != expected {
|
||||
t.Errorf("unexpected past value: expected %v: got %v", expected, got)
|
||||
}
|
||||
got, expected = b.Past(2), false
|
||||
got, expected := b.Past(), false
|
||||
if got != expected {
|
||||
t.Errorf("unexpected past value: expected %v: got %v", expected, got)
|
||||
}
|
||||
|
||||
b = Board{0, 1, 3, -1, 0, -1, 0, -2, 0, 0, -1, 0, -3, 3, 0, 0, 0, -2, 0, -5, 4, 0, 2, 2, 0, 0, 0, 0, 5, 5, 5, 5}
|
||||
got, expected = b.Past(1), false
|
||||
if got != expected {
|
||||
t.Errorf("unexpected past value: expected %v: got %v", expected, got)
|
||||
}
|
||||
got, expected = b.Past(2), false
|
||||
got, expected = b.Past(), false
|
||||
if got != expected {
|
||||
t.Errorf("unexpected past value: expected %v: got %v", expected, got)
|
||||
}
|
||||
|
||||
b = Board{0, -1, 1, -2, -1, 2, 4, 0, 0, 0, 0, 0, -1, 2, -1, 0, 0, -1, 3, -3, 0, 3, -1, -3, -1, 0, 0, 0, 4, 3, 0, 0}
|
||||
got, expected = b.Past(1), false
|
||||
if got != expected {
|
||||
t.Errorf("unexpected past value: expected %v: got %v", expected, got)
|
||||
}
|
||||
got, expected = b.Past(2), false
|
||||
got, expected = b.Past(), false
|
||||
if got != expected {
|
||||
t.Errorf("unexpected past value: expected %v: got %v", expected, got)
|
||||
}
|
||||
|
||||
b = Board{7, 2, 2, 4, 0, -2, 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, -1, -1, 0, -4, 0, -2, -1, -1, -1, 0, 0, 0, 6, 2, 0, 0}
|
||||
got, expected = b.Past(1), true
|
||||
if got != expected {
|
||||
t.Errorf("unexpected past value: expected %v: got %v", expected, got)
|
||||
}
|
||||
got, expected = b.Past(2), true
|
||||
got, expected = b.Past(), true
|
||||
if got != expected {
|
||||
t.Errorf("unexpected past value: expected %v: got %v", expected, got)
|
||||
}
|
||||
|
@ -112,6 +96,24 @@ func TestBlots(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAnalyze(t *testing.T) {
|
||||
b := NewBoard()
|
||||
b = b.Move(24, 23, 1)
|
||||
b = b.Move(1, 2, 2)
|
||||
b[SpaceRoll1], b[SpaceRoll2] = 1, 2
|
||||
|
||||
for player := 1; player <= 2; player++ {
|
||||
r := b.Analyze(player, b.Available(player))
|
||||
var blots int
|
||||
for _, r := range r {
|
||||
blots += r.Blots
|
||||
}
|
||||
if blots <= 0 {
|
||||
t.Errorf("expected >0 blots for player %d in results, got %d", player, blots)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAvailable(b *testing.B) {
|
||||
type testCase struct {
|
||||
roll1, roll2, roll3, roll4 int8
|
||||
|
|
Loading…
Reference in a new issue