//===================================================================== // Overtime : Program Simulates Overtime in College Football, (c) 1996 // Author : Chris Strickland // Company : New Horizons Software // : Links to the WEB page are welcomed // : Any copying of the code on this page will be under the // : standard shareware license agreement. Donations are // : appreciated and will encourage future development of WEB // : products. // Developed: Nov 24, 96 // Modified : Dec 13, 96 // : May 31, 97 // : Sep 27, 98 - Added some checks for the down so it wouldn't // : output down 99. // : Also started setting up for both offense and // : defensive play calls. // : Nov 1, 98 - Changed the starting field position from // : the 35 to the 25 yardline. // : Nov 6, 98 - Added Tight Pass play. // : Nov 8, 98 - Fixed a problem with 1st down further than // : goaline, and TD's further than yardage. // : Dec 3, 98 - Added applet for java animation. // : Dec 5, 98 - Added new text //===================================================================== //--------------------------------------------------------- // Compute a Normally Distributed random number //--------------------------------------------------------- function RndNorm(avg, std) { var rWin=self.parent.Results; var su=0, i, u1, u2, dWin=self.parent.Results; u1=Math.random(); u2=Math.random(); var pi = 4.0 * Math.atan(1); var x=Math.sqrt(-2.0 * Math.log(u1)); var y=Math.cos(2.0*pi*u2); su = x * y; var value=std*su + avg; if (DEBUG == 1) { rWin.document.write("RndNorm: x=",x," y=", y,"
"); rWin.document.write("RndNorm: su=",su," u1=",u1," u2=", u2, " pi=",pi,"
"); rWin.document.write("RndNorm: avg=",avg," std=",std,"
"); rWin.document.write("RndNorm: value=",value,"
"); } return value; } //--------------------------------------------------------- function GetDefense() { var first=getCookie("first"); var rand=Math.random(); var DefensivePlay=Math.floor(Math.random()*TotDefensePlays); if (first <= 3 ) { if (rand < .5 ) DefensivePlay = ShortYardage; else if (rand < .8) DefensivePlay = RunDefense; } if (first >=3 && first < 8 ) { if (rand < .4 ) DefensivePlay = Standard; else if (rand < .7 ) DefensivePlay = ShortPass; } if (first >=8 ) { if (rand < .2 ) DefensivePlay = Blitz; else if ( rand < .5 ) DefensivePlay = Prevent; else if ( rand < .8 ) DefensivePlay = Standard; } return DefensivePlay; } //--------------------------------------------------------- function GetMessage(Offense, TotalYards, Scramble) { Scramble=NO; if ( Offense == QBSneak) { MessagePtr=Scramble; if (TotalYards < 5 && TotalYards >=2) MessagePtr=Dive; if (TotalYards < 2 && TotalYards > -1) MessagePtr=Stuff; if (TotalYards <= -1) MessagePtr=Crush; } if ( Offense == OffTackle) { MessagePtr=BreakHole; if (TotalYards < 3 && TotalYards > 0) MessagePtr=CloseHole; if (TotalYards <= 0) MessagePtr=PushBack; } if ( Offense == Draw) { MessagePtr=BreakHole; if (TotalYards < 5 && TotalYards > 0) MessagePtr=CloseHole; if (TotalYards <= 0) MessagePtr=BackField; } if ( Offense == Sweep) { MessagePtr=BreakHole; if (TotalYards < 5 && TotalYards > 1) MessagePtr=CBReadPlay; if (TotalYards <= 1) MessagePtr=NotFooled; } if ( Offense == Reverse) { MessagePtr=DefenseFooled; if (TotalYards < 7 && TotalYards > 2) MessagePtr=CBStayedZone; if (TotalYards <= 2) MessagePtr=DEReadPlay; } if ( Offense == Screen) { MessagePtr=DefenseFooled; if (TotalYards < 7 && TotalYards > 2) MessagePtr=CBStayedZone; if (TotalYards <= 2) MessagePtr=DEReadPlay; if ( TotalYards == -99) MessagePtr=Incomplete; } if ( Offense == TEPass) { MessagePtr=DefenseFooled; if (TotalYards < 7 && TotalYards > 2) MessagePtr=CBStayedZone; if (TotalYards <= 2) MessagePtr=DEReadPlay; if ( TotalYards == -99) MessagePtr=Incomplete; } if ( Offense == MedPass) { MessagePtr=DefenseFooled; if (TotalYards < 12) MessagePtr=CBStayedZone; if (TotalYards < 6) { MessagePtr=Scramble; Scramble=YES; } if (TotalYards <= 0) MessagePtr=Sack; if ( TotalYards == -99) MessagePtr=Incomplete; } if ( Offense == Fly) { MessagePtr=Awesome; if ( TotalYards < 15) MessagePtr=Dump; if ( TotalYards < 8) { MessagePtr=Scramble; Scramble=YES; } if ( TotalYards <= 0 ) MessagePtr=Sack; if ( TotalYards == -99) MessagePtr=Incomplete; } return MessagePtr; } //--------------------------------------------------------- function Yardage(Offense,Defense) { var TotalYards=0; var rWin=self.parent.Results; var ptr=Offense+(Defense*TotOffensePlays); TotalYards = Math.ceil(RndNorm(AvgStats[Offense+ (Defense*TotOffensePlays)], StdStats[ Offense+ (Defense*TotOffensePlays)])); if (DEBUG==1) { rWin.document.write("Yardage: Before Comp TotalYards=", TotalYards,"
"); rWin.document.write("Yardage: Offense=",Offense," Defense=",Defense,"
"); rWin.document.write("Yardage: PTR=",TotOffensePlays*Defense,"
"); rWin.document.write("Yardage: AvgStats=",AvgStats[ptr],"
"); rWin.document.write("Yardage: StdStats=",StdStats[ptr],"
"); rWin.document.write("Yardage: CompPass=",CompPass[ptr],"
"); } if (CompPass[ptr] < Math.random()) TotalYards = -99; if (DEBUG==1) rWin.document.write("Yardage: After Comp TotalYards=", TotalYards,"
"); return TotalYards; } //----------------------------------------------------------- function CheckTurnOver(OffensePlay, DefensePlay, TurnOverOdds, Scramble, TotalYards) { var MessagePtr=NoTurnOver; var x=getCookie("player"); var Rand=Math.random(); if (DEBUG==1) { self.parent.Results.document.write("CheckTurnOver: Rand=",Rand, "Turnover=", TurnOverOdds,"
"); self.parent.Results.document.write("CheckTurnOver: player=",x,"
"); } if (Rand < TurnOverOdds) { MessagePtr=Fumble; if (OffensePlay>=PassPlay && TotalYards != -99 && Scramble==NO) MessagePtr=Interception; if (x==0) x=1; else x=0; Reset(1); } else setCookie("player",x,toExpire,null,null,false); return MessagePtr; } //---------------------------------------------------------------- function ComputeDown() { var down = getCookie("down"); var rWin=self.parent.Results; if ( eval(down) < 4) { down=eval(down) + 1; setCookie("down",down,toExpire,null,null,false); } else { Reset(1); down=Lost; } if (DEBUG==1) rWin.document.write("ComputeDown: After down=",down,"
"); return down; } //---------------------------------------------------------------- function ComputeFirst(yards) { var rWin=self.parent.Results; var first=getCookie("first"); if (DEBUG==1 ) rWin.document.write("ComputeFirst: Before first=",first,"
"); first = eval(first) - yards; if (DEBUG == 1) rWin.document.write("ComputeFirst: toExpire=",toExpire,"
"); if ( eval(first) <= 0 ) { setCookie("down","0",toExpire,null,null,false); setCookie("first","10",toExpire,null,null,false); first=10; } if (DEBUG==1 ) rWin.document.write("ComputeFirst: After first=",first,"
"); setCookie("first",first,toExpire,null,null,false); return first; } //--------------------------------------------------------------- function ComputeYardLine(yards) { var yardline=getCookie("yard"); var rWin=self.parent.Results; yardline=eval(yardline)-yards; setCookie("yard",yardline,toExpire,null,null,false); return yardline; } //-------------------------------------------------------------------- function Reset(status) { var rWin=self.parent.Results; if (DEBUG == 1 ) rWin.document.write("Enter Results
"); deleteCookie("play"); deleteCookie("down"); deleteCookie("first"); deleteCookie("yard"); deleteCookie("player"); if (DEBUG==1) rWin.document.write("ComputeFirst: toExpire=",toExpire,"
"); setCookie("play","0",toExpire,null,null,false); setCookie("down","1",toExpire,null,null,false); setCookie("first","10",toExpire,null,null,false); setCookie("yard","25",toExpire,null,null,false); setCookie("player","0",toExpire,null,null,false); if (eval(status) == 0) { rWin.document.open(); rWin.document.bgColor="gold"; rWin.document.write("


"); rWin.document.write("Let's Play a New Game
"); rWin.document.write("Florida just scored a TD
"); rWin.document.write("FSU blocked the extra point
"); rWin.document.write("FSU has to score a TD to win!!!
"); rWin.document.write("

"); rWin.document.close(); } } function PlayBall() { // Initialize All variables. var xstr=""; var rWin=self.parent.Results; var pWin=self.parent.PlaySel; var Player=0; var TurnOverOdds=0; rWin.document.open(); rWin.document.bgColor="gold"; var player=getCookie("player"); initOffensivePlays(); initDefensivePlays(); initVars(); initTeams(); initMessages(); storeStats(); storePlayNames(); Scramble=NO; //-------------------------------------------------------- // Get the play slection //-------------------------------------------------------- if ( player == 0 ) { var OffensePlay=parent.PlaySel.document.Offense.Call.value; } else { var OffensePlay=parent.DefenseSel.document.Defense.Call.value; } //-------------------------------------------------------- // Double check to see if a play was selected. //-------------------------------------------------------- if (OffensePlay == null || OffensePlay == "" ) alert("Please Select Play (or finishing loading)."); else { var OffensePlay=OffensePlay-1; //-------------------------------------------------------- // Generate a defensive play call. Purely random for now. //-------------------------------------------------------- DefensePlay=GetDefense(); //-------------------------------------------------------- // Get the total yards gained. //-------------------------------------------------------- var TotalYards=Yardage(OffensePlay, DefensePlay); if (DEBUG==1) rWin.document.write("TotalYards=",TotalYards); //-------------------------------------------------------- // Find out the message that goes with the play. //-------------------------------------------------------- MessagePtr = GetMessage(OffensePlay,TotalYards,Scramble); if (DEBUG==1) rWin.document.write(MessagePtr,"
"); if (TotalYards == -99) TotalYards = 0; //Fix Incomplete Pass //-------------------------------------------------------- // Get the yardline, then see if it's a TD. //-------------------------------------------------------- OldYardLine=eval(getCookie("yard")); YardLine=ComputeYardLine(TotalYards); if ( eval(YardLine) <= 0 ) { Reset(1); MessagePtr=TD; } else { ToFirst=ComputeFirst(TotalYards); Down=ComputeDown(); } //-------------------------------------------------------- // Look to see if a turnover occurred. //-------------------------------------------------------- if ( MessagePtr != Incomplete && MessagePtr != TD) { TurnOverOdds=TurnOver[OffensePlay+(DefensePlay*TotOffensePlays)]; var hldPtr=MessagePtr; MessagePtr=CheckTurnOver(OffensePlay, DefensePlay, TurnOverOdds, Scramble, TotalYards); if (MessagePtr == NoTurnOver) MessagePtr=hldPtr; } player=getCookie("player"); //-------------------------------------------- // Write out the results of the play. //-------------------------------------------- rWin.document.write("
"); rWin.document.write("

And the ball is snapped.

"); rWin.document.write("
"); if (MessagePtr==Sack) rWin.document.write(""); if (MessagePtr==BreakHole || MessagePtr==Dive || MessagePtr==BigRun) rWin.document.write(""); if (MessagePtr==Awesome) rWin.document.write(""); if (MessagePtr==Incomplete) rWin.document.write(""); if (MessagePtr==Scramble) rWin.document.write(""); if (MessagePtr==TD) rWin.document.write(""); if (MessagePtr==Fumble) rWin.document.write(""); if (MessagePtr==Interception) rWin.document.write(""); //-------------------------------------------- // Write out information in right column. //-------------------------------------------- rWin.document.write(""); //-------------------------------------------------------- // Write out the play calls. //-------------------------------------------------------- rWin.document.write(OffensePlayName[OffensePlay]," vs ", DefensePlayName[DefensePlay],"
"); //-------------------------------------------------------- // Set the text color for positive or negative gain. //-------------------------------------------------------- txtclr="black"; if (TotalYards < 0 ) txtclr="red"; if ( MessagePtr == TD ) TotalYards = OldYardLine; rWin.document.write(Message[MessagePtr].fontcolor(txtclr), ": ", TotalYards," Yards".fontcolor(txtclr),"
"); if (MessagePtr != Fumble && MessagePtr != TD && MessagePtr != Interception ) { if ( Down != 99) rWin.document.write("Down: ", Down,"
"); if (YardLine < ToFirst) ToFirst=YardLine; rWin.document.write("Yards For First: ",ToFirst,"
"); rWin.document.write("Ball on the: ",YardLine, "
"); } if ( Down == Lost || MessagePtr==Fumble || MessagePtr==Interception ) player=player*-1 + 1; rWin.document.write(PlayerName[player], " Has the Ball
"); rWin.document.write("
"); if ( Down == Lost || MessagePtr==Interception || MessagePtr==Fumble ) { rWin.document.write("

"); rWin.document.write("You Just Lost in Overtime
"); rWin.document.write("

"); } rWin.document.close(); } // if (TotalYards !=0 ) { var dialog = window.open("","dialogBox","height=375,width=425"); dialog.document.open("text/html"); dialog.document.writeln("College Football Overtime"); dialog.document.writeln(""); dialog.document.writeln("
Go Seminoles Go!!!

"); dialog.document.writeln("'); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.writeln(''); dialog.document.close(); dialog.focus(); // } // dialog.close(); }