Increase AI opponent difficulty

This commit is contained in:
Trevor Slocum 2023-02-01 10:52:45 -08:00
parent 3483dd4174
commit be89bd5e9c
6 changed files with 20 additions and 18 deletions

View File

@ -78,6 +78,8 @@ Please share issues and suggestions [here](https://code.rocketnine.space/tslocum
## Credits
- [Trevor Slocum](https://rocketnine.space) - Game design and programming
- [node punk](https://open.spotify.com/artist/15eFpWQPNRxB89PnFNWvjU?si=z-jfVwYHTxugaC-BGZiyNg) - Music
## Dependencies

View File

@ -721,7 +721,7 @@ func (g *Game) Update() error {
if preset == world.TPS {
if i > 0 {
world.TPS = world.TPSPresets[i-1]
ebiten.SetMaxTPS(world.TPS)
ebiten.SetTPS(world.TPS)
log.Printf("Set TPS to %d", world.TPS)
break
}
@ -735,7 +735,7 @@ func (g *Game) Update() error {
if preset == world.TPS {
if i < len(world.TPSPresets)-1 {
world.TPS = world.TPSPresets[i+1]
ebiten.SetMaxTPS(world.TPS)
ebiten.SetTPS(world.TPS)
log.Printf("Set TPS to %d", world.TPS)
break
}

View File

@ -129,19 +129,28 @@ func botInput() InputBits {
o := &world.Player1
const (
botMaxActionTime = 20
botWaitChance = 5
botMaxActionTime = 15
botWaitChance = 7
botPunchDistance = 25
botKickDistance = 25
botKickChance = 4
botBlockDistance = 35
botBlockTime = 35
botBlockChance = 5
botBlockTime = 20
botBlockChance = 2
botTauntMinTime = 60
botTauntTime = 200
botTauntMaxTime = 550
)
defer func() {
if !input.isButtonOn(ButtonPunch) {
botLastPunch++
}
if !input.isButtonOn(ButtonKick) {
botLastKick++
}
}()
if botTicks == 0 {
botTicks = rand.Intn(botMaxActionTime)
botWait = rand.Intn(botWaitChance) == 0 && world.Winner == 0
@ -217,13 +226,6 @@ func botInput() InputBits {
}
}
}
if !input.isButtonOn(ButtonPunch) {
botLastPunch++
}
if !input.isButtonOn(ButtonKick) {
botLastKick++
}
return input
}

2
go.mod
View File

@ -22,5 +22,3 @@ require (
golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect
golang.org/x/sys v0.4.0 // indirect
)
replace github.com/assemblaj/ggpo => github.com/tslocum/ggpo v0.0.0-20230130221056-9cfe5a275c31

4
go.sum
View File

@ -1,6 +1,8 @@
code.rocketnine.space/tslocum/gohan v1.0.0 h1:WBcJq7nVfmr1EB8bew6xWlB5Q1714yWJ3a9/q6aBBrY=
code.rocketnine.space/tslocum/gohan v1.0.0/go.mod h1:12yOt5Ygl/RVwnnZSVZRuS1W6gCaHJgezcvg8+THk10=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/assemblaj/ggpo v0.0.0-20230129160025-68dbb12db83e h1:tfcqziT05uc2ow93d8csUPVmt7EKnO3cGwMb2+mGOJ4=
github.com/assemblaj/ggpo v0.0.0-20230129160025-68dbb12db83e/go.mod h1:ZKiAYEZgxDlGHGeP/VZsv1+xIRo9kQpgUFmjP/PR0lQ=
github.com/ebitengine/purego v0.0.0-20220905075623-aeed57cda744/go.mod h1:Eh8I3yvknDYZeCuXH9kRNaPuHEwvXDCk378o9xszmHg=
github.com/ebitengine/purego v0.1.1 h1:HI8nW+LniW9Yb34k34jBs8nz+PNzsw68o7JF8jWFHHE=
github.com/ebitengine/purego v0.1.1/go.mod h1:Eh8I3yvknDYZeCuXH9kRNaPuHEwvXDCk378o9xszmHg=
@ -26,8 +28,6 @@ github.com/jfreymuth/oggvorbis v1.0.4/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHix
github.com/jfreymuth/vorbis v1.0.2 h1:m1xH6+ZI4thH927pgKD8JOH4eaGRm18rEE9/0WKjvNE=
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/tslocum/ggpo v0.0.0-20230130221056-9cfe5a275c31 h1:4Lx50UoTEn6YHtHbN2NJe2WVJ95jO53svDIjXtGgep0=
github.com/tslocum/ggpo v0.0.0-20230130221056-9cfe5a275c31/go.mod h1:ZKiAYEZgxDlGHGeP/VZsv1+xIRo9kQpgUFmjP/PR0lQ=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
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=

View File

@ -45,7 +45,7 @@ func main() {
}
// Run normally.
ebiten.SetMaxTPS(world.TPS)
ebiten.SetTPS(world.TPS)
ebiten.SetFullscreen(world.Fullscreen)
if world.DisableVsync {
ebiten.SetFPSMode(ebiten.FPSModeVsyncOffMaximum)