Browse Source

Fix ChoiceMap and skill/Song output

master
Noëlle Anthony 5 years ago
parent
commit
e6e4a31557
2 changed files with 59 additions and 32 deletions
  1. 53
    28
      main.go
  2. 6
    4
      src/util/arrays.go

+ 53
- 28
main.go View File

@@ -3,8 +3,9 @@ package main
import (
"fmt"
"math/rand"
// "sort"
// "strings"
"sort"
"strconv"
"strings"
"time"
"util"
)
@@ -152,36 +153,60 @@ func main() {
for i := cp; i > b; i-- {
r := rand.Intn(15)
if r < sklBrk { // it's a skill
q := rand.Intn(ply.TotalForces)
skl := ""
if q < corBrk { // it's a corporeal skill
skl = util.ChoiceStr(corSkills)
// fmt.Println("Selected Corporeal skill: ", skl)
} else if q < ethBrk { // it's an ethereal skill
skl = util.ChoiceStr(ethSkills)
if skl == "Knowledge" {
subskl := util.ChoiceStr(knowList)
skl = "Knowledge (" + subskl + ")"
} else if skl == "Area Knowledge" {
subskl := util.ChoiceStr(akList)
skl = "Area Knowledge (" + subskl + ")"
} else if skl == "Language" {
subskl := util.ChoiceStr(langList)
skl = "Language (" + subskl + ")"
if rand.Intn(3) == 0 && len(ply.Skills) != 0 {
key, val := util.ChoiceMap(ply.Skills)
ply.Skills[key] = val + 1
} else {
q := rand.Intn(ply.TotalForces)
skl := ""
if q < corBrk { // it's a corporeal skill
skl = util.ChoiceStr(corSkills)
// fmt.Println("Selected Corporeal skill: ", skl)
} else if q < ethBrk { // it's an ethereal skill
skl = util.ChoiceStr(ethSkills)
if skl == "Knowledge" {
subskl := util.ChoiceStr(knowList)
skl = "Knowledge (" + subskl + ")"
} else if skl == "Area Knowledge" {
subskl := util.ChoiceStr(akList)
skl = "Area Knowledge (" + subskl + ")"
} else if skl == "Language" {
subskl := util.ChoiceStr(langList)
skl = "Language (" + subskl + ")"
}
// fmt.Println("Selected Ethereal skill: ", skl)
} else { // it's a celestial skill
skl = util.ChoiceStr(celSkills)
// fmt.Println("Selected Celestial skill: ", skl)
}
// fmt.Println("Selected Ethereal skill: ", skl)
} else { // it's a celestial skill
skl = util.ChoiceStr(celSkills)
// fmt.Println("Selected Celestial skill: ", skl)
ply.Skills[skl] = ply.Skills[skl] + 1
}
ply.Skills[skl] = ply.Skills[skl] + 1
} else { // Songs
skl := util.ChoiceStr(songList)
// fmt.Println("Selected song: ", skl)
ply.Songs[skl] = ply.Songs[skl] + 1
if rand.Intn(3) == 0 && len(ply.Songs) != 0 {
key, val := util.ChoiceMap(ply.Songs)
ply.Songs[key] = val + 1
} else {
skl := util.ChoiceStr(songList)
// fmt.Println("Selected song: ", skl)
ply.Songs[skl] = ply.Songs[skl] + 1
}
}
}

skills := make([]string, 0, len(ply.Skills))
songs := make([]string, 0, len(ply.Songs))
// fmt.Println(len(ply.Skills), len(ply.Songs), ply.Skills, ply.Songs)
for k, v := range ply.Skills {
skills = append(skills, k+"/"+strconv.Itoa(v))
}
for k, v := range ply.Songs {
songs = append(songs, k+"/"+strconv.Itoa(v))
}
sort.Strings(skills)
sort.Strings(songs)
sklout := strings.Join(skills[:], ", ")
sngout := strings.Join(songs[:], ", ")

fmt.Println("=== Generated In Nomine character ===")
fmt.Println(ply.Name)
fmt.Printf("Cor %d\tEth %d\tCel %d\n",
@@ -196,7 +221,7 @@ func main() {
ply.Agility,
ply.Precision,
ply.Perception)
fmt.Println("Skills: ", ply.Skills)
fmt.Println("Songs: ", ply.Songs)
fmt.Println("Skills: ", sklout)
fmt.Println("Songs: ", sngout)
fmt.Println("CP Remaining: ", b)
}

+ 6
- 4
src/util/arrays.go View File

@@ -34,20 +34,22 @@ func ChoiceStr(ary []string) string {
func ChoiceMap(ary map[string]int) (string, int) {
rand.Seed(time.Now().UnixNano())
l := len(ary)
if l == 0 {
return "", 0
}
// fmt.Println(l)
key, val, rot := "", 0, 0
for key == "" {
Debug(rot, key, val)
// Debug(rot, key, val)
for k, v := range ary {
Debug(k, v)
// Debug(k, v)
// Debug(rot)
r := 0
if rot < 3 {
r = rand.Intn(l)
}
if r == 0 {
key, val = k, v
break
return k, v
}
}
rot++

Loading…
Cancel
Save