packages feed

SoccerFun 0.1.2 → 0.2.1

raw patch · 3 files changed

+51/−67 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- SoccerFun.Prelude: avg :: (Fractional a) => [a] -> a
- SoccerFun.Prelude: boundedBy :: (Ord a) => a -> (a, a) -> a
- SoccerFun.Prelude: break' :: (a -> Bool) -> [a] -> ([a], [a], [a])
- SoccerFun.Prelude: break1 :: (a -> Bool) -> [a] -> ([a], a, [a])
- SoccerFun.Prelude: isbetween :: (Ord a) => a -> a -> a -> Bool
- SoccerFun.Prelude: iterateStn :: Int -> (s -> (a, s)) -> s -> ([a], s)
- SoccerFun.Prelude: minmax :: (Ord a) => (a, a) -> (a, a)
- SoccerFun.Prelude: one :: (Num a) => a
- SoccerFun.Prelude: perhaps :: (a -> Bool) -> (Maybe a) -> Bool
- SoccerFun.Prelude: removeMember :: (Eq a) => a -> [a] -> [a]
- SoccerFun.Prelude: removeMembers :: (Eq a) => [a] -> [a] -> [a]
- SoccerFun.Prelude: singleOutElems :: [a] -> [(a, [a])]
- SoccerFun.Prelude: spanfilter :: (a -> Bool) -> [a] -> ([a], [a])
- SoccerFun.Prelude: spanfilterSt :: (a -> s -> (Bool, s)) -> [a] -> s -> (([a], [a]), s)
- SoccerFun.Prelude: type AssocList k v = [(k, v)]
- SoccerFun.Prelude: unbreak :: ([a], [a], [a]) -> [a]
- SoccerFun.Prelude: unbreak1 :: ([a], a, [a]) -> [a]
- SoccerFun.Prelude: zero :: (Num a) => a
- SoccerFun.Random: makeRandomRealistic :: (Floating f) => f -> f
- SoccerFun.Random: makeRandomRealisticSkilled :: (Floating f) => f -> f
+ SoccerFun.Geometry: instance FromPosition (Float, Float)
+ SoccerFun.Geometry: instance FromPosition Position3D
+ SoccerFun.Geometry: instance FromPosition3D (Float, Float, Float)
+ SoccerFun.Geometry: instance FromPosition3D Position
+ SoccerFun.Geometry: instance FromSpeed Speed3D
+ SoccerFun.Geometry: instance FromSpeed3D Speed
+ SoccerFun.Geometry: instance ToPosition (Float, Float)
+ SoccerFun.Geometry: instance ToPosition Position3D
+ SoccerFun.Geometry: instance ToPosition3D (Float, Float, Float)
+ SoccerFun.Geometry: instance ToSpeed Speed3D
- SoccerFun.Geometry: coordinates :: Position3D -> (Metre, Metre, Metre)
+ SoccerFun.Geometry: coordinates :: Position3D -> (XPos, YPos, ZPos)

Files

SoccerFun.cabal view
@@ -1,5 +1,5 @@ Name:           SoccerFun-Version:        0.1.2+Version:        0.2.1 Copyright:      (c) 2010, Jan Rochel License:        BSD3 License-File:   LICENSE@@ -14,7 +14,7 @@ 	From the website: Soccer-Fun is an educational project to stimulate functional programming by thinking about, designing, implementing, running, and competing with the brains of football players! It is open for participation by everybody who likes to contribute. It is not restricted to a particular functional programming language. Category:       Game, Education, AI Cabal-Version:  >= 1.6-Extensions:     UnicodeSyntax, NamedFieldPuns, Rank2Types, ExistentialQuantification+Extensions:     UnicodeSyntax, NamedFieldPuns, Rank2Types, ExistentialQuantification, FlexibleInstances Data-Files:	template/Makefile template/*.hs Build-Depends: 	base >= 4 && < 4.3,@@ -25,11 +25,9 @@ 	mtl >= 1.1 && < 1.2 Exposed-Modules: 	SoccerFun.UI.GL-	SoccerFun.Prelude 	SoccerFun.Ball 	SoccerFun.Types 	SoccerFun.Team-	SoccerFun.Random 	SoccerFun.Geometry 	SoccerFun.Field 	SoccerFun.Player@@ -38,3 +36,5 @@ 	SoccerFun.MatchControl 	SoccerFun.Referee 	SoccerFun.Referee.Ivanov+	SoccerFun.Random+	SoccerFun.Prelude
SoccerFun/Ball.hs view
@@ -40,7 +40,7 @@  ------------------------------------------------------------------------------ -radiusBall		∷ Float -- officially it should be 0.113m, but that turns out to be too small for rendering+radiusBall		∷ Float -- ^ officially it should be 0.113m, but that turns out to be too small for rendering radiusBall		= 0.4  surfaceResistance	∷ Float -- ^ maximum speed of ball when moving over surface
SoccerFun/Geometry.hs view
@@ -1,10 +1,11 @@-{-# LANGUAGE UnicodeSyntax, MultiParamTypeClasses #-}+{-# LANGUAGE UnicodeSyntax, MultiParamTypeClasses, FlexibleInstances #-} module SoccerFun.Geometry where  import Prelude.Unicode import SoccerFun.Prelude import Data.List (sort) + type Metre = Float type Length = Metre type XPos = Metre@@ -18,9 +19,13 @@  data Position3D = Position3D {pxy ∷ Position, pz ∷ ZPos} deriving (Show,Eq) -coordinates ∷ Position3D → (Metre,Metre,Metre)+coordinates ∷ Position3D → (XPos,YPos,ZPos) coordinates pos = (px $ pxy pos, py $ pxy pos, pz pos) +type XRadius = Metre+type YRadius = Metre+type ZRadius = Metre+ -- position3D is within the cube around #param5 with measures of #param2t/m4 inRadiusOfPosition ∷ Position3D → XRadius → YRadius → ZRadius → Position → Bool inRadiusOfPosition pos1 xr yr zr pos2 = let@@ -28,10 +33,6 @@ 		Position x2 y2 = pos2 	in x2+xr >= x1 && x1 >= x2-xr && y2+yr >= y1 && y1 >= y2-yr && z1 <= zr -type XRadius = Metre-type YRadius = Metre-type ZRadius = Metre- type Angle = Radian -- ^ angle in radians, clockwise type Radian = Float @@ -55,9 +56,9 @@ movePoint3D ∷ RVector3D → Position3D → Position3D movePoint3D (RVector3D dxy dz) (Position3D pxy pz) = Position3D (movePoint dxy pxy) (pz+dz) --- | @pointToRectangle (a,b) c@ returns c if (pointInRectangle (a,b) c) and the--- | projected point c' of c that is exactly on the closest edge of rectangle--- | (a,b).+-- | @pointToRectangle (a,b) c@ returns @c@ if @pointInRectangle (a,b) c@ and the+-- | projected point @c'@ of @c@ that is exactly on the closest edge of rectangle+-- | @(a,b)@. pointToRectangle ∷ (Position,Position) → Position → Position pointToRectangle (a,b) c 	| pointInRectangle (a,b) c = c@@ -81,8 +82,8 @@ 	   | otherwise = error ("unsuspected error; please rotate with angles between pi and -pi\n")  -- | @pointInRectangle (a,b) c@--- | returns True iff point c is inside the rectangle determined by--- | the diagonal corner points a and b.+-- | returns @True@ iff point @c@ is inside the rectangle determined by+-- | the diagonal corner points @a@ and @b@. pointInRectangle ∷ (Position,Position) → Position → Bool pointInRectangle (a,b) c = minX ≤ px c ∧ px c ≤ maxX ∧ minY ≤ py c ∧ py c ≤ maxY where 	(minX,maxX) = minmax ((px a),(px b))@@ -93,21 +94,22 @@ 	= dist pxy pos <= r && pz <= zr  data RVector = RVector-	{dx ∷ Metre, -- ^difference in x-coordinate (|dx| <= 1.0)-	 dy ∷ Metre -- ^difference in y-coordinate (|dy| <= 1.0)+	{dx ∷ Metre, -- ^ difference in x-coordinate @|dx| <= 1.0@+	 dy ∷ Metre  -- ^ difference in y-coordinate @|dy| <= 1.0@ 	} deriving (Show,Eq)  data RVector3D = RVector3D {dxy ∷ RVector, dz ∷ Metre} deriving (Show,Eq)  -- | speed of an object data Speed = Speed-	{direction ∷ Angle, -- ^ direction of object-	 velocity ∷ Velocity -- ^ velocity of object+	{direction ∷ Angle,   -- ^ direction of object+	 velocity  ∷ Velocity -- ^ velocity of object 	} deriving (Show,Eq)+ -- | speed of an object in space data Speed3D = Speed3D-	{vxy ∷ Speed, -- ^ surface speed of object-	 vz ∷ Velocity -- ^ velocity in z-axis (positive: goes up; negative: goes down; zero: horizontally)+	{vxy ∷ Speed,   -- ^ surface speed of object+	 vz  ∷ Velocity -- ^ velocity in z-axis (positive: goes up; negative: goes down; 0: horizontally) 	} deriving (Show,Eq)  type Velocity = Float -- ^ velocity in metre/second@@ -117,15 +119,13 @@ class ToSpeed3D a where toSpeed3D ∷ a → Speed3D class FromSpeed3D a where fromSpeed3D ∷ Speed3D → a -instance ToSpeed3D Speed where toSpeed3D s = Speed3D {vxy = s, vz = zero}- instance Num RVector3D where 	p1 + p2 = RVector3D {dxy = dxy p1 + dxy p2, dz = dz p1 + dz p2} 	p1 * p2 = RVector3D {dxy = dxy p1 * dxy p2, dz = dz p1 * dz p2} 	p1 - p2 = RVector3D {dxy = dxy p1 - dxy p2, dz = dz p1 - dz p2} 	abs p = RVector3D {dxy = abs $ dxy p, dz = abs $ dz p} 	signum p = RVector3D {dxy = signum $ dxy p, dz = signum $ dz p}-	fromInteger i = RVector3D {dxy = fromInteger i, dz = zero}+	fromInteger i = RVector3D {dxy = fromInteger i, dz = 0}  instance Num Speed3D where 	p1 + p2 = Speed3D {vxy = vxy p1 + vxy p2, vz = vz p1 + vz p2}@@ -133,7 +133,7 @@ 	p1 - p2 = Speed3D {vxy = vxy p1 - vxy p2, vz = vz p1 - vz p2} 	abs p = Speed3D {vxy = abs $ vxy p, vz = abs $ vz p} 	signum p = Speed3D {vxy = signum $ vxy p, vz = signum $ vz p}-	fromInteger i = Speed3D {vxy = fromInteger i, vz = zero}+	fromInteger i = Speed3D {vxy = fromInteger i, vz = 0}  instance Num Position3D where 	p1 + p2 = Position3D {pxy = pxy p1 + pxy p2, pz = pz p1 + pz p2}@@ -141,7 +141,7 @@ 	p1 - p2 = Position3D {pxy = pxy p1 - pxy p2, pz = pz p1 - pz p2} 	abs p = Position3D {pxy = abs $ pxy p, pz = abs $ pz p} 	signum p = Position3D {pxy = signum $ pxy p, pz = signum $ pz p}-	fromInteger i = Position3D {pxy = fromInteger i, pz = zero}+	fromInteger i = Position3D {pxy = fromInteger i, pz = 0}  instance Num RVector where 	p1 + p2 = RVector {dx = dx p1 + dx p2, dy = dy p1 + dy p2}@@ -149,7 +149,7 @@ 	p1 - p2 = RVector {dx = dx p1 - dx p2, dy = dy p1 - dy p2} 	abs p = RVector {dx = abs $ dx p, dy = abs $ dy p} 	signum p = RVector {dx = signum $ dx p, dy = signum $ dy p}-	fromInteger i = RVector {dx = fromInteger i, dy = zero}+	fromInteger i = RVector {dx = fromInteger i, dy = 0}  instance Num Position where 	p1 + p2 = Position {px = px p1 + px p2, py = py p1 + py p2}@@ -157,7 +157,7 @@ 	p1 - p2 = Position {px = px p1 - px p2, py = py p1 - py p2} 	abs p = Position {px = abs $ px p, py = abs $ py p} 	signum p = Position {px = signum $ px p, py = signum $ py p}-	fromInteger i = Position {px = fromInteger i, py = zero}+	fromInteger i = Position {px = fromInteger i, py = 0}  instance Num Speed where 	p1 + p2 = Speed {direction = direction p1 + direction p2, velocity = velocity p1 + velocity p2}@@ -165,7 +165,7 @@ 	p1 - p2 = Speed {direction = direction p1 - direction p2, velocity = velocity p1 - velocity p2} 	abs p = Speed {direction = abs $ direction p, velocity = abs $ velocity p} 	signum p = Speed {direction = signum $ direction p, velocity = signum $ velocity p}-	fromInteger i = Speed {direction = fromInteger i, velocity = zero}+	fromInteger i = Speed {direction = fromInteger i, velocity = 0}  class ToRVector a where toRVector ∷ a → RVector @@ -205,7 +205,6 @@  -- | interpret Float as angle in radians instance ToRVector Float where toRVector angle = RVector {dx=cos angle,dy=sin angle}- instance ToRVector Position where toRVector p = RVector {dx=(px p),dy=(py p)}  -- | @sizeVector {dx,dy} = sqrt (dx**2 + dy**2)@@@ -217,44 +216,29 @@ sizeVector3D (RVector3D dxy dz) = sqrt ((dx dxy)**2.0 + (dy dxy)**2.0 + dz**2.0)  class Dist a b where dist ∷ a → b → Float-instance Dist Float Float where-	dist a b = abs (a-b)-instance Dist Position Position where-	dist a b = sqrt ((abs ((px a)-(px b)))**2.0 + (abs ((py a)-(py b)))**2.0)-instance Dist Position3D Position3D where-	dist a b = sqrt ((abs (px (pxy a)-px(pxy b)))**2.0 + (abs (py (pxy a)-py (pxy b)))**2.0 + (abs ((pz a)-(pz b)))**2.0)-instance Dist Position Position3D where-	dist a b = dist (Position3D a zero) b-instance Dist Position3D Position where-	dist a b = dist a (Position3D b zero)+instance Dist Float Float where dist a b = abs (a-b)+instance Dist Position Position where dist a b = sqrt $ (abs $ px a - px b)**2.0 + (abs $ py a - py b)**2.0+instance Dist Position3D Position3D where dist a b = sqrt ((abs (px (pxy a)-px(pxy b)))**2.0 + (abs (py (pxy a)-py (pxy b)))**2.0 + (abs ((pz a)-(pz b)))**2.0)+instance Dist Position Position3D where dist a b = dist (Position3D a 0) b+instance Dist Position3D Position where dist a b = dist a (Position3D b 0)   {-| @orthogonal a@ returns the left- and right- orthogonal angles to a -} orthogonal ∷ Angle → (Angle,Angle) orthogonal a = (a+pi/4.0, a-pi/4.0) ---instance toPosition (Float,Float) where toPosition (x,y) = {px=x,py=y}---instance toPosition Position3D where toPosition p3D = p3D.pxy---instance fromPosition (Float,Float) where fromPosition p2D = (p2D.px,p2D.py)---instance fromPosition Position3D where fromPosition p2D = zero {pxy=p2D}---instance toPosition3D (Float,Float,Float) where toPosition3D (x,y,z) = {pxy=toPosition (x,y),pz=z}-instance ToPosition3D Position where toPosition3D p2D = zero {pxy=p2D}---instance fromPosition3D (Float,Float,Float) where fromPosition3D p3D = (p3D.(px pxy),p3D.(py pxy),p3D.pz)---instance fromPosition3D Position where fromPosition3D p3D = p3D.pxy----instance show Speed where show {direction,velocity}= "{direction=" +++ show direction +++ ",velocity=" +++ show velocity +++ "}"---instance show Speed3D where show {vxy,vz} = "{vxy=" +++ show vxy +++ ",vz=" +++ show vz +++ "}"---instance show Position where show {px, py} = "{px=" +++ show px +++ ",py=" +++ show py +++ "}"---instance show Position3D where show {pxy,pz} = "{pxy=" +++ show pxy +++ ",pz=" +++ show pz +++ "}"-------instance toSpeed Speed3D where toSpeed s = (vxy s)---instance fromSpeed Speed3D where fromSpeed s = zero {vxy=s}---instance toSpeed3D Speed where toSpeed3D s = zero {vxy=s}---instance fromSpeed3D Speed where fromSpeed3D s = (vxy s)----zero ∷ Num a ⇒ a---zero = fromIntegral 0+instance ToPosition (Float,Float) where toPosition (x,y) = Position {px=x,py=y}+instance ToPosition Position3D where toPosition p3D = pxy p3D+instance FromPosition (Float,Float) where fromPosition p2D = (px p2D, py p2D)+instance FromPosition Position3D where fromPosition p2D = 0 {pxy=p2D}+instance ToPosition3D (Float,Float,Float) where toPosition3D (x,y,z) = Position3D {pxy=toPosition (x,y),pz=z}+instance ToPosition3D Position where toPosition3D p2D = 0 {pxy=p2D}+instance FromPosition3D (Float,Float,Float) where fromPosition3D p3D = (px $ pxy p3D, py $ pxy p3D, pz p3D)+instance FromPosition3D Position where fromPosition3D p3D = pxy p3D+instance ToSpeed Speed3D where toSpeed s = (vxy s)+instance FromSpeed Speed3D where fromSpeed s = 0 {vxy=s}+instance ToSpeed3D Speed where toSpeed3D s = 0 {vxy=s}+instance FromSpeed3D Speed where fromSpeed3D s = (vxy s)  oppositeAngle ∷ Angle → Angle oppositeAngle a@@ -265,10 +249,10 @@  angleWithObject ∷ Position → Position → Angle angleWithObject base target-	| a >= (0.5*pi) && b >= zero = ((-pi)+a) -- linksvoor, naar boven, negatieve hoek, -0.5*pi < hoek < zero-	| a <= (0.5*pi) && b >= zero = (-pi)+b -- linksachter, naar beneden, negatieve hoek, -0.5*pi < hoek < -pi-	| a <= (0.5*pi) && b <= zero = pi+b -- rechtsachter, naar beneden, positieve hoek, 0.5*pi < hoek < pi-	| a >= (0.5*pi) && b <= zero = (-b) -- rechtsvoor, naar boven, positieve hoek, 0 < hoek < 0.5*pi+	| a >= (0.5*pi) && b >= 0 = ((-pi)+a) -- linksvoor, naar boven, negatieve hoek, -0.5*pi < hoek < 0+	| a <= (0.5*pi) && b >= 0 = (-pi)+b -- linksachter, naar beneden, negatieve hoek, -0.5*pi < hoek < -pi+	| a <= (0.5*pi) && b <= 0 = pi+b -- rechtsachter, naar beneden, positieve hoek, 0.5*pi < hoek < pi+	| a >= (0.5*pi) && b <= 0 = (-b) -- rechtsvoor, naar boven, positieve hoek, 0 < hoek < 0.5*pi 	where 	v = RVector (px base-px target) (py base-py target) 	d = dist base target