当前位置: 首页>>代码示例>>Golang>>正文


Golang Ruleset.AddRule方法代码示例

本文整理汇总了Golang中github.com/ryanfaerman/fsm.Ruleset.AddRule方法的典型用法代码示例。如果您正苦于以下问题:Golang Ruleset.AddRule方法的具体用法?Golang Ruleset.AddRule怎么用?Golang Ruleset.AddRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ryanfaerman/fsm.Ruleset的用法示例。


在下文中一共展示了Ruleset.AddRule方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getLocationRules

func getLocationRules() fsm.Ruleset {
	rules := fsm.Ruleset{}
	rules.AddTransition(fsm.T{"town", "forest"})
	rules.AddTransition(fsm.T{"forest", "battle"})
	rules.AddRule(fsm.T{"town", "forest"}, func(subject fsm.Stater, goal fsm.State) bool {
		println("You must have enough energy to go to forest.")
		return true
	})

	return rules
}
开发者ID:tony,项目名称:gorpg,代码行数:11,代码来源:ocation.go

示例2: NewWindowRules

func NewWindowRules() fsm.Ruleset {
	rules := fsm.Ruleset{}
	rules.AddTransition(fsm.T{"title", "character selection"})
	rules.AddTransition(fsm.T{"character selection", "game"})
	rules.AddTransition(fsm.T{"character selection", "create character"})
	rules.AddRule(fsm.T{"title", "character selection"}, func(subject fsm.Stater, goal fsm.State) bool {
		return true
	})

	return rules
}
开发者ID:tony,项目名称:gorpg,代码行数:11,代码来源:window.go

示例3: NewBattleRules

func NewBattleRules() fsm.Ruleset {
	rules := fsm.Ruleset{}
	rules.AddTransition(fsm.T{"wait", "attack"})
	rules.AddTransition(fsm.T{"wait", "run"})
	rules.AddTransition(fsm.T{"wait", "use item"})
	rules.AddTransition(fsm.T{"wait", "end"})
	rules.AddRule(fsm.T{"wait", "attack"}, func(subject fsm.Stater, goal fsm.State) bool {
		return true
	})

	return rules
}
开发者ID:tony,项目名称:gorpg,代码行数:12,代码来源:attle.go

示例4: TestRulesetParallelGuarding

func TestRulesetParallelGuarding(t *testing.T) {
	rules := fsm.Ruleset{}
	rules.AddTransition(fsm.T{"pending", "started"})
	rules.AddTransition(fsm.T{"started", "finished"})

	// Add two failing rules, the slow should be caught first
	rules.AddRule(fsm.T{"started", "finished"}, func(subject fsm.Stater, goal fsm.State) bool {
		time.Sleep(1 * time.Second)
		t.Error("Slow rule should have been short-circuited")
		return false
	})

	rules.AddRule(fsm.T{"started", "finished"}, func(subject fsm.Stater, goal fsm.State) bool {
		return false
	})

	st.Expect(t, rules.Permitted(&Thing{State: "started"}, "finished"), false)
}
开发者ID:hongbinz,项目名称:fsm,代码行数:18,代码来源:fsm_test.go

示例5: BenchmarkRulesetParallelGuarding

func BenchmarkRulesetParallelGuarding(b *testing.B) {
	rules := fsm.Ruleset{}
	rules.AddTransition(fsm.T{"pending", "started"})
	rules.AddTransition(fsm.T{"started", "finished"})

	// Add two failing rules, one very slow and the other terribly fast
	rules.AddRule(fsm.T{"started", "finished"}, func(subject fsm.Stater, goal fsm.State) bool {
		time.Sleep(1 * time.Second)
		return false
	})

	rules.AddRule(fsm.T{"started", "finished"}, func(subject fsm.Stater, goal fsm.State) bool {
		return false
	})

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		rules.Permitted(&Thing{State: "started"}, "finished")
	}
}
开发者ID:hongbinz,项目名称:fsm,代码行数:21,代码来源:fsm_test.go

示例6: BenchmarkRulesetRuleForbids

func BenchmarkRulesetRuleForbids(b *testing.B) {
	// Here, we explicity create a transition that is forbidden. This simulates an
	// otherwise valid transition that would be denied based on a user role or the like.
	// It should be slower than a standard invalid transition, since we have to
	// actually execute a function to perform the check. The first guard to
	// fail (returning false) will short circuit the execution, getting some some speed.

	rules := fsm.Ruleset{}
	rules.AddTransition(fsm.T{"pending", "started"})

	rules.AddRule(fsm.T{"started", "finished"}, func(subject fsm.Stater, goal fsm.State) bool {
		return false
	})

	some_thing := &Thing{State: "started"}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		rules.Permitted(some_thing, "finished")
	}
}
开发者ID:hongbinz,项目名称:fsm,代码行数:22,代码来源:fsm_test.go


注:本文中的github.com/ryanfaerman/fsm.Ruleset.AddRule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。