Skip to content

Commit

Permalink
added tablewriter to improve printing, made main and screenshot funct…
Browse files Browse the repository at this point in the history
…ions more reusable, updated readme and improved tests
  • Loading branch information
K0ntr4 committed Apr 8, 2024
1 parent 17b7b1d commit 55d5b13
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 203 deletions.
31 changes: 4 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,10 @@ The Pokemon Battle Advisor provides a convenient way to strategize and optimize
1. **Define Your Party:**

```go
func getMoveIgnoreError(name string) pokemonbattleadvisor.Move {
move, err := pokemonbattleadvisor.GetHelperStructsMove(name)
if err != nil {
return pokemonbattleadvisor.Move{}
}
return move
}

func getTypesIgnoreError(pokemonName string) []string {
types, err := pokemonbattleadvisor.GetHelperStructsTypes(pokemonName)
if err != nil {
return []string{}
}
return types
}

func main() {
var party = []pokemonbattleadvisor.Pokemon{
{
Name: "weavile", Types: getTypesIgnoreError("weavile"),
Abilities: []string{"pressure"},
Moves: []pokemonbattleadvisor.Move{
getMoveIgnoreError("poison-jab"),
getMoveIgnoreError("false-swipe"),
getMoveIgnoreError("hail"),
getMoveIgnoreError("blizzard"),
},
},
pokemonbattleadvisor.GetPartyPokemon("weavile", []string{"pressure"}, []string{"poison-jab", "false-swipe", "hail", "blizzard"}),
}
// Add more party members as needed
}
```
Expand All @@ -80,7 +56,7 @@ The Pokemon Battle Advisor provides a convenient way to strategize and optimize
```go
func getEnemyPokemon() (enemy pokemonbattleadvisor.Pokemon) {
// Capture a screenshot of the battle
screenshot, err := pokemonbattleadvisor.TakeScreenshot()
screenshot, err = pokemonbattleadvisor.TakeScreenshot(0, 1250, 450, 1600, 800) // Adjust display and coordinates as needed
if err != nil {
return
}
Expand Down Expand Up @@ -140,5 +116,6 @@ The Pokemon Battle Advisor project utilizes several external libraries and resou
- [imjeffhi/pokemon_classifier](https://huggingface.co/imjeffhi/pokemon_classifier): Utilizes a Hugging Face model for Pokemon classification.
- [sajari/fuzzy](https://pkg.go.dev/github.com/sajari/fuzzy@v1.0.0): Implements fuzzy search functionality for improved user experience.
- [kbinani/screenshot](https://pkg.go.dev/github.com/kbinani/screenshot@v0.0.0-20230812210009-b87d31814237): Enables capturing screenshots for automatic enemy detection.
- [olekukonko/typewriter](https://pkg.go.dev/github.com/olekukonko/tablewriter@v0.0.5): Provides table formatting functionality for improved output presentation.

Special thanks to the developers and maintainers of these libraries for their contributions to the Pokemon Battle Advisor project. Their work greatly enhances the functionality and usability of the tool.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ require (
github.com/Kardbord/hfapigo/v2 v2.1.0
github.com/kbinani/screenshot v0.0.0-20230812210009-b87d31814237
github.com/mtslzr/pokeapi-go v1.4.0
github.com/olekukonko/tablewriter v0.0.5
github.com/sajari/fuzzy v1.0.0
)

require (
github.com/gen2brain/shm v0.0.0-20230802011745-f2460f5984f7 // indirect
github.com/jezek/xgb v1.1.0 // indirect
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
golang.org/x/sys v0.11.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ github.com/kbinani/screenshot v0.0.0-20230812210009-b87d31814237 h1:YOp8St+CM/AQ
github.com/kbinani/screenshot v0.0.0-20230812210009-b87d31814237/go.mod h1:e7qQlOY68wOz4b82D7n+DdaptZAi+SHW0+yKiWZzEYE=
github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc=
github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mtslzr/pokeapi-go v1.4.0 h1:fp8+9OOxY168Nk4Tk27wCNG9f8MV+MVWO1fIlKjWW/M=
github.com/mtslzr/pokeapi-go v1.4.0/go.mod h1:QYc519LxPVY3T2fm8ufHfvGSu4xUG+erNLHA5luiqq0=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
90 changes: 11 additions & 79 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func getEnemyPokemon() (enemy pokemonbattleadvisor.Pokemon) {
var screenshot string
var classifierResult string

screenshot, err = pokemonbattleadvisor.TakeScreenshot()
screenshot, err = pokemonbattleadvisor.TakeScreenshot(0, 1250, 450, 1600, 800)
if err != nil {
return
}
Expand All @@ -40,95 +40,27 @@ func getEnemyPokemon() (enemy pokemonbattleadvisor.Pokemon) {
return enemy
}

func getMoveIgnoreError(name string) pokemonbattleadvisor.Move {
move, err := pokemonbattleadvisor.GetHelperStructsMove(name)
if err != nil {
return pokemonbattleadvisor.Move{}
}
return move
}

func getTypesIgnoreError(pokemonName string) []string {
types, err := pokemonbattleadvisor.GetHelperStructsTypes(pokemonName)
if err != nil {
return []string{}
}
return types
}

func main() {
var enemy = getEnemyPokemon()
var party = []pokemonbattleadvisor.Pokemon{
{
Name: "weavile", Types: getTypesIgnoreError("weavile"),
Abilities: []string{"pressure"},
Moves: []pokemonbattleadvisor.Move{
getMoveIgnoreError("poison-jab"),
getMoveIgnoreError("false-swipe"),
getMoveIgnoreError("hail"),
getMoveIgnoreError("blizzard"),
},
},
{
Name: "clefable", Types: getTypesIgnoreError("clefable"),
Abilities: []string{"unaware"},
Moves: []pokemonbattleadvisor.Move{
getMoveIgnoreError("moonblast"),
getMoveIgnoreError("flash"),
getMoveIgnoreError("flamethrower"),
getMoveIgnoreError("double-slap"),
},
},
{
Name: "azumarill", Types: getTypesIgnoreError("azumarill"),
Abilities: []string{"huge-power"},
Moves: []pokemonbattleadvisor.Move{
getMoveIgnoreError("ice-beam"),
getMoveIgnoreError("play-rough"),
getMoveIgnoreError("surf"),
getMoveIgnoreError("hydro-pump"),
},
},
{
Name: "luxray", Types: getTypesIgnoreError("luxray"),
Abilities: []string{"rivalry"},
Moves: []pokemonbattleadvisor.Move{
getMoveIgnoreError("thunderbolt"),
getMoveIgnoreError("crunch"),
getMoveIgnoreError("flash"),
getMoveIgnoreError("discharge"),
},
},
{
Name: "ludicolo", Types: getTypesIgnoreError("ludicolo"),
Abilities: []string{"swift-swim"},
Moves: []pokemonbattleadvisor.Move{
getMoveIgnoreError("dive"),
getMoveIgnoreError("surf"),
getMoveIgnoreError("giga-drain"),
getMoveIgnoreError("energy-ball"),
},
},
{
Name: "sceptile", Types: getTypesIgnoreError("sceptile"),
Abilities: []string{"overgrow"},
Moves: []pokemonbattleadvisor.Move{
getMoveIgnoreError("cut"),
getMoveIgnoreError("dig"),
getMoveIgnoreError("energy-ball"),
getMoveIgnoreError("giga-drain"),
},
},
pokemonbattleadvisor.GetPartyPokemon("weavile", []string{"pressure"}, []string{"poison-jab", "false-swipe", "hail", "blizzard"}),
pokemonbattleadvisor.GetPartyPokemon("clefable", []string{"unaware"}, []string{"moonblast", "flash", "flamethrower", "double-slap"}),
pokemonbattleadvisor.GetPartyPokemon("azumarill", []string{"huge-power"}, []string{"ice-beam", "play-rough", "surf", "hydro-pump"}),
pokemonbattleadvisor.GetPartyPokemon("luxray", []string{"rivalry"}, []string{"thunderbolt", "crunch", "flash", "discharge"}),
pokemonbattleadvisor.GetPartyPokemon("ludicolo", []string{"swift-swim"}, []string{"dive", "surf", "giga-drain", "energy-ball"}),
pokemonbattleadvisor.GetPartyPokemon("sceptile", []string{"overgrow"}, []string{"cut", "dig", "energy-ball", "giga-drain"}),
}
pokemonbattleadvisor.PrintParty(&party)

partyMember, move, shouldSwitch := pokemonbattleadvisor.BestPokemonMoveAndShouldSwitch(&party, &enemy)
if shouldSwitch {
fmt.Println("Should switch")
fmt.Printf("Best party member: %s\n", party[partyMember].Name)
fmt.Printf("Best move: %s\n", party[partyMember].Moves[move].Name)
fmt.Println("Best move:")
pokemonbattleadvisor.PrintHelperStructsMove(&party[partyMember].Moves[move])
} else {
fmt.Println("Should not switch")
fmt.Printf("Best move: %s\n", party[0].Moves[move].Name)
fmt.Println("Best move:")
pokemonbattleadvisor.PrintHelperStructsMove(&party[partyMember].Moves[move])
}
}
46 changes: 46 additions & 0 deletions src/screenshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package pokemonbattleadvisor

import (
"fmt"
"github.com/kbinani/screenshot"
"image"
"image/png"
"os"
)

const defaultScreenshotPath = "screenshot.png"

func save(img *image.RGBA, filePath string) (err error) {
var file *os.File
file, err = os.Create(filePath)
if err != nil {
return err
}
defer file.Close()
err = png.Encode(file, img)
if err != nil {
return err
}
return nil
}

func TakeScreenshot(monitorIndex int, boundaries ...int) (string, error) {
var img *image.RGBA
var err error

if !(len(boundaries) == 4) {
fmt.Printf("No correct boundaries provided, taking full screenshot\n")
img, err = screenshot.CaptureDisplay(monitorIndex)
} else {
img, err = screenshot.CaptureRect(image.Rect(boundaries[0], boundaries[1], boundaries[2], boundaries[3]))
}
if err != nil {
return "", err
}

err = save(img, defaultScreenshotPath)
if err != nil {
return "", err
}
return defaultScreenshotPath, nil
}
57 changes: 0 additions & 57 deletions src/takeScreenshot.go

This file was deleted.

Loading

0 comments on commit 55d5b13

Please sign in to comment.