adding validated services? patching forcad_local.py

This commit is contained in:
Your Name
2026-08-13 08:32:35 +07:00
parent d485f61169
commit e795614e45
1459 changed files with 420036 additions and 436 deletions

View File

@@ -0,0 +1,40 @@
package xy
import (
"fmt"
)
type Point struct {
X int `json:"x"`
Y int `json:"y"`
}
func (p Point) Go(dir Direction) (Point, error) {
switch dir {
case Up:
return Point{X: p.X, Y: p.Y - 1}, nil
case Down:
return Point{X: p.X, Y: p.Y + 1}, nil
case Left:
return Point{X: p.X - 1, Y: p.Y}, nil
case Right:
return Point{X: p.X + 1, Y: p.Y}, nil
}
return p, fmt.Errorf("invalid direction: %s", dir)
}
type Direction string
const (
Up Direction = "up"
Down Direction = "down"
Left Direction = "left"
Right Direction = "right"
)
func (d Direction) Validate() error {
if d == Up || d == Down || d == Left || d == Right {
return nil
}
return fmt.Errorf("invalid direction: %s (out of %v)", d, []Direction{Up, Down, Left, Right})
}