DO
Wait[delay];
IF stopped THEN {process ← NIL; EXIT};
check clock and penalties
IF ~controlGame.clockStopped
AND controlGame.quarter # 5
THEN
IF BasicTime.Now[] # gmt
THEN {
controlGame.clock ← controlGame.clock - 1;
gmt ← BasicTime.Now[]};
IF controlGame.clock <= 0
AND controlGame.state < option
THEN
PlayOver[controlGame.scrimmage];
IF delayOfGame
AND controlGame.state < option
AND startHuddle - controlGame.clock > 60
THEN {
readyHome: BOOL = Ready[home];
readyVisitors: BOOL = Ready[visitors];
SELECT
TRUE
FROM
~readyHome AND ~readyVisitors => {startHuddle ← controlGame.clock; LOOP};
~readyHome => controlGame.penalties[home] ← delayOfGame;
~readyVisitors => controlGame.penalties[visitors] ← delayOfGame;
ENDCASE => controlGame.penalties[controlGame.offense] ← delayOfGame;
PlayOver[controlGame.scrimmage, TRUE]};
IF (controlGame.penalties[home] = offSides
OR controlGame.penalties[visitors] = offSides)
AND controlGame.state > setUp THEN PlayOver[controlGame.scrimmage, TRUE];
is the ball now out of play?
x ← controlGame.player[ball].x;
y ← controlGame.player[ball].y;
IF controlGame.state > setUp
AND
(x NOT IN [-10..110] OR y NOT IN [0..fieldWidth]) THEN PlayOver[x, TRUE];
IF controlGame.state > setUp
AND controlGame.ballCarrier # ball
AND
Direction[TeamOf[controlGame.ballCarrier], controlGame.quarter] = 1 AND x > 100
THEN PlayOver[101, TRUE];
IF controlGame.state > setUp
AND controlGame.ballCarrier # ball
AND
Direction[TeamOf[controlGame.ballCarrier], controlGame.quarter] = -1 AND x < 0
THEN PlayOver[-1, TRUE];
move the ball
IF controlGame.state > setUp
AND controlGame.ballCarrier = none
THEN {
[x, y] ← GetTarget[controlGame.ballTarget, none];
MoveBall[@controlGame.player[ball], x, y]; CatchBall[];
IF controlGame.player[ball].x = x
AND controlGame.player[ball].y = y
THEN
-- ball has hit the ground
IF controlGame.pass
AND ~controlGame.lateral
THEN PlayOver[controlGame.scrimmage, TRUE]
ELSE controlGame.state ← liveBall};
are we committed to a run?
IF controlGame.state = option
AND
CrossLine[x, controlGame.scrimmage, controlGame.offense, controlGame.quarter]
THEN controlGame.state ← run;
move home team
command ← commands[home];
FOR i:
CARDINAL
IN [0..6)
DO
player ← @controlGame.player[Add[HQB, i]];
IF controlGame.state
IN [offField..setUp]
THEN {
IF command[i].action # run THEN LOOP;
[x, y] ← GetTarget[command[i].target, player.position];
Move[player, x, y, TRUE]; LOOP};
PlayAction[player, command[i]];
ENDLOOP;
move visitors team
command ← commands[visitors];
FOR i:
CARDINAL
IN [0..6)
DO
player ← @controlGame.player[Add[VQB, i]];
IF controlGame.state
IN [offField..setUp]
THEN {
IF command[i].action # run THEN LOOP;
[x, y] ← GetTarget[command[i].target, player.position];
Move[player, x, y, TRUE]; LOOP};
PlayAction[player, command[i]];
ENDLOOP;
ENDLOOP;