Health | Weapons | The enemies | Decision |
50 | one | one | Attack |
90 | one | 2 | Attack |
80 | 0 | one | Attack |
thirty | one | one | Steal |
60 | one | 2 | Steal |
40 | 0 | one | Steal |
90 | one | 7 | Run away |
60 | one | four | Run away |
ten | 0 | one | Run away |
60 | one | 0 | Nothing to do |
100 | 0 | 0 | Nothing to do |
go get github.com/fxsjy/gonn/gonn
import ( "fmt" "github.com/fxsjy/gonn/gonn" )
func CreateNN() { // 3 ( ), // 16 // 4 ( ) nn := gonn.DefaultNetwork(3, 16, 4, false) // : // 1 - (0.1 - 1.0) // 2 - (0 - , 1 - ) // 3 - input := [][]float64 { []float64{0.5, 1, 1}, []float64{0.9, 1, 2}, []float64{0.8, 0, 1}, []float64{0.3, 1, 1}, []float64{0.6, 1, 2}, []float64{0.4, 0, 1}, []float64{0.9, 1, 7}, []float64{0.6, 1, 4}, []float64{0.1, 0, 1}, []float64{0.6, 1, 0}, []float64{1, 0, 0} } // "" - , target := [][]float64 { []float64{1, 0, 0, 0}, []float64{1, 0, 0, 0}, []float64{1, 0, 0, 0}, []float64{0, 1, 0, 0}, []float64{0, 1, 0, 0}, []float64{0, 1, 0, 0}, []float64{0, 0, 1, 0}, []float64{0, 0, 1, 0}, []float64{0, 0, 1, 0}, []float64{0, 0, 0, 1}, []float64{0, 0, 0, 1} } // . // - 100000 nn.Train(input, target, 100000) // . gonn.DumpNN("gonn", nn) }
func GetResult(output []float64) string { max := -99999 pos := -1 // . for i, value := range output { if (value > max) { max = value pos = i } } // , , . switch pos { case 0: return "" case 1: return "" case 2: return "" case 3: return " " } return "" }
func main() { CreateNN() // . nn := gonn.LoadNN("gonn") // : // hp - (0.1 - 1.0) // weapon - (0 - , 1 - ) // enemyCount - var hp float64 = 0.7 var weapon float64 = 1.0 var enemyCount float64 = 1.0 // ( ) out := nn.Forward([]float64{ hp, weapon, enemyCount }) // . fmt.Println(GetResult(out)) }
Source: https://habr.com/ru/post/343466/
All Articles