THE TOOLS (SUB-PROGRAMS) OF BHL PROJECT Tuesday, October 15, 2002 --------------------------------------------------------------------------- --------------------------------------------------------------------------- A) CONSTANTS & GLOBALS use constant CONFIG_FILE => 'sim.cfg' ; use constant PLAYERS_DB => 'playersdb.csv' ; use constant GOALIES_DB => 'goaliesdb.csv' ; use constant TEAMS_DB => 'teamsdb.csv' ; use constant SEASON_P_DB => 'season_p_db.csv'; use constant SEASON_G_DB => 'season_g_db.csv'; use constant LOGIN_PHP => 'login.php' ; use constant BUG_FILE => 'bug.log' ; use constant EMPTY => '' ; use constant TRUE => 1 ; use constant FALSE => 0 ; use constant SEASON_DIR => 'season' ; use constant TEAM_DIR => 'teams' ; use constant PLAYOFF_DIR => 'playoffs' ; use constant SCHED_DAT => 'schedule.dat' ; use constant SIM_SPEED => 0 ; use constant FREE_AGENT => '---' ; use constant SCORER_INDEX => 2 ; use constant PENALTY_INDEX => 4 ; use constant META_TAG => ''; my $BROWSER = "explorer"; my $START = 1; # flag only when game 1st up my $LEAGUE_NAME = "default"; my $SEASON_NAME = "default"; my $SEASON_NUM = 0; my $PLAYOFF_MODE = 0; #0=reg. season, 1=playoffs. my $ROUND = 0; #Playoff round my $SEASON_OVER_FLAG = 0; my $PP_FLAG = 0; my $HOME_ADVANTAGE = 5; my $P_P_ADVANTAGE = 3; my $GOALIE_STRENGTH = 2; my $OT = 1; # 0=3 per, 1=1 ot, 2=ot till per. my $DBUG = FALSE; --------------------------------------------------------------------------- B) METHODS 1) sub mkGameArray - @home=mkGameArray($team); 2) sub gameSetUp - @home=gameSetUp($homeTeam); 3) sub testGameMis - testGameMis(); 4) sub specificPen - @penalty=specificPen(); 5) sub decider - $decided = decider($percentage); 6) sub decideOn3 - $decision = decideOn3(70, 20, 10); 7) sub randEvent - $event = randEvent(); 8) sub printClock - printClock(@timeOfEvent); 9) sub gameClock - @timeOfEvent=gameClock(1, 0, 5); 10) sub whoScored - @scorer = whoScored(5, @homeTeam); 11) sub puckPosition - $whersPuck=puckPosition($homePlusMinus, $awayPlusMinus, 0, 15, 50); 12) sub percentAdjustTo - $per = percentAdjustTo($per); 13) sub getValues - $homePlusMinus=getValues(3, 0, 17, @home); 14) sub getGoalie - @goalie=getGoalie($GOALIE_STRENGTH, @home); 15) sub getValue - $homePlusMinus=getValue(3, 17, @home); 16) sub updateBox - %penaltyBox=updateBox($secondCount, %penaltyBox); 17) sub currentSecond - $SecondCount=currentSecond(@timeOfEvent); 18) sub checkTheBox - @homePenPerson = checkTheBox($PEN_INDEX, $hashReference, @home); 19) sub penBoxOfficial - $flag = penBoxOfficial($home, $away, %penaltyBox); 20) sub doesPlayerExist - if(doesPlayeExist($name, @teamArray)){} 21) sub clockToString - $t = clockToString(@timeOfEvent); 22) sub handleEvent - handleEvent($currentPeriod, $time, $EVENT, $player1, $player2, $player3, $team, $H_OR_A, $powerPlayFlag, $penSec, $penDesc, $gameMisconductFlag, @results); 23) sub makeTeamNameHash - %teams = makeTeamNameHash(); 24) sub gameArrayZeroerOuter - @hGameStats=gameArrayZeroerOuter(0, @aTeam); 25) sub getStat - $stat=getStat($stat_name, $player, @game_array); 26) sub postStat - @aTeam=postStat("p_goal", $player, $thing, $add_write_flag, @aTeam); 27) sub getLineMates - @line_mates = getLineMates($player, @team); 28) sub getLine - $line_number = getLine($player, @team); 29) sub runGame - @results = runGame("nyr", "nyi", $hAdvantage, $powerPlayAdvantage, $goalieStrength, $howManyOvertimes); 30) sub getDate - @today = getDate(); 31) sub makeHtmlResults - makeHtmlResults(@game); 32) sub printScreenResults - printScreenResults(@game); 33) sub checkTeam - if(checkTeam($team, @array)){} 34) sub getTeam - $homeTeam = getTeam("Home"); 35) sub openFile - @team_array = openFile($file); 36) sub teamsArray - @teamsAvail = teamsArray(); 37) sub teamsAvailable - teamsAvailable(); 38) sub saveStats - saveStats($PLAYERS_DB, @playersStats); 39) sub changeLines - changeLines($teamWanted, $manOrRand); 40) sub countGoalies - @array=countGoalies($team); 30) sub countPlayers - @array=countPlayers($team); 31) sub reportLines - reportLines($team); 32) sub inspectLines - inspectLines($team); 33) sub getEAnswer - $answer = getEAnswer(); 34) sub prompt_clear - prompt_clear(); 35) sub leagueEdit - leagueEdit(); 36) sub saveGameResults - saveGameResults($file); 37) sub createPlayer - createPlayer(); 38) sub deletePlayer - deletePlayer(); 39) sub printPlayersAvailable - printPlayersAvail($team); 40) sub startSeason - startSeason(); 41) sub makePlayerHtmlStats - makePlayerHtmlStats(); 42) sub sorter - sorter(2, 11, PLAYERS_DB); 43) sub makeGoalieHtmlStats - makeGoalieHtmlStats(); 44) sub rounder - rounder($value, $precision); 45) sub addStats - addStats(@homeResults); 46) sub makeSchedule - makeSchedule($exclusionTeam); 47) sub updateHtmlSched - updateHtmlSched($hscore, $ascore, $home, $way); 48) sub checkDB - checkDB(); 49) sub updateHtmlSched - updateHtmlSched($hscore, $ascore); 50) sub trade - trade(); 51) sub reinsertPlayer - reinsertPlayer($db_line, $replace_with, $index); 52) sub printBHL - printBHL(); 53) sub makeTradeHtml - makeTradeHtml(); 54) sub updateTradesWebPage - updateTradesWebPage($player_name, $from_team_abr, $to_team_abr); 55) sub checkDir - checkDir($dir); 56) sub makeStandingsFile - makeStandingsFile(); 57) sub updateTeamDB - updateTeamDB(@results); 59) sub resetStandDB - resetStandDB(); 60) sub arraySorter - arraySorter(2, $delimiter, @file_contents); 61) sub backErUpper - backErUpper($file, $dir); 62) sub getSAnswer - $answer = getSAnswer(); 63) sub getPAnswer - $answer = getPAnswer(); 64) sub setUpPlayoffsSchedule - setUpPlayoffsSchedule(); 65) sub setUpPlayoffs - setUpPlayoffs(); 66) sub configFileReadMe - configFileReadMe(); 67) sub openFileWIgnore - openFileWIgnore($file, $ignore, $i); 68) sub createTeam - createTeam(); 69) sub debug - if ($DBUG){debug($tabs, $message);} 70) sub initializeConstants - initializeConstants(); 71) sub setDivisions - @array=setDivisions(@array); 72) sub evenChecker - if (evenChecker(%hash)){} 73) sub printHash - printHash(%hi); 74) sub DBFixer - DBFixer(@file_array); 75) sub addTeamsToHtml - addTeamsToHtml(); 76) sub saftyFirst - saftyFirst(); 77) sub getTeamStats - @array = getTeamStats($team); 78) sub pc - pc(); 79) sub getTeamHTMLInfo - @info=getTeamHTMLInfo($team); 80) sub makeTeamHTML - makeTeamHTML(); 81) sub array2DReplace - if (array2DReplace($rs, $rw, $s, $r, $file)){} --------------------------------------------------------------------------- B) ARRAY DEFINITIONS 1) runGame results array: [0] = 1st period home team points [1] = 2nd period home team points [2] = 3rd period home team points [3] = OT periods home team points [4] = 1st period away team points [5] = 2nd period away team points [6] = 3rd period away team points [7] = OT periods away team points [8] = 1st period events list(: separated) [9] = 2nd period events list(: separated) [10] = 3rd period events list(: separated) [11] = OT period events list(: separated) [12] = 1st period home team shots [13] = 2nd period home team shots [14] = 3rd period home team shots [15] = OT periods home team shots [16] = 1st period away team shots [17] = 2nd period away team shots [18] = 3rd period away team shots [19] = OT periods away team shots [20] = home power play conversions [21] = away power play conversions [22] = home goalie [23] = away goalie [24] = home pen minutes [25] = away pen minutes [26] = periods [27] = game misconduct list (, separated) [28] = home Full Team Name String [29] = away Full Team Name String [30] = game winning goal scorer 2) goaliesdb: [0] = full name [1] = team abbr [2] = save % [3] = line [4] = wins [5] = losses [6] = ties [7] = saves [8] = goals against [9] = goals against average [10] = games 3) playersdb: [0] = full name [1] = team abbr [2] = pts [3] = +/- [4] = pen [5] = ppg [6] = shg [7] = gwg [8] = gtg [9] = line [10] = shots [11] = goals [12] = assists [13] = games 4) teamsdb: [0] = team name abbr. [1] = full name [2] = conference [3] = division [4] = games [5] = wins [6] = loses [7] = ties [8] = points [9] = win% [10] = Goals For [11] = Goals Against [12] = Power Play Goals [13] = PPM [14] = PP% [15] = PM [16] = PK% [17] = Owner Info [18] = Address [19] = Contact Info [20] = Arena Name [21] = Seating Capacity [22] = Last Games Attendance 5) handleEvent: [0] = int (current period) [1] = string (formatted time of event) [2] = string (goal, shot, pen) [3] = string (player name) [4] = string (player two name, null if none) [5] = string (player three name, null if none) [6] = string (team name) [7] = string (home, away) [8] = int (power play)1=homepp, 2=awaypp, 0=evenstrength [9] = int (penalty seconds) [10] = string (penalty description) [11] = int (game Misconduct Flag) [12] = array (the return array) SAMPLE CALL: handleEvent($currentPeriod, $time, $EVENT, $player1, $player2, $player3, $team, $H_OR_A, $powerPlayFlag, $penSec, $penDesc, $gameMisconductFlag, @results); 6) specificPen: [0] = string (description) [1] = int (seconds penalized) [2] = int (kind my $SINGLE_PEN = 1; my $MATCHING_PEN = 2; my $INSTIGATOR_OTHER_PEN = 3; my $INSTIGATOR_THIS_PEN = 4; my $MATCH_MISCONDUCT = 5; my $GAME_MISCONDUCT = 6; 7) team info array: [0] = team name abbr. [1] = full name [2] = conference [3] = division [4] = games [5] = wins [6] = loses [7] = ties [8] = points [9] = win% [10] = Goals For [11] = Goals Against [12] = Power Play Goals [13] = PPM [14] = PP% [15] = PM [16] = PK% [17] = Owner Info [18] = Address [19] = Contact Info [20] = Arena Name [21] = Seating Capacity [22] = Last Games Attendance [23] = Next opponent w/ date [24] = Last opponent w/ date & score [25] = Lines are set flag [26] = Date Compiled 7) bug log array (csv file): [0] = who posted [1] = date posted [2] = date action is taken [3] = status (posted, in progress, done, cant be fixed) [4] = message --------------------------------------------------------------------------- C) ERROR/DEBUG TOOLS 1) my $problem = "argument is to small"; (my $package, my $filename, my $line) = caller; print"\n$filename:subroutine $package,$problem,line $line\n"; prompt_clear(1); return 1; 2) if($DBUG){ my ($p, $f, $l) = caller; print"---------- HANDLE EVENT ----------\n"; print"$f Called from line $l\n"; print"----------------------------------\n"; print"trades array: \n@trades\n"; prompt_clear(1); }