Make the AI a little smarter.
This commit is contained in:
+22
-4
@@ -9,16 +9,34 @@ import (
|
||||
)
|
||||
|
||||
// winScore converts a simulated battle outcome to a utility for mySeat:
|
||||
// win 1, draw 0.5 (nobody gains ground), loss 0.
|
||||
// win 1, draw 0.5 (nobody gains ground), loss 0, plus a small margin term.
|
||||
//
|
||||
// The margin — your surviving pets minus the enemy's — breaks ties among
|
||||
// outcomes that share a verdict: a loss where you took most of the enemy down
|
||||
// beats a wipe, and a decisive win beats a squeaker. It is capped well under
|
||||
// 0.25 so it can never reorder win above draw above loss; it only decides
|
||||
// between moves the coarse win/draw/loss signal rates identically. That
|
||||
// gradient is what makes the bot play on sensibly when every option looks
|
||||
// hopeless — fielding its strongest force instead of picking at random.
|
||||
func winScore(res *game.BattleResult, mySeat int) float64 {
|
||||
var base float64
|
||||
switch res.WinnerSeat {
|
||||
case mySeat:
|
||||
return 1
|
||||
base = 1
|
||||
case -1:
|
||||
return 0.5
|
||||
base = 0.5
|
||||
default:
|
||||
return 0
|
||||
base = 0
|
||||
}
|
||||
margin := 0
|
||||
for seat, s := range res.Survivors {
|
||||
if seat == mySeat {
|
||||
margin += s
|
||||
} else {
|
||||
margin -= s
|
||||
}
|
||||
}
|
||||
return base + 0.1*math.Tanh(float64(margin)/3)
|
||||
}
|
||||
|
||||
// winProb estimates the chance the arranged deck wins the upcoming battle by
|
||||
|
||||
Reference in New Issue
Block a user