rules

package
v0.0.0-...-e4b2dea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IncrementRule1Id    = 1 << iota
	IncrementRule2Id    = 1 << iota
	IncrementRule3Id    = 1 << iota
	IncrementRule7Id    = 1 << iota
	TakeTurnsRuleId     = 1 << iota
	GuessNormallyRuleId = 1 << iota
	NoValidateRuleId    = 1 << iota
	FibonacciRuleId     = 1 << iota
	RomanNumeralRuleId  = 1 << iota
	JeopardyRuleId      = 1 << iota
)
View Source
const (
	PreValidateType = "PreValidate"
	CountType       = "Count"
	ValidateType    = "Validate"
)

Variables

View Source
var (
	IncrementOne   = createIncrementRule(1, IncrementRule1Id, 30)
	IncrementTwo   = createIncrementRule(2, IncrementRule2Id, 30)
	IncrementThree = createIncrementRule(3, IncrementRule3Id, 20)
	IncrementSeven = createIncrementRule(7, IncrementRule7Id, 20)
)
View Source
var (
	AllRules         = []Rule{}
	PreValidateRules = []Rule{}
	CountRules       = []Rule{}
	ValidateRules    = []Rule{}
)
View Source
var (
	Fibonacci = (func() ValidateRule {
		fr := FibonacciRule{
			id:       FibonacciRuleId,
			weight:   20,
			ruleType: CountType,
		}

		registerRule(fr)

		return fr
	})()
)
View Source
var (
	GuessNormally = (func() Rule {
		gnr := GuessNormallyRule{
			id:       GuessNormallyRuleId,
			weight:   100,
			ruleType: PreValidateType,
		}

		registerRule(gnr)

		return gnr
	})()
)
View Source
var (
	Jeopardy = (func() Rule {
		jr := JeopardyRule{
			id:       JeopardyRuleId,
			weight:   10,
			ruleType: PreValidateType,
		}

		registerRule(jr)

		return jr
	})()
)
View Source
var (
	NoValidate = (func() ValidateRule {
		nvr := NoValidateRule{
			id:       NoValidateRuleId,
			weight:   30,
			ruleType: ValidateType,
		}

		registerRule(nvr)

		return nvr
	})()
)
View Source
var (
	RomanNumeral = (func() Rule {
		rnr := RomanNumeralRule{
			id:       RomanNumeralRuleId,
			weight:   15,
			ruleType: PreValidateType,
		}

		registerRule(rnr)

		return rnr
	})()
)
View Source
var (
	TakeTurns = (func() Rule {
		ttr := TakeTurnsRule{
			id:       TakeTurnsRuleId,
			weight:   100,
			ruleType: ValidateType,
		}

		registerRule(ttr)

		return ttr
	})()
)

Functions

func GetRuleTextsForGame

func GetRuleTextsForGame(g database.Turn) []string

Types

type FibonacciRule

type FibonacciRule struct {
	// contains filtered or unexported fields
}

func (FibonacciRule) Description

func (fr FibonacciRule) Description() string

func (FibonacciRule) Id

func (fr FibonacciRule) Id() int

func (FibonacciRule) Name

func (fr FibonacciRule) Name() string

func (FibonacciRule) OnNewGame

func (fr FibonacciRule) OnNewGame(db *gorm.DB, s *discordgo.Session, ng database.Turn, channelID string)

func (FibonacciRule) Type

func (fr FibonacciRule) Type() string

func (FibonacciRule) Validate

func (fr FibonacciRule) Validate(db *gorm.DB, lastTurn database.Turn, msg discordgo.Message, guess int) bool

func (FibonacciRule) Weight

func (fr FibonacciRule) Weight() int

type GuessNormallyRule

type GuessNormallyRule struct {
	// contains filtered or unexported fields
}

func (GuessNormallyRule) Description

func (gnr GuessNormallyRule) Description() string

func (GuessNormallyRule) Id

func (gnr GuessNormallyRule) Id() int

func (GuessNormallyRule) Name

func (gnr GuessNormallyRule) Name() string

func (GuessNormallyRule) OnNewGame

func (gnr GuessNormallyRule) OnNewGame(_ *gorm.DB, _ *discordgo.Session, _ database.Turn, _ string)

func (GuessNormallyRule) PreValidate

func (gnr GuessNormallyRule) PreValidate(db *gorm.DB, dg *discordgo.Session, msg discordgo.Message) (int, error)

func (GuessNormallyRule) Type

func (gnr GuessNormallyRule) Type() string

func (GuessNormallyRule) Weight

func (gnr GuessNormallyRule) Weight() int

type IncrementRule

type IncrementRule struct {
	// contains filtered or unexported fields
}

func (IncrementRule) Description

func (ir IncrementRule) Description() string

func (IncrementRule) Id

func (ir IncrementRule) Id() int

func (IncrementRule) Name

func (ir IncrementRule) Name() string

func (IncrementRule) OnNewGame

func (ir IncrementRule) OnNewGame(_ *gorm.DB, _ *discordgo.Session, _ database.Turn, _ string)

func (IncrementRule) Type

func (ir IncrementRule) Type() string

func (IncrementRule) Validate

func (ir IncrementRule) Validate(db *gorm.DB, lastTurn database.Turn, msg discordgo.Message, guess int) bool

func (IncrementRule) Weight

func (ir IncrementRule) Weight() int

type JeopardyRule

type JeopardyRule struct {
	// contains filtered or unexported fields
}

func (JeopardyRule) Description

func (jr JeopardyRule) Description() string

func (JeopardyRule) Id

func (jr JeopardyRule) Id() int

func (JeopardyRule) Name

func (jr JeopardyRule) Name() string

func (JeopardyRule) OnNewGame

func (jr JeopardyRule) OnNewGame(_ *gorm.DB, _ *discordgo.Session, _ database.Turn, _ string)

func (JeopardyRule) PreValidate

func (jr JeopardyRule) PreValidate(db *gorm.DB, dg *discordgo.Session, msg discordgo.Message) (int, error)

func (JeopardyRule) Type

func (jr JeopardyRule) Type() string

func (JeopardyRule) Weight

func (jr JeopardyRule) Weight() int

type NoValidateRule

type NoValidateRule struct {
	// contains filtered or unexported fields
}

func (NoValidateRule) Description

func (nvr NoValidateRule) Description() string

func (NoValidateRule) Id

func (nvr NoValidateRule) Id() int

func (NoValidateRule) Name

func (nvr NoValidateRule) Name() string

func (NoValidateRule) OnNewGame

func (nvr NoValidateRule) OnNewGame(_ *gorm.DB, _ *discordgo.Session, _ database.Turn, _ string)

func (NoValidateRule) Type

func (nvr NoValidateRule) Type() string

func (NoValidateRule) Validate

func (nvr NoValidateRule) Validate(_ *gorm.DB, lastTurn database.Turn, _ discordgo.Message, _ int) bool

func (NoValidateRule) Weight

func (nvr NoValidateRule) Weight() int

type PreValidateRule

type PreValidateRule interface {
	Rule
	// PreValidate returns the guess as an int and an error if the guess is invalid
	PreValidate(db *gorm.DB, dg *discordgo.Session, msg discordgo.Message) (int, error)
}

The purpose of a prevalidate rule is to take the message and extract the guess from it, and return the guess as an int

func GetRandomPreValidateRule

func GetRandomPreValidateRule() PreValidateRule

type RomanNumeralRule

type RomanNumeralRule struct {
	// contains filtered or unexported fields
}

func (RomanNumeralRule) Description

func (rnr RomanNumeralRule) Description() string

func (RomanNumeralRule) Id

func (rnr RomanNumeralRule) Id() int

func (RomanNumeralRule) Name

func (rnr RomanNumeralRule) Name() string

func (RomanNumeralRule) OnNewGame

func (rnr RomanNumeralRule) OnNewGame(_ *gorm.DB, _ *discordgo.Session, _ database.Turn, _ string)

func (RomanNumeralRule) PreValidate

func (rnr RomanNumeralRule) PreValidate(db *gorm.DB, dg *discordgo.Session, msg discordgo.Message) (int, error)

func (RomanNumeralRule) Type

func (rnr RomanNumeralRule) Type() string

func (RomanNumeralRule) Weight

func (rnr RomanNumeralRule) Weight() int

type Rule

type Rule interface {
	Id() int
	Name() string
	Weight() int
	Description() string
	Type() string

	// OnNewGame is called once when a new game is started
	OnNewGame(db *gorm.DB, dg *discordgo.Session, ng database.Turn, channelID string)
}

func GetAllRulesForTurn

func GetAllRulesForTurn(g database.Turn) []Rule

type RulesForTurn

type RulesForTurn struct {
	PreValidateRules []PreValidateRule
	ValidateRules    []ValidateRule
}

func GetRulesForTurn

func GetRulesForTurn(g database.Turn) RulesForTurn

type TakeTurnsRule

type TakeTurnsRule struct {
	// contains filtered or unexported fields
}

func (TakeTurnsRule) Description

func (ttr TakeTurnsRule) Description() string

func (TakeTurnsRule) Id

func (ttr TakeTurnsRule) Id() int

func (TakeTurnsRule) Name

func (ttr TakeTurnsRule) Name() string

func (TakeTurnsRule) OnNewGame

func (ttr TakeTurnsRule) OnNewGame(_ *gorm.DB, _ *discordgo.Session, _ database.Turn, _ string)

func (TakeTurnsRule) Type

func (ttr TakeTurnsRule) Type() string

func (TakeTurnsRule) Validate

func (ttr TakeTurnsRule) Validate(db *gorm.DB, lastTurn database.Turn, msg discordgo.Message, guess int) bool

func (TakeTurnsRule) Weight

func (ttr TakeTurnsRule) Weight() int

type ValidateRule

type ValidateRule interface {
	Rule
	// Validate returns true if the guess is correct
	Validate(db *gorm.DB, lt database.Turn, msg discordgo.Message, guess int) bool
}

The purpose of a validate rule is to take the guess and validate that it meets the rule criteria, returning a bool

func GetRandomCountRule

func GetRandomCountRule() ValidateRule

func GetRandomValidateRule

func GetRandomValidateRule() ValidateRule

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL