33 Commits

Author SHA1 Message Date
18b221d972 Update stats.go 2024-09-27 16:04:17 -07:00
e45c5b3711 Test change
We'll see if this just works.
2024-09-27 15:45:34 -07:00
f53beb4b17 New card, update for crime stats 2023-05-23 11:30:21 -07:00
c30254a36d Crime stats update 2023-05-23 11:30:09 -07:00
350fd0f777 Use Mean to calculate StatChaos. 2023-05-13 20:15:57 -07:00
816b5e8e7a Mathematical mean helper. 2023-05-13 20:13:05 -07:00
e61d7571f0 Chaos Stat 2023-05-13 20:05:07 -07:00
6d6d0f5c8b Squalor mechanic introduction
I haven't connected it to crime yet.
2023-04-19 22:33:24 -07:00
3ca17d8881 Update go.mod 2023-04-19 11:37:48 -07:00
976610b1bb Food supply tweaks, new card 2023-04-19 11:37:40 -07:00
a4692712cc Issue #7, plus DimReturns 2023-04-13 16:06:56 -07:00
2ca8f3ed13 Economy Update,
Adding in diminishing returns.
2023-04-13 16:06:40 -07:00
0a39cc76d6 Two Kobolds In A Trenchcoat: grammar fix 2023-04-08 18:38:51 -07:00
de7092cf4b SwitchingCard.IsValid: control drawability.
Cards can now specify conditions that must be met for them to be drawn into the hand.

Additionally, this improves the documentation of SwitchingCard.
2023-04-08 18:33:58 -07:00
d434e50897 Shuffle cards back by default.
If no After function is provided for a SwitchingCard, it uses ShuffleIntoBottomHalf.

This also modifies Then to be callable with a nil `o`, which it recognizes as "nothing happened but we need cleanup anyway", in preparation for the incoming "make cards sometimes not drawable" feature.
2023-04-08 18:18:00 -07:00
95a30cb522 Foreign Relations, Forestry, and a New Issue
I guess this project will continue growing for now.
2023-04-05 20:26:57 -07:00
f3fd0c582f Expansion of Issue #4
Parks spending will have more features later.
2023-04-05 12:30:00 -07:00
de98cf8fb3 Obesity Stat Implementation
First sigmoid function!
2023-04-05 12:29:23 -07:00
d66e17a279 Partial New Policy Card
It works like this, but it needs more options.
2023-04-05 00:09:37 -07:00
caa5c2e60c New Expense
I missed one from my notes
2023-04-05 00:09:12 -07:00
159508b202 New Issue, Food Supply Feature 2023-04-04 20:23:32 -07:00
301d8ae161 Hide unavailable options on SwitchingCard. 2023-04-04 20:21:12 -07:00
e0dad09045 Refactor, new menu, issue feature update
It's now possible to make issue options enabled or disabled conditional upon having taken other actions with that issue before.
2023-04-04 13:22:43 -07:00
ccd141ddc5 Economic Stats Expansion
I also got rid of the "Sector" and "Gov" parts of the tokens, they were just pointless elongation.
2023-04-04 10:33:14 -07:00
d2f89f5bd4 Issue #2 Option Validity Check
I also fixed the write to-do and changed an improbable mention of Education into a more likely mention of Finance.
2023-04-03 21:20:14 -07:00
f7bed6c4b9 Can't assume CanDo is always there.
BasicPolicy doesn't know how to do fallback, that's driven by the VerbosePolicy. But the VerbosePolicy isn't there if BasicPolicy is trying to use CanDo itself. Just remove the check.
2023-04-03 21:15:43 -07:00
1eedfb50e8 Fix enablement 2023-04-03 20:33:35 -07:00
c2d637b109 Fix out-of-range check. 2023-04-03 20:25:29 -07:00
7313ac0d73 Fully implement Festival of Bureaucracy. 2023-04-03 20:24:01 -07:00
140d7b6cbb DisabledPolicy: a policy that doesn't 2023-04-03 20:12:06 -07:00
5af762474c OverrideDefaultMsg and support in VerbosePolicy
For when you need a partially-functional message but don't want to repeatedly write the same Enact func.
2023-04-03 19:57:09 -07:00
2c1fc73ef5 FuncPolicy: function pointer policy
For when you don't want to go to the trouble of writing a type, but do need actual functions.
2023-04-03 19:52:47 -07:00
a1f55c865d Refactor VerbosePolicy.
This allows it to switch between other complete policies, with fallbacks to a default if parts aren't impelemented. Complementing it is the change to BasicPolicy, which throws ErrUnimplemented if fields are missing, which VerbosePolicy uses as a "go ask the default" sign.
2023-04-03 19:41:32 -07:00
7 changed files with 1934 additions and 175 deletions

9
go.mod
View File

@ -2,4 +2,11 @@ module git.chromaticdragon.app/kistaro/KoboldSim
go 1.20
require git.chromaticdragon.app/kistaro/CardSimEngine v0.1.3
require git.chromaticdragon.app/kistaro/CardSimEngine v0.5.0
require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
)

16
go.sum
View File

@ -1,4 +1,12 @@
git.chromaticdragon.app/kistaro/CardSimEngine v0.1.2 h1:+8KVFhSxXbQO7CPzmL89sJ+qjgU4J42Z5OinGuDMR0U=
git.chromaticdragon.app/kistaro/CardSimEngine v0.1.2/go.mod h1:VFaOagdbtM6gH87ioHent8v76nDh9PddpymMqWdrLfI=
git.chromaticdragon.app/kistaro/CardSimEngine v0.1.3 h1:rNaDDXnPVoMpavpx4vR9k30sl0nO0BnCe32nZbAF2IM=
git.chromaticdragon.app/kistaro/CardSimEngine v0.1.3/go.mod h1:VFaOagdbtM6gH87ioHent8v76nDh9PddpymMqWdrLfI=
git.chromaticdragon.app/kistaro/CardSimEngine v0.5.0 h1:o4ncTVfDgax3w2tVhkap4/ZrZDe13YnNNJ0pe7zaqjM=
git.chromaticdragon.app/kistaro/CardSimEngine v0.5.0/go.mod h1:FYuoJHaK7lDI8Fwf4lZY2Y+8P9zavT4oLvSFUG6drw4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,14 @@ import (
var (
ErrOptionNotEnabled = errors.New("option not enabled")
ErrPolicyNotEnacted = errors.New("cannot unenact policy that is not enacted")
// ErrUnimplemented and ErrKeepMessaage are "non-errors". They are used
// as special signals that the result needs to be handled in a special way;
// VerbosePolicy uses these to decide when to use the Default instead.
// If these are returned in a context that does not know how to respond
// to them, then they're just errors.
ErrUnimplemented = errors.New("unimplemented policy element")
ErrKeepMessage = errors.New("use the default behavior but this message")
)
type Policy interface {
@ -34,12 +42,62 @@ type Policy interface {
// previously, and undoes it before doing a different one. It is always valid
// to draw.
type SwitchingCard struct {
Name cardsim.Message
Desc cardsim.Message
IsUrgent bool
After func(Card, *Player, CardOption) error
Policies []Policy
// Name contains the name of the card, displayed as its title in the
// action selection menu and in the card detail page itself.
Name cardsim.Message
// Desc contains the event description for the card, displayed in the
// card detail page.
Desc cardsim.Message
// IsUrgent marks a card as urgent. If the player has any urgent cards
// in hand, they cannot act on any non-urgent cards (or permanent actions
// not marked as urgent).
IsUrgent bool
// After is invoked after the player has chosen to act on this card and
// the chosen option has been fully enacted. If the card should be returned
// to the deck, After is responsible for doing this!
//
// If After is not provided, ShuffleIntoBottomHalf is used as a fallback.
//
// The first argument to After is the card itself. This will be type
// *SwitchingCard. It's represented as Card so general "After" functions
// that can be used with multiple card types (for example,
// ShuffleIntoBottomHalf) can be trivially implemented.
//
// If the card cannot be drawn into the hand because it has an IsValid
// check and the check fails, After is invoked with a nil CardOption.
// ShuffleIntoBottomHalf works just fine with a nil argument here.
// (It doesn't care about the CardOption at all.)
After func(Card, *Player, CardOption) error
// IsValid is used to check whether the card can be drawn into the hand.
// If it cannot, After is immediately invoked (whenever the card was
// being drawn, which is probably the "draw" stage of the turn but can
// happen any time if something else causes the player to draw cards) with
// a nil CardOption (because no option was selected) and the SwitchingCard
// does not invoke any option and does not change its active policy.
//
// The first argument to IsValid is the card itself. This will be type
// *SwitchingCard. It's presented via the Card interface to support
// general validity functions that could be used with arbitrary kinds of Card.
IsValid func(Card, *Player) bool
// Policies contains the options the player may choose between. Policy is
// a more specific type than CardOption; a Policy can be un-enacted.
// Unenactment of the previous policy before selecting a new one is the
// core feature of SwitchingCard.
Policies []Policy
// lastPolicy stores the last policy selected for this card. It's used
// extensively by SwitchingCard's logic.
lastPolicy Policy
// ShowUnavailable controls whether options for which Enabled() = false
// should be presented to the player at all. Indexes for "last enacted"
// still refer to the original list, not the shortened one.
ShowUnavailable bool
}
// Title implements Card.
@ -53,7 +111,12 @@ func (s *SwitchingCard) Urgent(*Player) bool {
}
// Drawn implements Card.
func (s *SwitchingCard) Drawn(*Player) bool {
func (s *SwitchingCard) Drawn(p *Player) bool {
if s.IsValid != nil && !s.IsValid(s, p) {
err := s.Then(p, nil)
p.ReportError(err) // can't do anything with the error right now
return false
}
return true
}
@ -63,7 +126,7 @@ func (s *SwitchingCard) EventText(*Player) (cardsim.Message, error) {
}
// Options implements Card.
func (s *SwitchingCard) Options(*Player) ([]CardOption, error) {
func (s *SwitchingCard) Options(player *Player) ([]CardOption, error) {
lastIdx := -1
for i, p := range s.Policies {
if p.Is(s.lastPolicy) {
@ -71,96 +134,123 @@ func (s *SwitchingCard) Options(*Player) ([]CardOption, error) {
break
}
}
ret := make([]CardOption, len(s.Policies))
for i, p := range s.Policies {
ret := make([]CardOption, 0, len(s.Policies))
for _, p := range s.Policies {
p.LastEnacted(lastIdx, s.lastPolicy)
ret[i] = p
if s.ShowUnavailable || p.Enabled(player) {
ret = append(ret, p)
}
}
return ret, nil
}
// Then implements Card.
func (s *SwitchingCard) Then(p *Player, o CardOption) error {
newPolicy := o.(Policy)
var errs cardsim.ErrorCollector
if s.lastPolicy != nil && !newPolicy.Is(s.lastPolicy) {
err := s.lastPolicy.Unenact(p)
if cardsim.IsSeriousError(err) {
return err
if o != nil {
newPolicy := o.(Policy)
if s.lastPolicy != nil && !newPolicy.Is(s.lastPolicy) {
err := s.lastPolicy.Unenact(p)
if cardsim.IsSeriousError(err) {
return err
}
errs.Add(err)
}
errs.Add(err)
s.lastPolicy = o.(Policy)
}
s.lastPolicy = o.(Policy)
if s.After != nil {
errs.Add(s.After(s, p, o))
} else {
// Fallback: Shuffle the card back into the bottom half of the deck.
errs.Add(ShuffleIntoBottomHalf(s, p, o))
}
return errs.Emit()
}
// CurrentlyEnacted returns the currently enacted Policy, if any.
func (s *SwitchingCard) CurrentlyEnacted() Policy {
return s.lastPolicy
}
// BasicPolicy is a straightfoward implementation of Policy. If the currently
// enacted option is re-enacted, it refunds the player's action point.
type BasicPolicy struct {
Desc cardsim.Message
UnenactedDesc cardsim.Message
EnactedDesc cardsim.Message
NothingChanged cardsim.Message
Do func(*Player) (cardsim.Message, error)
Undo func(*Player) error
CanDo func(*Player) bool
CanDo func(*BasicPolicy, *Player) bool
currentlyEnacted bool
CurrentlyEnacted bool
LastEnactedPolicy Policy
LastEnactedIdx int
}
// YesWeCan returns true. It's the default value for BasicPolicy.CanDo / BasicPolicy.CanUndo.
func YesWeCan(*Player) bool {
func YesWeCan(*BasicPolicy, *Player) bool {
return true
}
// LastEnacted notifies b about the last-enacted policy in its group. It updates
// b.currentlyEnacted accordingly.
func (b *BasicPolicy) LastEnacted(_ int, p Policy) {
b.currentlyEnacted = b.Is(p)
func (b *BasicPolicy) LastEnacted(i int, p Policy) {
b.LastEnactedPolicy = p
b.LastEnactedIdx = i
b.CurrentlyEnacted = b.Is(p)
}
// OptionText implements CardOption.
func (b *BasicPolicy) OptionText(*Player) (cardsim.Message, error) {
if b.currentlyEnacted {
if b.CurrentlyEnacted {
if b.EnactedDesc == nil {
return nil, ErrUnimplemented
}
return b.EnactedDesc, nil
}
if b.UnenactedDesc == nil {
return nil, ErrUnimplemented
}
return b.UnenactedDesc, nil
}
// Enact implements CardOption.
func (b *BasicPolicy) Enact(p *Player) (cardsim.Message, error) {
if b.currentlyEnacted {
if b.Do == nil {
return nil, ErrUnimplemented
}
if b.CurrentlyEnacted {
p.ActionsRemaining++
if b.NothingChanged == nil {
b.NothingChanged = cardsim.MsgStr("You continue your current approach.")
}
return b.NothingChanged, nil
}
if b.CanDo != nil && !b.CanDo(p) {
return nil, ErrOptionNotEnabled
}
return b.Do(p)
}
// Unenact implements Policy.
func (b *BasicPolicy) Unenact(p *Player) error {
if !b.currentlyEnacted {
if !b.CurrentlyEnacted {
return ErrPolicyNotEnacted
}
if b.Undo == nil {
return ErrUnimplemented
}
return b.Undo(p)
}
// Enabled implements CardOption.
func (b *BasicPolicy) Enabled(p *Player) bool {
if b.currentlyEnacted {
if b.CurrentlyEnacted {
return true
}
if b.CanDo == nil {
b.CanDo = YesWeCan
panic(ErrUnimplemented)
}
return b.CanDo(p)
return b.CanDo(b, p)
}
func (b *BasicPolicy) Is(p Policy) bool {
@ -170,52 +260,254 @@ func (b *BasicPolicy) Is(p Policy) bool {
return false
}
// A DescResuilt is descriptive text for an option and the text result of
// enacting that option when it was described this way.
type DescResult struct {
Desc cardsim.Message
Result cardsim.Message
}
// A VerbosePolicy is an extension to a BasicPolicy. It emits the BasicPolicy's
// `UnenactedDesc` and the message returned from Do only when no policy has ever
// been enacted for this card; otherwise, it looks up the description and result
// from a slice using the index of the last policy selected.
// A VerbosePolicy is a group of related policies pretending to all be the same
// policy. Which policy is used is determined by what the previous policy for
// the card was (as reported via a call to LastEnacted):
//
// - If no policy has yet been enacted, use FirstTime.
// - If a policy has been enacted, use the Policy at the slot in Variants
// that corresponds to the slot (on the Card) of the currently-enacted policy.
// - If the policy retrieved in this way returns ErrUnimplemented, throw away
// its response and use Default instead. For Enabled, which does not have
// an error component to its return value, look for ErrUnimplemented as the
// argument to a Panic call, instead.
// - If the policy retrieved in this way returns ErrKeepMessage when Enact
// is called, it calls Default for the side effects but ignores its message,
// retaining the message from the original call. This is to avoid having to
// repeat the same Enact function except with different text each time.
// OptionText does this too, even though OptionText doesn't have side effects,
// so the same helper function can create a "constant message" callback
// that works the same for both fields so someone implementing a card won't
// accidentally fail to enact their policy's effects by using the wrong one
// in the wrong slot.
type VerbosePolicy struct {
*BasicPolicy
lastIdx int
Content []DescResult
Default Policy
FirstTime Policy
lastIdx int
lastWasMe bool
lastEnacted Policy
Variants []Policy
}
func (v *VerbosePolicy) LastEnacted(i int, p Policy) {
v.lastIdx = i
v.BasicPolicy.currentlyEnacted = v.Is(p)
}
v.lastEnacted = p
v.lastWasMe = v.Is(p)
func (v *VerbosePolicy) OptionText(*Player) (cardsim.Message, error) {
if v.lastIdx < 0 {
return v.BasicPolicy.UnenactedDesc, nil
// make sure we can just assume that there is a policy in this slot,
// inserting the default if there is none.
v.fillDefaults()
// Tell the potential candidate policy about this, too. Two special cases:
// * first time -- use first-time policy
// * lastWasMe -- tell the polcy that the last encated policy was itself,
// since it doesn't know it's wrapped in another policy and would not
// recognize itself as v
if i < 0 {
v.FirstTime.LastEnacted(i, p) // p should be nil here...
} else if v.lastWasMe {
v.Variants[i].LastEnacted(i, v.Variants[i])
} else {
v.Variants[i].LastEnacted(i, p)
}
// In case we need it, also prepare the Default for use.
if v.lastWasMe {
v.Default.LastEnacted(i, v.Default)
} else {
v.Default.LastEnacted(i, p)
}
return v.Content[v.lastIdx].Desc, nil
}
func (v *VerbosePolicy) Enact(p *Player) (cardsim.Message, error) {
msg, err := v.BasicPolicy.Enact(p)
if v.lastIdx >= 0 {
msg = v.Content[v.lastIdx].Result
func (v *VerbosePolicy) fillDefaults() {
if v.FirstTime == nil {
v.FirstTime = v.Default
}
for len(v.Variants) <= v.lastIdx {
v.Variants = append(v.Variants, v.Default)
}
if v.lastIdx >= 0 && v.Variants[v.lastIdx] == nil {
v.Variants[v.lastIdx] = v.Default
}
}
func (v *VerbosePolicy) OptionText(p *Player) (cardsim.Message, error) {
var msg cardsim.Message
var err error
if v.lastIdx < 0 {
msg, err = v.FirstTime.OptionText(p)
} else {
msg, err = v.Variants[v.lastIdx].OptionText(p)
}
if errors.Is(err, ErrKeepMessage) {
_, err = v.Default.OptionText(p)
} else if errors.Is(err, ErrUnimplemented) {
msg, err = v.Default.OptionText(p)
}
return msg, err
}
func (v *VerbosePolicy) Enact(p *Player) (cardsim.Message, error) {
var msg cardsim.Message
var err error
if v.lastIdx < 0 {
msg, err = v.FirstTime.Enact(p)
} else {
msg, err = v.Variants[v.lastIdx].Enact(p)
}
if errors.Is(err, ErrKeepMessage) {
_, err = v.Default.Enact(p)
} else if errors.Is(err, ErrUnimplemented) {
msg, err = v.Default.Enact(p)
}
return msg, err
}
func (v *VerbosePolicy) Unenact(p *Player) error {
if !v.lastWasMe {
return ErrPolicyNotEnacted
}
var err error
if v.lastIdx < 0 {
err = v.FirstTime.Unenact(p)
} else {
err = v.Variants[v.lastIdx].Unenact(p)
}
if errors.Is(err, ErrUnimplemented) {
err = v.Default.Unenact(p)
}
return err
}
func (v *VerbosePolicy) Is(p Policy) bool {
if o, ok := p.(*VerbosePolicy); ok {
return o == p
return o == v
}
return false
}
func (v *VerbosePolicy) Enabled(p *Player) (result bool) {
// oops, enablement isn't designed to error out. so we have to use
// panic/recover for this.
defer func() {
if x := recover(); x != nil {
if e, ok := x.(error); ok {
if errors.Is(e, ErrUnimplemented) {
// Recover and use the Default to cover for the missing
// Enabled method.
result = v.Default.Enabled(p)
return
}
}
// Whatever we caught, it's not something we're actually ready to recover from.
panic(x)
}
}()
if v.lastIdx < 0 {
result = v.FirstTime.Enabled(p)
return
}
result = v.Variants[v.lastIdx].Enabled(p)
return
}
// FuncPolicy implements Policy by calling specified functions. If they're
// missing, it returns ErrUnimplemented. It handles Is itself. It also tracks
// LastEnacted data (last index, which policy, is policy self) itself.
type FuncPolicy struct {
OptionTextFunc func(*Player) (cardsim.Message, error)
EnactFunc func(*Player) (cardsim.Message, error)
EnabledFunc func(*Player) bool
UnenactFunc func(*Player) error
// These three fields are assigned by LastEnacted and typically should not
// be set in the initializer.
LastEnactedIdx int
LastEnactedPolicy Policy
WasEnactedLast bool
}
func (f *FuncPolicy) OptionText(p *Player) (cardsim.Message, error) {
if f.OptionTextFunc == nil {
return nil, ErrUnimplemented
}
return f.OptionTextFunc(p)
}
func (f *FuncPolicy) Enact(p *Player) (cardsim.Message, error) {
if f.EnactFunc == nil {
return nil, ErrUnimplemented
}
return f.EnactFunc(p)
}
func (f *FuncPolicy) Enabled(p *Player) bool {
if f.EnabledFunc == nil {
panic(ErrUnimplemented)
}
return f.EnabledFunc(p)
}
func (f *FuncPolicy) Unenact(p *Player) error {
if f.UnenactFunc == nil {
return ErrUnimplemented
}
return f.UnenactFunc(p)
}
func (f *FuncPolicy) LastEnacted(i int, p Policy) {
f.LastEnactedIdx = i
f.LastEnactedPolicy = p
f.WasEnactedLast = f.Is(p)
}
func (f *FuncPolicy) Is(p Policy) bool {
fp, ok := p.(*FuncPolicy)
return ok && (f == fp)
}
// A DisabledPolicy is never enabled.
type DisabledPolicy struct {
Msg cardsim.Message
}
func (d *DisabledPolicy) OptionText(p *Player) (cardsim.Message, error) {
return d.Msg, nil
}
func (d *DisabledPolicy) Enact(*Player) (cardsim.Message, error) {
return nil, ErrOptionNotEnabled
}
func (d *DisabledPolicy) Enabled(*Player) bool {
return false
}
func (d *DisabledPolicy) Unenact(*Player) error {
return ErrPolicyNotEnacted
}
func (d *DisabledPolicy) LastEnacted(int, Policy) {}
func (d *DisabledPolicy) Is(p Policy) bool {
dp, ok := p.(*DisabledPolicy)
return ok && (dp == d)
}
// ShuffleIntoBottomHalf is a common "what to do with the card after?" behavior.
func ShuffleIntoBottomHalf(c Card, p *Player, _ CardOption) error {
p.Deck.InsertRandomBottom(0.5, c)
return nil
}
// OverrideDefaultMsg returns a closure that returns the provided message and
// ErrKeepMessage. This can be used in a FuncPolicy to tell a VerbosePolicy
// to use its Default but keep the message written here, to avoid writing
// repetitive Enact funcs (and, for that matter, OptionText funcs, even though
// the underlying Default call should be unnecessary).
func OverrideMsg(m cardsim.Message) func(*Player) (cardsim.Message, error) {
return func(p *Player) (cardsim.Message, error) {
return m, ErrKeepMessage
}
}

View File

@ -1,6 +1,10 @@
package koboldsim
import "git.chromaticdragon.app/kistaro/CardSimEngine/cardsim"
import (
"strings"
"git.chromaticdragon.app/kistaro/CardSimEngine/cardsim"
)
func InitPlayer() *Player {
p := cardsim.InitPlayer(NewKoboldMine())
@ -13,6 +17,16 @@ func InitPlayer() *Player {
Name: cardsim.MsgStr("All Stats"),
Intro: cardsim.MsgStr("All available statistics."),
},
&cardsim.BasicStatsPanel[*KoboldMine]{
Name: cardsim.MsgStr("Per Capita Economic"),
Intro: cardsim.MsgStr("Yield and Investment per Capita"),
Filter: cardsim.All(
cardsim.VisibleOrDebug[*KoboldMine],
func(p *Player, s cardsim.Stat) bool {
return strings.Contains(s.StatName(), "Productivity") || strings.Contains(s.StatName(), "Investment")
},
),
},
}
p.Prompt = &cardsim.BasicStatsPanel[*KoboldMine]{
Name: cardsim.MsgStr("The Kobold Mine"),
@ -21,6 +35,7 @@ func InitPlayer() *Player {
"Kobolds",
"Total Sector Income",
"Total Government Expense",
"Tax Rate",
),
}
p.State = cardsim.GameActive

View File

@ -1,52 +1,410 @@
package koboldsim
import (
"math"
"git.chromaticdragon.app/kistaro/CardSimEngine/cardsim"
)
// KoboldMine is the state of a kobold mine.
type KoboldMine struct {
Kobolds cardsim.Stored[int64]
BasePopulation float64 `cardsim:"stathidden"`
SectorMiningIncome cardsim.Stored[float64]
SectorScavengingIncome cardsim.Stored[float64]
MiningIncome float64 `cardsim:"stathidden" cardsim_name:"Mining Productivity"`
ScavengingIncome float64 `cardsim:"stathidden" cardsim_name:"Scavenging Productivity"`
AlchemyIncome float64 `cardsim:"stathidden" cardsim_name:"Alchemy Productivity"`
HospitalityIncome float64 `cardsim:"stathidden" cardsim_name:"Hospitality Productivity"`
AgricultureIncome float64 `cardsim:"stathidden" cardsim_name:"Agriculture Productivity"`
ManufacturingIncome float64 `cardsim:"stathidden" cardsim_name:"Manufacturing Productivity"`
PlanarIncome float64 `cardsim:"stathidden" cardsim_name:"Planar Productivity"`
PublishingIncome float64 `cardsim:"stathidden" cardsim_name:"Publishing Productivity"`
ForestryIncome float64 `cardsim:"stathidden" cardsim_name:"Forestry Productivity"`
FinanceIncome float64 `cardsim:"stathidden" cardsim_name:"Finance Productivity"`
GadgetryIncome float64 `cardsim:"stathidden" cardsim_name:"Gadgetry Productivity"`
FishingIncome float64 `cardsim:"stathidden" cardsim_name:"Fishing Productivity"`
ConstructionIncome float64 `cardsim:"stathidden" cardsim_name:"Construction Productivity"`
GovBureaucracyExpense cardsim.Stored[float64]
GovWarExpense cardsim.Stored[float64]
PropagandaExpense float64 `cardsim:"stathidden" cardsim_name:"Propaganda Investment"`
BureaucracyExpense float64 `cardsim:"stathidden" cardsim_name:"Bureaucracy Investment"`
WarExpense float64 `cardsim:"stathidden" cardsim_name:"War Investment"`
QoLExpense float64 `cardsim:"stathidden" cardsim_name:"QoL Investment"`
LogisticsExpense float64 `cardsim:"stathidden" cardsim_name:"Logistics Investment"`
DragonSubsExpense float64 `cardsim:"stathidden" cardsim_name:"Dragon Subsidies Investment"`
ResearchSubsExpense float64 `cardsim:"stathidden" cardsim_name:"Research Subsidies Investment"`
EducationExpense float64 `cardsim:"stathidden" cardsim_name:"Education Investment"`
HealthcareExpense float64 `cardsim:"stathidden" cardsim_name:"Healthcare Investment"`
ForeignRelExpense float64 `cardsim:"stathidden" cardsim_name:"Foreign Relations Investment"`
PoliceExpense float64 `cardsim:"stathidden" cardsim_name:"Law Enforcement Investment"`
EconPlanExpense float64 `cardsim:"stathidden" cardsim_name:"Economic Planning Investment"`
ParksExpense float64 `cardsim:"stathidden" cardsim_name:"Parks and Aesthetics Investment"`
FaithExpense float64 `cardsim:"stathidden" cardsim_name:"Faith Investment"`
FoodSupply float64 `cardsim:"stathidden"`
ObesogenicFood float64 `cardsim:"stathidden"`
ForeignRelations float64 `cardsim:"stathidden"`
HiddenRelPenalty float64 `cardsim:"stathidden"` // Lower is better.
Secrecy float64 `cardsim:"stathidden"`
PointOfDimReturns float64 `cardsim:"stathidden"`
Rebellion float64 `cardsim:"stathidden"`
Madness float64 `cardsim:"stathidden"`
Cruelty float64 `cardsim:"stat"`
Greed float64 `cardsim:"stat"`
Gullibility float64 `cardsim:"stathidden"`
Authoritarianism float64 `cardsim:"stat"`
// AnotherExpense float64 `cardsim:"hiddenround5"`
// A different way of adding stats that is slightly more empowering.
}
func (k *KoboldMine) ProductivityFunc(s *cardsim.Stored[float64]) func() float64 {
func (k *KoboldMine) ProductivityFunc(s float64) func() float64 {
return func() float64 {
return s.Value * float64(k.Kobolds.Value)
return math.Max(s*float64(k.Kobolds()), 0)
}
}
func (k *KoboldMine) ProductivityTotal() float64 {
total := math.Max(k.MiningIncome, 0.01)
total += math.Max(k.ScavengingIncome, 0)
total += math.Max(k.AlchemyIncome, 0)
total += math.Max(k.HospitalityIncome, 0)
total += math.Max(k.AgricultureIncome, 0)
total += math.Max(k.ManufacturingIncome, 0)
total += math.Max(k.PlanarIncome, 0)
total += math.Max(k.PublishingIncome, 0)
total += math.Max(k.FinanceIncome, 0)
total += math.Max(k.GadgetryIncome, 0)
total += math.Max(k.FishingIncome, 0)
total += math.Max(k.ConstructionIncome, 0.02)
total += math.Max(k.PropagandaExpense, 0)
total += math.Max(k.BureaucracyExpense, 0)
total += math.Max(k.WarExpense, 0)
total += math.Max(k.QoLExpense, 0)
total += math.Max(k.LogisticsExpense, 0)
total += math.Max(k.DragonSubsExpense, 0)
total += math.Max(k.ResearchSubsExpense, 0)
total += math.Max(k.EducationExpense, 0)
total += math.Max(k.HealthcareExpense, 0)
total += math.Max(k.ForeignRelExpense, 0)
total += math.Max(k.PoliceExpense, 0)
total += math.Max(k.EconPlanExpense, 0)
total += math.Max(k.ParksExpense, 0)
total += math.Max(k.FaithExpense, 0)
return total
}
func (k *KoboldMine) ProductivityMultiplier() float64 {
return math.Pow(0.95, math.Max(0, k.ProductivityTotal()-k.PointOfDimReturns))
}
func (k *KoboldMine) TrueMiningIncome() float64 {
return math.Max(k.MiningIncome*k.ProductivityMultiplier(), 0.01)
}
func (k *KoboldMine) TrueScavengingIncome() float64 {
return math.Max(k.ScavengingIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueAlchemyIncome() float64 {
return math.Max(k.AlchemyIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueHospitalityIncome() float64 {
return math.Max(k.HospitalityIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueAgricultureIncome() float64 {
return math.Max(k.AgricultureIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueManufacturingIncome() float64 {
return math.Max(k.ManufacturingIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TruePlanarIncome() float64 {
return math.Max(k.PlanarIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TruePublishingIncome() float64 {
return math.Max(k.PublishingIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueForestryIncome() float64 {
return math.Max(k.ForestryIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueFinanceIncome() float64 {
return math.Max(k.FinanceIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueGadgetryIncome() float64 {
return math.Max(k.GadgetryIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueFishingIncome() float64 {
return math.Max(k.FishingIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueConstructionIncome() float64 {
return math.Max(k.ConstructionIncome*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TruePropagandaExpense() float64 {
return math.Max(k.PropagandaExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueBureaucracyExpense() float64 {
return math.Max(k.BureaucracyExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueWarExpense() float64 {
return math.Max(k.WarExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueQoLExpense() float64 {
return math.Max(k.QoLExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueLogisticsExpense() float64 {
return math.Max(k.LogisticsExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueDragonSubsExpense() float64 {
return math.Max(k.DragonSubsExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueResearchSubsExpense() float64 {
return math.Max(k.ResearchSubsExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueEducationExpense() float64 {
return math.Max(k.EducationExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueHealthcareExpense() float64 {
return math.Max(k.HealthcareExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueForeignRelExpense() float64 {
return math.Max(k.ForeignRelExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TruePoliceExpense() float64 {
return math.Max(k.PoliceExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueEconPlanExpense() float64 {
return math.Max(k.EconPlanExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueParksExpense() float64 {
return math.Max(k.ParksExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TrueFaithExpense() float64 {
return math.Max(k.FaithExpense*k.ProductivityMultiplier(), 0)
}
func (k *KoboldMine) TotalSectorIncome() float64 {
return float64(k.Kobolds.Value) * (k.SectorMiningIncome.Value + k.SectorScavengingIncome.Value)
return float64(k.Kobolds()) * (math.Max(k.TrueMiningIncome(), 0.01) + math.Max(k.TrueScavengingIncome(), 0) + math.Max(k.TrueAlchemyIncome(), 0) + math.Max(k.TrueHospitalityIncome(), 0) + math.Max(k.TrueAgricultureIncome(), 0) + math.Max(k.TrueManufacturingIncome(), 0) + math.Max(k.TruePlanarIncome(), 0) + math.Max(k.TruePublishingIncome(), 0) + math.Max(k.TrueFinanceIncome(), 0) + math.Max(k.TrueGadgetryIncome(), 0) + math.Max(k.TrueFishingIncome(), 0) + math.Max(k.TrueConstructionIncome(), 0.02))
}
func (k *KoboldMine) TotalGovExpense() float64 {
return float64(k.Kobolds.Value) * (k.GovBureaucracyExpense.Value + k.GovWarExpense.Value)
return float64(k.Kobolds()) * (math.Max(k.TruePropagandaExpense(), 0) + math.Max(k.TrueBureaucracyExpense(), 0) + math.Max(k.TrueWarExpense(), 0) + math.Max(k.TrueQoLExpense(), 0) + math.Max(k.TrueLogisticsExpense(), 0) + math.Max(k.TrueDragonSubsExpense(), 0) + math.Max(k.TrueResearchSubsExpense(), 0) + math.Max(k.TrueEducationExpense(), 0) + math.Max(k.TrueHealthcareExpense(), 0) + math.Max(k.TrueForeignRelExpense(), 0) + math.Max(k.TruePoliceExpense(), 0) + math.Max(k.TrueEconPlanExpense(), 0) + math.Max(k.TrueParksExpense(), 0) + math.Max(k.TrueFaithExpense(), 0))
}
func (k *KoboldMine) Taxation() float64 {
return (k.TotalGovExpense() / (k.TotalSectorIncome() + k.TotalGovExpense())) * 100
}
// Idea for the tax rate. I could have a tracked "tax evasion" stat that drives up taxation (people who actually pay have to pay more) as well as a tracked "public pay ratio" stat that drives up taxation if the public sector is paid more than the private sector and vice versa if the public sector is paid less. Both stats should be exposed to the player.
// Idea for tax evasion. The corruption stat should increase tax evasion, while the squalor stat should reduce it. The link with corruption should be obvious, but for squalor: when the economy improves, more people have resources with which to attempt to protect their income.
func (k *KoboldMine) StatTaxRate() float64 {
return k.Taxation()
}
func (k *KoboldMine) Kobolds() int64 {
return int64((k.BasePopulation + (k.HealthcareExpense * 1000)) * k.FoodSupply * (1 - 0.5*(k.StatObesity()/100)) * (1 + k.TrueForeignRelations()))
}
func (k *KoboldMine) DisplayedFoodSupply() float64 {
return (k.FoodSupply - 1) * 100
}
func (k *KoboldMine) StatObesogenicity() float64 {
return (k.ObesogenicFood - 1) * 100
}
func (k *KoboldMine) StatObesity() float64 {
return (100 / (2.3 + math.Exp(-0.04*(k.DisplayedFoodSupply()-37)))) + 100/(2.3+math.Exp(-0.04*(k.StatObesogenicity()-37)))
}
func (k *KoboldMine) TrueForeignRelations() float64 {
return (1 - math.Max(math.Min(k.Secrecy, 1), 0)) * (math.Max(math.Min(k.ForeignRelations, 1), -1) - k.HiddenRelPenalty)
}
func (k *KoboldMine) DisplayedForeignRelations() float64 {
return math.Max(math.Min((k.ForeignRelations*100), 100), -100)
}
func (k *KoboldMine) DisplayedSecrecy() float64 {
return k.Secrecy * 100
}
func (k *KoboldMine) SqualorReduction() float64 {
total := math.Max(k.MiningIncome, 0.01)
total -= math.Max(k.ScavengingIncome, 0)
total += math.Max(k.AlchemyIncome, 0)
total += math.Max(k.HospitalityIncome, 0) * 2
total += math.Max(k.ManufacturingIncome, 0)
total += math.Max(k.PlanarIncome, 0)
total += math.Max(k.PublishingIncome, 0) * 2
total += math.Max(k.FinanceIncome, 0) * 3
total += math.Max(k.GadgetryIncome, 0) * 2
total += math.Max(k.ConstructionIncome, 0.02) * 2
total += math.Max(k.PropagandaExpense, 0)
total += math.Max(k.BureaucracyExpense, 0) * 2
total += math.Max(k.QoLExpense, 0) * 20
total += math.Max(k.LogisticsExpense, 0)
total += math.Max(k.ResearchSubsExpense, 0) * 2
total += math.Max(k.EducationExpense, 0) * 4
total += math.Max(k.HealthcareExpense, 0) * 6
total += math.Max(k.ForeignRelExpense, 0)
total += math.Max(k.PoliceExpense, 0)
total += math.Max(k.EconPlanExpense, 0)
total += math.Max(k.ParksExpense, 0) * 3
total += math.Max(k.FaithExpense, 0) * 10
return total
}
func (k *KoboldMine) StatSqualor() float64 {
return 100 * math.Pow(1.204, 1.2-(2*k.SqualorReduction()))
}
// So I want squalor to be a value between 100 and 0 that reduces readily at the start and then becomes increasingly difficult to further reduce. This initial squalor stat starts at about 80%, but may not change rapidly enough. Note that the 1.2-(2* sequence is meant to balance it at 80% starting point. If I change the velocity on the 2* side, I have to change the 1.2 offset as well. I really hope this math works, because I don't quite understand it.
func (k *KoboldMine) StatChaos() float64 {
return Mean(k.Rebellion, k.Madness, k.Cruelty)
}
// This is the "crimes of chaos" stat for my crime calculations. It will also be displayed to the player as just Chaos. The player can see Cruelty, but not Madness or Rebellion. I'm concerned some players may think, "Oh, chaos is a good thing, I want more of that as long as it's not cruel!" In that case, they'll have mad, rebellious colonies that commit crimes against those perceived to be cruel...
func (k *KoboldMine) StatCorruption() float64 {
return Mean(k.Greed, k.Gullibility, k.Authoritarianism)
}
// This is the "crimes of cunning" stat for my crime calculations. It will also be displayed to the player as just Corruption. The player can also see Greed and Authoritarianism, so they should have a good idea what goes into Corruption, but they'll have to infer the importance of Gullibility.
func (k *KoboldMine) Stats() []cardsim.Stat {
stats := cardsim.ExtractStats(k)
funcs := []cardsim.Stat{
cardsim.StatFunc(
"Total Sector Mining Income",
k.ProductivityFunc(&k.SectorMiningIncome),
"Mining Income",
k.ProductivityFunc(k.TrueMiningIncome()),
),
cardsim.StatFunc(
"Total Sector Scavenging Income",
k.ProductivityFunc(&k.SectorScavengingIncome),
"Scavenging Income",
k.ProductivityFunc(k.TrueScavengingIncome()),
),
cardsim.StatFunc(
"Total Government Bureaucracy Expense",
k.ProductivityFunc(&k.GovBureaucracyExpense),
"Alchemy Income",
k.ProductivityFunc(k.TrueAlchemyIncome()),
),
cardsim.StatFunc(
"Total Government War Expense",
k.ProductivityFunc(&k.GovWarExpense),
"Hospitality Income",
k.ProductivityFunc(k.TrueHospitalityIncome()),
),
cardsim.StatFunc(
"Agriculture Income",
k.ProductivityFunc(k.TrueAgricultureIncome()),
),
cardsim.StatFunc(
"Manufacturing Income",
k.ProductivityFunc(k.TrueManufacturingIncome()),
),
cardsim.StatFunc(
"Planar Harvesting Income",
k.ProductivityFunc(k.TruePlanarIncome()),
),
cardsim.StatFunc(
"Book Publishing Income",
k.ProductivityFunc(k.TruePublishingIncome()),
),
cardsim.StatFunc(
"Forestry Income",
k.ProductivityFunc(k.TrueForestryIncome()),
),
cardsim.StatFunc(
"Finance Income",
k.ProductivityFunc(k.TrueFinanceIncome()),
),
cardsim.StatFunc(
"Gadgetry Income",
k.ProductivityFunc(k.TrueGadgetryIncome()),
),
cardsim.StatFunc(
"Fishing Income",
k.ProductivityFunc(k.TrueFishingIncome()),
),
cardsim.StatFunc(
"Construction Income",
k.ProductivityFunc(k.TrueConstructionIncome()),
),
cardsim.StatFunc(
"Propaganda Expense",
k.ProductivityFunc(k.TruePropagandaExpense()),
),
cardsim.StatFunc(
"Bureaucracy Expense",
k.ProductivityFunc(k.TrueBureaucracyExpense()),
),
cardsim.StatFunc(
"War Expense",
k.ProductivityFunc(k.TrueWarExpense()),
),
cardsim.StatFunc(
"QoL Expense",
k.ProductivityFunc(k.TrueQoLExpense()),
),
cardsim.StatFunc(
"Logistics Expense",
k.ProductivityFunc(k.TrueLogisticsExpense()),
),
cardsim.StatFunc(
"Dragon Subsidies",
k.ProductivityFunc(k.TrueDragonSubsExpense()),
),
cardsim.StatFunc(
"Research Subsidies",
k.ProductivityFunc(k.TrueResearchSubsExpense()),
),
cardsim.StatFunc(
"Education Expense",
k.ProductivityFunc(k.TrueEducationExpense()),
),
cardsim.StatFunc(
"Healthcare Expense",
k.ProductivityFunc(k.TrueHealthcareExpense()),
),
cardsim.StatFunc(
"Foreign Relations Expense",
k.ProductivityFunc(k.TrueForeignRelExpense()),
),
cardsim.StatFunc(
"Law Enforcement Expense",
k.ProductivityFunc(k.TruePoliceExpense()),
),
cardsim.StatFunc(
"Economic Planning Expense",
k.ProductivityFunc(k.TrueEconPlanExpense()),
),
cardsim.StatFunc(
"Parks and Aesthetics Expense",
k.ProductivityFunc(k.TrueParksExpense()),
),
cardsim.StatFunc(
"Faith Expense",
k.ProductivityFunc(k.TrueFaithExpense()),
),
cardsim.StatFunc(
"Total Sector Income",
@ -56,33 +414,78 @@ func (k *KoboldMine) Stats() []cardsim.Stat {
"Total Government Expense",
k.TotalGovExpense,
),
cardsim.StatFunc(
"Foreign Relations",
k.DisplayedForeignRelations,
),
cardsim.StatFunc(
"Secrecy",
k.DisplayedSecrecy,
),
cardsim.StatFunc(
"Food Supply",
k.DisplayedFoodSupply,
),
cardsim.StatFunc(
"Kobolds",
k.Kobolds,
),
cardsim.InvisibleStatFunc(
"Squalor Reduction",
k.SqualorReduction,
),
cardsim.StatFunc(
"Squalor",
k.StatSqualor,
),
}
stats = append(stats, funcs...)
cardsim.SortStats(stats)
// cardsim.SortStats(stats)
return stats
}
func NewKoboldMine() *KoboldMine {
return &KoboldMine{
Kobolds: cardsim.Stored[int64]{
Name: "Kobolds",
Value: 1000,
},
SectorMiningIncome: cardsim.Stored[float64]{
Name: "Sector Mining Income",
Value: 0.15,
},
SectorScavengingIncome: cardsim.Stored[float64]{
Name: "Sector Scavenging Income",
Value: 0.1,
},
GovBureaucracyExpense: cardsim.Stored[float64]{
Name: "Government Bureaucracy Expense",
Value: 0.05,
},
GovWarExpense: cardsim.Stored[float64]{
Name: "Government War Expense",
Value: 0.1,
},
BasePopulation: 1025,
MiningIncome: 0.15,
ScavengingIncome: 0.1,
AlchemyIncome: 0.01,
HospitalityIncome: 0.0,
AgricultureIncome: 0.0,
ManufacturingIncome: 0.10,
PlanarIncome: 0.00,
PublishingIncome: 0.02,
ForestryIncome: 0.0,
FinanceIncome: 0.02,
GadgetryIncome: 0.03,
FishingIncome: 0.0,
ConstructionIncome: 0.05,
PropagandaExpense: 0.01,
BureaucracyExpense: 0.05,
WarExpense: 0.1,
QoLExpense: 0.01,
LogisticsExpense: 0.02,
DragonSubsExpense: 0.0,
ResearchSubsExpense: 0.0,
EducationExpense: 0.01,
HealthcareExpense: 0.01,
ForeignRelExpense: 0.0,
PoliceExpense: 0.03,
EconPlanExpense: 0.02,
ParksExpense: 0.0,
FaithExpense: 0.03,
FoodSupply: 0.20,
ForeignRelations: -0.40,
HiddenRelPenalty: -0.01,
Rebellion: 0.10,
Madness: 0.25,
Cruelty: 0.45,
Greed: 0.35,
Gullibility: 0.10,
Authoritarianism: 0.70,
Secrecy: .95,
PointOfDimReturns: 1.0,
}
}
// Note that the mine initializes with 1.02 points of overall productivity.

22
koboldsim/util.go Normal file
View File

@ -0,0 +1,22 @@
package koboldsim
import "math"
// Generic helper functions not directly attached to Card Sim Engine mechanics.
// Mean calculates the mathematical mean of its arguments (the sum, divided
// by the number of elements). If it is called with no arguments, it returns
// NaN ("not a number"). If there are contradictory infinities among the
// arguments, it also returns NaN. Overflowing or underflowing can create an
// infinity.
func Mean(vals ...float64) float64 {
if len(vals) == 0 {
return math.NaN()
}
total := 0.0
for _, x := range vals {
total += x
}
return total / float64(len(vals))
}