本文整理汇总了Golang中github.com/zond/godip/common.Validator类的典型用法代码示例。如果您正苦于以下问题:Golang Validator类的具体用法?Golang Validator怎么用?Golang Validator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Validator类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: validateRetreatPhase
func (self *move) validateRetreatPhase(v dip.Validator) error {
if !v.Graph().Has(self.targets[0]) {
return cla.ErrInvalidSource
}
if !v.Graph().Has(self.targets[1]) {
return cla.ErrInvalidDestination
}
if self.targets[0] == self.targets[1] {
return cla.ErrIllegalMove
}
var unit dip.Unit
var ok bool
if unit, self.targets[0], ok = v.Dislodged(self.targets[0]); !ok {
return cla.ErrMissingUnit
}
var err error
if self.targets[1], err = cla.AnyMovePossible(v, unit.Type, self.targets[0], self.targets[1], unit.Type == cla.Army, false, false); err != nil {
return cla.ErrIllegalMove
}
if _, _, ok := v.Unit(self.targets[1]); ok {
return cla.ErrIllegalRetreat
}
if v.Bounce(self.targets[0], self.targets[1]) {
return cla.ErrIllegalRetreat
}
return nil
}
开发者ID:arlm,项目名称:godip,代码行数:27,代码来源:move.go
示例2: Validate
func (self *disband) Validate(v dip.Validator) error {
if v.Phase().Type() == cla.Adjustment {
return self.validateBuildPhase(v)
} else if v.Phase().Type() == cla.Retreat {
return self.validateRetreatPhase(v)
}
return cla.ErrInvalidPhase
}
开发者ID:arlm,项目名称:godip,代码行数:8,代码来源:disband.go
示例3: Validate
func (self *move) Validate(v dip.Validator) error {
if v.Phase().Type() == cla.Movement {
return self.validateMovementPhase(v)
} else if v.Phase().Type() == cla.Retreat {
return self.validateRetreatPhase(v)
}
return cla.ErrInvalidPhase
}
开发者ID:arlm,项目名称:godip,代码行数:8,代码来源:move.go
示例4: validateRetreatPhase
func (self *disband) validateRetreatPhase(v dip.Validator) error {
if !v.Graph().Has(self.targets[0]) {
return cla.ErrInvalidTarget
}
var ok bool
if _, self.targets[0], ok = v.Dislodged(self.targets[0]); !ok {
return cla.ErrMissingUnit
}
return nil
}
开发者ID:arlm,项目名称:godip,代码行数:10,代码来源:disband.go
示例5: validateBuildPhase
func (self *disband) validateBuildPhase(v dip.Validator) error {
if !v.Graph().Has(self.targets[0]) {
return cla.ErrInvalidTarget
}
var unit dip.Unit
var ok bool
if unit, self.targets[0], ok = v.Unit(self.targets[0]); !ok {
return cla.ErrMissingUnit
}
if _, _, balance := cla.AdjustmentStatus(v, unit.Nation); balance > -1 {
return cla.ErrMissingDeficit
}
return nil
}
开发者ID:arlm,项目名称:godip,代码行数:14,代码来源:disband.go
示例6: Winner
func (self *phase) Winner(s dip.Validator) *dip.Nation {
sizes := map[dip.Nation]int{}
for _, nat := range s.SupplyCenters() {
sizes[nat]++
}
var biggest *dip.Nation
var bigSize int
for nat, size := range sizes {
if biggest == nil || size > bigSize {
natCpy := nat
biggest = &natCpy
bigSize = size
}
}
if bigSize > 17 {
return biggest
}
return nil
}
开发者ID:arlm,项目名称:godip,代码行数:19,代码来源:phase.go
示例7: Validate
func (self *hold) Validate(v dip.Validator) error {
if v.Phase().Type() != cla.Movement {
return cla.ErrInvalidPhase
}
if !v.Graph().Has(self.targets[0]) {
return cla.ErrInvalidTarget
}
var ok bool
if _, self.targets[0], ok = v.Unit(self.targets[0]); !ok {
return cla.ErrMissingUnit
}
return nil
}
开发者ID:arlm,项目名称:godip,代码行数:13,代码来源:hold.go
示例8: Options
func (self *hold) Options(v dip.Validator, nation dip.Nation, src dip.Province) (result dip.Options) {
if v.Phase().Type() == cla.Movement {
if v.Graph().Has(src) {
if unit, actualSrc, ok := v.Unit(src); ok {
if unit.Nation == nation {
result = dip.Options{
dip.SrcProvince(actualSrc): nil,
}
}
}
}
}
return
}
开发者ID:arlm,项目名称:godip,代码行数:14,代码来源:hold.go
示例9: Options
func (self *move) Options(v dip.Validator, nation dip.Nation, src dip.Province) (result dip.Options) {
if v.Phase().Type() == cla.Retreat {
if !self.flags[cla.ViaConvoy] {
if v.Graph().Has(src) {
if unit, actualSrc, ok := v.Dislodged(src); ok {
if unit.Nation == nation {
for _, dst := range cla.PossibleMoves(v, src, false, true) {
if _, _, foundUnit := v.Unit(dst); !foundUnit {
if !v.Bounce(src, dst) {
if result == nil {
result = dip.Options{}
}
if result[dip.SrcProvince(actualSrc)] == nil {
result[dip.SrcProvince(actualSrc)] = dip.Options{}
}
result[dip.SrcProvince(actualSrc)][dst] = nil
}
}
}
}
}
}
}
} else if v.Phase().Type() == cla.Movement {
if v.Graph().Has(src) {
if unit, actualSrc, ok := v.Unit(src); ok {
if unit.Nation == nation {
if !self.flags[cla.ViaConvoy] || unit.Type == cla.Army {
for _, dst := range cla.PossibleMoves(v, src, true, false) {
if !self.flags[cla.ViaConvoy] {
if result == nil {
result = dip.Options{}
}
if result[dip.SrcProvince(actualSrc)] == nil {
result[dip.SrcProvince(actualSrc)] = dip.Options{}
}
result[dip.SrcProvince(actualSrc)][dst] = nil
} else {
if cp := cla.AnyConvoyPath(v, src, dst, false, nil); len(cp) > 1 {
if result == nil {
result = dip.Options{}
}
if result[dip.SrcProvince(actualSrc)] == nil {
result[dip.SrcProvince(actualSrc)] = dip.Options{}
}
result[dip.SrcProvince(actualSrc)][dst] = nil
}
}
}
}
}
}
}
}
return
}
开发者ID:arlm,项目名称:godip,代码行数:56,代码来源:move.go
示例10: Options
func (self *disband) Options(v dip.Validator, nation dip.Nation, src dip.Province) (result dip.Options) {
if v.Phase().Type() == cla.Adjustment {
if v.Graph().Has(src) {
if unit, actualSrc, ok := v.Unit(src); ok {
if unit.Nation == nation {
if _, _, balance := cla.AdjustmentStatus(v, unit.Nation); balance < 0 {
result = dip.Options{
dip.SrcProvince(actualSrc): nil,
}
}
}
}
}
} else if v.Phase().Type() == cla.Retreat {
if v.Graph().Has(src) {
if unit, actualSrc, ok := v.Dislodged(src); ok {
if unit.Nation == nation {
result = dip.Options{
dip.SrcProvince(actualSrc): nil,
}
}
}
}
}
return
}
开发者ID:arlm,项目名称:godip,代码行数:26,代码来源:disband.go
示例11: Options
func (self *phase) Options(s dip.Validator, nation dip.Nation) (result dip.Options) {
return s.Options(orders.Orders(), nation)
}
开发者ID:arlm,项目名称:godip,代码行数:3,代码来源:phase.go
注:本文中的github.com/zond/godip/common.Validator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论