adding validated services? patching forcad_local.py
This commit is contained in:
40
OmCTF-2025/services/block_game/backend/utils/xy/xy.go
Normal file
40
OmCTF-2025/services/block_game/backend/utils/xy/xy.go
Normal 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})
|
||||
}
|
||||
Reference in New Issue
Block a user