# Note: rules files can now use '#' as a comment character 
# (but only if it's the first char in a line)
# An alternative to this file is to use the -cmdline option on ./trilearn_player 
# and input coach commands via stdin. 
#

(define (definer "RegLeft" (rec (pt -52 35) (pt -5 -35) )) )
(define (definer "RegRight" (rec (pt -5 -35) (pt 52 35) )) )
# RegLeft and RegRight overlap a little

(define (definer "RegCenter" (rec (pt -5 -35) (pt 5 35) )) )
(define (definer "RegLeftGoal" (rec (pt -52 -35) (pt -45 35) )) )
(define (definer "RegLeftGoalSpace" (rec (pt -52 -10) (pt -45 10) )) )

(define (definer "RegRightGoal" (rec (pt 40 -20) (pt 52 20) )) )
#(define (definer "BallPos" (rec ((pt ball)+(pt -2 -2)) ((pt ball)+(pt 1 1)) )  ))

#(define (definer "CloseToBall" (rec ((pt ball) - (pt 0.5 0.5)) ((pt ball) + (pt 0.5 0.5)))))
# a circle around the ball:
(define (definer "CloseToBall" (arc (pt ball) 0 0.5 0 360) ))
(define (definer "RegAroundBall" (arc (pt ball) 0 10 0 360) ))

(define (definer "RegLeftOfBall" (rec (pt -52.5 -34) (((pt ball) * (pt 1 0)) + (pt 0 34)))))
(define (definer "RegRightOfBall" (rec (((pt ball) * (pt 1 0)) + (pt 0 34)) (pt 52.5 -34))))




#-----------------------------------------------------------------------------------------

# Defender offsides and marking

# defensive strategies

# if the ball is in the right side of the field, pull defenders up!
# We have to separate the regions because the UTA players will all go to middle
# otherwise.

(define (definer "RegOffsides5" (rec (pt -15 -30) (pt -10 -15))))
(define (definer "RegOffsides4" (rec (pt -15 -15) (pt -10 0))))
(define (definer "RegOffsides3" (rec (pt -15 0) (pt -10 15))))
(define (definer "RegOffsides2" (rec (pt -15 15) (pt -10 30))))
(define (definerule PullOffsides direc ((and (playm play_on) (bpos "RegRight")) (do our {2} (pos "RegOffsides2")) (do our {3} (pos "RegOffsides3")) (do our {4} (pos "RegOffsides4")) (do our {5} (pos "RegOffsides5")) )))
# turn the rules on
(rule (on PullOffsides))

# if the player is a defender and the ball is behind it, go straight to a point left of the ball
#(define (definerule GetBehindBall direc ((and (playm play_on) (ppos our {2 3 4 5} 1 4 "RegRightOfBall")) (do our {2 3 4 5} (pos "RegLeftOfBall")))))
# a more complicated version so that only the players who are right of the ball go there
#(define (definerule GetBehindBall direc ((and (playm play_on) (unum X {2 3 4 5} (ppos our {X} 1 4 "RegRightOfBall")) (do our {X} (pos "RegLeftOfBall")))))
# now exapnded out
(define (definerule GetBehindBall2 direc ((and (playm play_on) (ppos our {2} 1 1 "RegRightOfBall")) (do our {2} (pos "RegLeftOfBall")))) (definerule GetBehindBall3 direc ((and (playm play_on) (ppos our {3} 1 1 "RegRightOfBall")) (do our {3} (pos "RegLeftOfBall")))) (definerule GetBehindBall4 direc ((and (playm play_on) (ppos our {4} 1 1 "RegRightOfBall")) (do our {4} (pos "RegLeftOfBall")))) (definerule GetBehindBall5 direc ((and (playm play_on) (ppos our {5} 1 1 "RegRightOfBall")) (do our {5} (pos "RegLeftOfBall")))) )
# turn the rules on
(rule (on (GetBehindBall2 GetBehindBall3 GetBehindBall4 GetBehindBall5)))


# if the ball is in our side of the field, start marking opponents!
(define (definer "RegAlwaysMark" (rec (pt -52 35) (pt -5 -35) )) )
(define (definer "RegSometimesMark" (rec (pt -5 35) (pt 25 -35) )) )
(define (definer "RegAlwaysPullUp" (rec (pt 25 35) (pt 52.5 -35) )) )
(define (definerule MarkPlayer direc ((and (playm play_on) (not (bpos "RegAlwaysPullUp")) (or (bpos "RegAlwaysMark") (and (not (bowner our {0})) (bpos "RegSometimesMark")))) (do our {2 3 4 5} (mark {0})))))
# turn the rules on
(rule(on MarkPlayer))


#-----------------------------------------------------------------------------------------
# handling the ball - these should all be really simple so that the action picker can choose based on priority levels

# only defenders and midfielders should clear the ball
(define (definerule ClearBall direc ((and (playm play_on) (unum DefenderMid {2 3 4 5 6 7 8}) (bpos (arc (pt our DefenderMid) 0 .7 0 360)) (bpos "RegLeft")) (do our {DefenderMid} (clear "RegLeft")))))
(rule (on ClearBall))

# all players should consider pass forwards if the ball is kickable
#(define (definerule PassBall direc ((and (playm play_on) (unum Passer {0}) (bpos (arc (pt our Passer) 0 0.7 0 360)) (unum Passee {0}) (ppos our {Passee} 1 11 "RegRightOfBall")) (do our {Passer} (pass {Passee})))))
#(rule (on PassBall))

# all players should consider dribbling if the ball is kickable
#(define (definerule DribbleDownField direc ((and (unum Dribbler {0}) (bpos "RegRight")) (do our {Dribbler} (dribble "RegRightGoal")))))
#(rule (off DribbleDownField))

# all players should consider taking a shot
#(define (definerule ShootBall direc ((and (unum Shooter {0}) (bpos (arc (pt our Defender) 0 .7 0 360))) (do our {Shooter} (shoot)))))
#(rule (on ShootBall))

# all players should consider a tackle
#(define (definerule TackleBall direc ((unum Tackler {0}) (do our {Tackler} (tackle {0})))))
#(rule (on TackleBall))

#-----------------------------------------------------------------------------------------
