Skip to content

Commit

Permalink
Tweak pawn structure and king safety rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjpro committed Mar 8, 2021
1 parent 2633bf8 commit 699ad2f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
42 changes: 32 additions & 10 deletions evaluation/evaluation.go
Expand Up @@ -625,18 +625,29 @@ func Evaluate(position *Position) int32 {
}
if blackPawnsPerFile[f] == 0 { // no pawn here
if whitePawnsPerFile[f] == 0 { // open file!!
blackKingSafetyCentiPawns -= 90
blackKingSafetyCentiPawns -= 60
} else {
blackKingSafetyCentiPawns -= 70
blackKingSafetyCentiPawns -= 50
}
} else {
blackKingSafetyCentiPawns -= 6 * (int32(Rank8 - blackLeastAdvancedPawnsPerFile[f]))
if blackLeastAdvancedPawnsPerFile[f] == Rank5 {
blackKingSafetyCentiPawns -= 25
} else if blackLeastAdvancedPawnsPerFile[f] <= Rank4 {
blackKingSafetyCentiPawns -= 35 + 8 - int32(blackLeastAdvancedPawnsPerFile[f])
}
}

if whitePawnsPerFile[f] != 0 {
blackKingSafetyCentiPawns -= 5 * int32(whiteMostAdvancedPawnsPerFile[f])
if whiteMostAdvancedPawnsPerFile[f] >= Rank5 {
blackKingSafetyCentiPawns -= 25
}
} else {
blackKingSafetyCentiPawns -= 60 // black can pile up
wfile := int8(whiteKingSquare.File())
if File(wfile-1) != file &&
File(wfile) != file &&
File(wfile)+1 != file {
blackKingSafetyCentiPawns -= 40 // white can pile up
}
}
}
}
Expand Down Expand Up @@ -670,18 +681,29 @@ func Evaluate(position *Position) int32 {
}
if whitePawnsPerFile[f] == 0 { // no pawn here
if blackPawnsPerFile[f] == 0 { // open file!!
whiteKingSafetyCentiPawns -= 90
whiteKingSafetyCentiPawns -= 60
} else {
whiteKingSafetyCentiPawns -= 70
whiteKingSafetyCentiPawns -= 50
}
} else {
whiteKingSafetyCentiPawns -= 6 * int32(whiteLeastAdvancedPawnsPerFile[f])
if whiteLeastAdvancedPawnsPerFile[f] == Rank4 {
whiteKingSafetyCentiPawns -= 25
} else if whiteLeastAdvancedPawnsPerFile[f] >= Rank4 {
whiteKingSafetyCentiPawns -= 35 + int32(whiteLeastAdvancedPawnsPerFile[f])
}
}

if blackPawnsPerFile[f] != 0 {
whiteKingSafetyCentiPawns -= 5 * (int32(Rank8 - blackMostAdvancedPawnsPerFile[f]))
if blackMostAdvancedPawnsPerFile[f] <= Rank4 {
whiteKingSafetyCentiPawns -= 25
}
} else {
whiteKingSafetyCentiPawns -= 60 // black can pile up
bfile := int8(blackKingSquare.File())
if File(bfile-1) != file &&
File(bfile) != file &&
File(bfile)+1 != file {
whiteKingSafetyCentiPawns -= 40 // black can pile up
}
}
}
}
Expand Down
30 changes: 12 additions & 18 deletions evaluation/evaluation_test.go
Expand Up @@ -99,21 +99,19 @@ func TestRookStructureEval(t *testing.T) {
game := FromFen(fen, true)

actual := Evaluate(game.Position())
expected := int32(39)

if actual != expected {
err := fmt.Sprintf("Semi-open file - White:\nExpected: %d\nGot: %d\n", expected, actual)
if actual <= 0 {
err := fmt.Sprintf("Semi-open file - White:\nExpected: positive \nGot: %d\n", actual)
t.Errorf(err)
}

fen = "k4r2/4p3/8/8/8/8/5P2/K4R2 b - - 0 1"
game = FromFen(fen, true)

actual = Evaluate(game.Position())
expected = int32(39)

if actual != expected {
err := fmt.Sprintf("Semi-open file - Black:\nExpected: %d\nGot: %d\n", expected, actual)
if actual <= 0 {
err := fmt.Sprintf("Semi-open file - Black:\nExpected: positive \nGot: %d\n", actual)
t.Errorf(err)
}
}
Expand All @@ -124,10 +122,9 @@ func TestKingSafetyEval(t *testing.T) {
game := FromFen(fen, true)

actual := Evaluate(game.Position())
expected := int32(-4)

if actual != expected {
err := fmt.Sprintf("Advanced Own Pawn - White:\nExpected: %d\nGot: %d\n", expected, actual)
if actual >= 0 {
err := fmt.Sprintf("Advanced Own Pawn - White:\nExpected: negative \nGot: %d\n", actual)
t.Errorf(err)
}

Expand All @@ -136,10 +133,9 @@ func TestKingSafetyEval(t *testing.T) {
game = FromFen(fen, true)

actual = Evaluate(game.Position())
expected = int32(-4)

if actual != expected {
err := fmt.Sprintf("Advanced Own Pawn - Black:\nExpected: %d\nGot: %d\n", expected, actual)
if actual >= 0 {
err := fmt.Sprintf("Advanced Own Pawn - Black:\nExpected: negative \nGot: %d\n", actual)
t.Errorf(err)
}

Expand All @@ -148,21 +144,19 @@ func TestKingSafetyEval(t *testing.T) {
game = FromFen(fen, true)

actual = Evaluate(game.Position())
expected = int32(-33)

if actual != expected {
err := fmt.Sprintf("Missing Own Pawn -open file - Black:\nExpected: %d\nGot: %d\n", expected, actual)
if actual >= 0 {
err := fmt.Sprintf("Missing Own Pawn -open file - White:\nExpected: negative\nGot: %d\n", actual)
t.Errorf(err)
}
fen = "krq5/1pp3pp/8/8/8/8/PPP4P/KRQ5 b - - 0 1"

game = FromFen(fen, true)

actual = Evaluate(game.Position())
expected = int32(-33)

if actual != expected {
err := fmt.Sprintf("Missing Own Pawn -open file - Black:\nExpected: %d\nGot: %d\n", expected, actual)
if actual >= 0 {
err := fmt.Sprintf("Missing Own Pawn -open file - Black:\nExpected: negative\nGot: %d\n", actual)
t.Errorf(err)
}
}

0 comments on commit 699ad2f

Please sign in to comment.