unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Menus, ComCtrls, shellapi; Const LoadFile = 'config.txt'; Scroll = 'Woburn Robotics Scoring program, visit us at www.team188.com'; BlankString = ' '; Title = 'Team 188 Scoring '; type TForm1 = class(TForm) ListBox1: TListBox; Edit1: TEdit; Label1: TLabel; Edit2: TEdit; Edit3: TEdit; Label3: TLabel; Edit4: TEdit; Edit5: TEdit; Label2: TLabel; Edit6: TEdit; Edit7: TEdit; Label4: TLabel; Edit8: TEdit; Edit9: TEdit; Label5: TLabel; Edit10: TEdit; Edit11: TEdit; RadioButton1: TRadioButton; RadioButton2: TRadioButton; CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; Edit18: TEdit; Image1: TImage; MainMenu1: TMainMenu; File1: TMenuItem; Run1: TMenuItem; Exit1: TMenuItem; Export1: TMenuItem; Edit16: TMenuItem; Clear1: TMenuItem; Sort1: TMenuItem; Refresh1: TMenuItem; TerminateCase1: TMenuItem; Help1: TMenuItem; About1: TMenuItem; Label8: TLabel; Label9: TLabel; CheckBox4: TCheckBox; CheckBox5: TCheckBox; SaveConfig1: TMenuItem; Label6: TLabel; Label7: TLabel; Label10: TLabel; Edit12: TEdit; Label13: TLabel; Edit13: TEdit; Edit14: TEdit; Label11: TLabel; Label12: TLabel; Timer1: TTimer; Bevel1: TBevel; Image2: TImage; Label14: TLabel; procedure RunScores(Sender: TObject); procedure ExportData(Sender: TObject); procedure ClearBox(Sender: TObject); procedure RfrshData(Sender: TObject); procedure FormCreate(Sender: TObject); procedure SaveData(Sender: TObject); procedure ResetCase(Sender: TObject); procedure SortData(Sender: TObject); procedure About1Click(Sender: TObject); procedure Exit1Click(Sender: TObject); procedure FormResize(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Image2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; FirstRun : Boolean; BlackMod : Byte; Start : Integer; Lead : Byte; Link : String; K : Integer; Neg : Boolean; implementation uses Unit2; const G : array[0..2] of Byte = (1,2,4); T : array[2..6] of Byte = (0,15,30,60,90); {$R *.DFM} type tSituation = class Mu,Ro,Bi,Bl,Go,Yo,St : Byte; Score : Word; Constructor Create( _Mu,_Ro,_Bi,_Bl,_Go,_Yo,_St : Byte ); End; tarr = array of tsituation; TRobStats = class OnRamp : Boolean; Squish : Byte; ScoreBig : Boolean; Cork : Boolean; ScoreSmall : Boolean; SmallTime : Byte; BigTime : Byte; SquishTime : Byte; BalanceTime : Byte; CrossTime : Byte; Moving : Boolean; Pusher : Boolean; PushTime : Byte; RampManip : Boolean; RampMTime : Byte; //Constructor Create; End; Var Scs : tarr; Procedure KillArray( var A : tarr ); Var I : Word; Begin If Length(A) > 0 Then For I := Low(A) to High(A) Do A[i].free; SetLength( A, 0 ); End; (*procedure sort(var a : array of tsituation); procedure sort2(lo, hi : integer); var i, j : integer; mid : integer; t : tsituation; begin mid := a[(i + j) div 2].score; i := lo; j := hi; while i <= j do begin while a[i].score < a[mid].score do inc(i); while a[mid].score < a[j].score do dec(j); if i <= j then begin t := a[i]; a[i] := a[j]; a[j] := t; inc(i); dec(j); end; end; if lo < j then sort2(lo, j); if i < hi then sort2(i, hi); end; begin if length(a) > 1 then sort2(0, high(a)); end; *) procedure SortScore(var a : array of tsituation); procedure sort2(lo, hi : integer); var i, j : integer; mid : integer; t : tsituation; begin Application.ProcessMessages; i := lo; j := hi; mid := a[(i + j) div 2].score; while i <= j do begin while a[i].score < mid do inc(i); while mid < a[j].score do dec(j); if i <= j then begin t := a[i]; a[i] := a[j]; a[j] := t; inc(i); dec(j); end; end; if lo < j then sort2(lo, j); if i < hi then sort2(i, hi); end; begin if length(a) > 1 then sort2(0, high(a)); end; Constructor tSituation.Create( _Mu,_Ro,_Bi,_Bl,_Go,_Yo,_St : Byte ); Begin Mu := _Mu; Ro := _Ro; Bl := _Bl; Bi := _Bi; Go := _Go; Yo := _Yo; St := _St; Score := Round((Mu/2)*G[Go]*(Yo/10)*(10*Bi + 10*Ro + bl*BlackMod + st*10)); End; Procedure PrintResults(B : array of tsituation; X : TListBox ); Var I, It : LongInt; Begin If form1.checkBox1.checked or FirstRun Then Begin X.Clear; FirstRun := False; End; For I := Low(B) to High(B) Do with B[i] do With X Do Begin Application.ProcessMessages; It := Items.Add( IntToStr( Score ) ); if form1.radiobutton2.checked then Begin Items[It] := Items[it] + ': ' + IntToStr(T[Mu]) + 's remaining'; If Ro > 0 Then Items[it] := Items[it] +' '+ IntToStr(Ro) + ' robots in end zone'; If go > 0 Then Items[it] := Items[it] +' '+ IntToStr(Go) + ' goals balanced'; If st > 0 Then Items[it] := Items[it] +' '+'stretcher in end zone'; If bi > 0 Then Items[it] := Items[it] +' '+ IntToStr(bi) + ' big balls scored'; If Yo > 10 Then Items[it] := Items[it] +' '+ 'our ball on top'; If bl > 0 Then Items[it] := Items[it] +' '+ IntToStr(bl*BlackMod) + ' small balls scored'; End; if form1.radiobutton1.checked then Items[it] := Items[it] + ',' + IntToStr( t[Mu]) + ',' + IntToStr( ro) + ',' + IntToStr( bi) + ',' + IntToStr( bl) + ',' + IntToStr( go) + ',' + floatToStr(yo/10) + ',' + IntToStr( St); End; End; procedure TForm1.RunScores(Sender: TObject); Var Multi,Robots,Big,Black,Goals,Your,Stretch : Byte; aMulti,aRobots,aBig,aBlack,aGoals,aYour,aStretch : Byte; bMulti,bRobots,bBig,bBlack,bGoals,bYour,bStretch : Byte; Score : Integer; It : Integer; X : tSituation; Mx,Mn : Word; begin Label12.Caption := 'Working ...'; Label12.Repaint; // X := tSituation.Create(2,0,0,0,0,0,0); If checkbox2.checked then KillArray(Scs); aMulti := StrToInt( Edit1.Text ); case aMulti of 0..15: amulti:=2; 16..30: amulti:=3; 31..60: amulti:=4; 61..90: amulti:=5; 91..120: amulti:=6; end; // bMulti := StrtoInt (Edit3.Text); case StrToInt(Edit3.Text) of 0..15: bmulti:=2; 16..30: bmulti:=3; 31..60: bmulti:=4; 61..90: bmulti:=5; 91..120: bmulti:=6; end; aRobots := StrToInt( Edit4.Text ); aBig := StrToInt( Edit6.Text ); aBlack := StrToInt( Edit8.Text ); aGoals := StrToInt( Edit10.Text ); if CheckBox5.Checked Then Begin aYour := 11; bYour := 11; End Else Begin aYour := 10; bYour := 10; End; if CheckBox4.Checked Then Begin aStretch := 1; bStretch := 1; End Else Begin aStretch := 0; bStretch := 0; End; //bMulti := StrToInt( Edit3.Text ); bRobots := StrToInt( Edit5.Text ); bBig := StrToInt( Edit7.Text ); bBlack := StrToInt( Edit9.Text ); bGoals := StrToInt( Edit11.Text ); Mn := StrToInt ( Edit13.Text ); Mx := StrToInt ( Edit14.Text ); BlackMod := StrToInt( Edit12.text ); For Multi := aMulti to bMulti Do For Robots := aRobots to bRobots Do For Big := aBig to bBig Do Begin For Black := aBlack to bBlack Do For Goals := aGoals to bGoals do For Your := aYour to bYour Do For Stretch := aStretch to bStretch Do Begin X := tSituation.Create(Multi,Robots,Big,Black,Goals,Your,Stretch); If (X.Score > Mn) and (X.Score < Mx) Then If (Not ((Your = 11) and (Big<1))) Then Begin SetLength( Scs, Length(Scs)+1); Scs[High(Scs)] := X; Application.ProcessMessages; End; End; End; Label12.Caption := 'Sorting ...'; Label12.Repaint; If checkbox3.checked then SortScore(Scs); Label12.Caption := 'Displaying ...'; Label12.Repaint; RfrshData(Sender); Label12.Caption := ''; end; procedure TForm1.ExportData(Sender: TObject); begin ListBox1.Items.Insert(0,Edit18.Text); ListBox1.Items.SaveToFile(edit2.text); // Form1.Close; end; procedure TForm1.ClearBox(Sender: TObject); begin ListBox1.Clear; end; procedure TForm1.SaveData(Sender: TObject); Var X : TextFile; begin AssignFile( X, LoadFile ); ReWrite ( X ); WriteLn(X,Edit1.Text); WriteLn(X,Edit4.Text); WriteLn(X,Edit6.Text); WriteLn(X,Edit8.Text); WriteLn(X,Edit10.Text); WriteLn(X,CheckBox4.Checked); WriteLn(X,CheckBox5.Checked); WriteLn(X,Edit3.Text); WriteLn(X,Edit5.Text); WriteLn(X,Edit7.Text); WriteLn(X,Edit9.Text); WriteLn(X,Edit11.Text); WriteLn ( X, Edit12.Text ); WriteLn ( x, Edit18.text ); WriteLn ( X, Edit2.Text ); WriteLn ( X, CheckBox1.Checked ); WriteLn ( X, CheckBox2.Checked ); WriteLn ( X, CheckBox3.Checked ); WriteLn ( X, RadioButton1.Checked ); WriteLn ( X, RadioButton2.Checked ); WriteLn ( x, Edit13.Text ); WriteLn ( X, Edit14.Text ); CloseFile( X ); end; procedure TForm1.FormCreate(Sender: TObject); var X : TextFile; S : String; begin Left := 10; Top := 10; AssignFile( X, LoadFile ); Reset ( X ); ReadLN(X,S); Edit1.Text := s; ReadLN(X,S); Edit4.Text := s; ReadLN(X,S); Edit6.Text := s; ReadLN(X,S); Edit8.Text := s; ReadLN(X,S); Edit10.Text := s; ReadLN(X,S); If uppercase(S) = 'TRUE' Then CheckBox4.Checked := True Else CheckBox4.Checked := False; ReadLN(X,S); CheckBox5.Checked := UpperCase(S) = 'TRUE'; ReadLN(X,S); Edit3.Text := s; ReadLN(X,S); Edit5.Text := s; ReadLN(X,S); Edit7.Text := s; ReadLN(X,S); Edit9.Text := s; ReadLN(X,S); Edit11.Text := s; ReadLn ( x, S ); Edit12.Text := S; ReadLn ( x, S ); Edit18.Text := S; ReadLn ( x, S ); Edit2.Text := S; ReadLn ( x, S ); CheckBox1.Checked := uppercase(S) = 'TRUE'; ReadLn ( x, S ); CheckBox2.Checked := uppercase(S) = 'TRUE'; ReadLn ( x, S ); CheckBox3.Checked := uppercase(S) = 'TRUE'; ReadLn ( x, S ); RadioButton1.Checked := uppercase(S) = 'TRUE'; ReadLn ( x, S ); RadioButton2.Checked := uppercase(S) = 'TRUE'; ReadLn ( x, S ); Edit13.Text := S; ReadLn ( x, S ); Edit14.Text := S; CloseFile(X); If (Height + Top) > Screen.Height Then Height := Screen.Height - (20+Top); //If (Width + Left) > Screen.Width Then Width := Screen.Width - (20+Left); Width := Screen.Width - Left - 20; ListBox1.Width := Width - ListBox1.Left - 10; Image1.Left := (Width - Image1.Width) div 2; { Label14.Top := ClientHeight - Label14.Height - 5; Label14.Left := ClientWidth - Label14.Width - 5; } bevel1.width:=form1.clientwidth; end; procedure TForm1.RfrshData(Sender: TObject); begin PrintResults( Scs, ListBox1 ); end; procedure TForm1.SortData(Sender: TObject); var An : String; begin //An := UpperCase ( InputBox ( 'Sort by', 'Sc (score), Bi (big), bl (black), ti (time), St (stretcher), Ou (our ball)', 'sc' ) ); {If 'SC' = An then} SortScore(Scs); PrintResults( Scs, ListBox1 ); end; procedure TForm1.ResetCase(Sender: TObject); begin KillArray(Scs); end; procedure TForm1.About1Click(Sender: TObject); begin AboutBox.Show; end; procedure TForm1.Exit1Click(Sender: TObject); begin Close; end; { tInData } procedure TForm1.FormResize(Sender: TObject); begin ListBox1.Width := Width - ListBox1.Left - 10; Image1.Left := (Width - Image1.Width) div 2; //Label14.Caption := IntToStr( Width ); { Label14.Top := ClientHeight - Label14.Height - 5; Label14.Left := ClientWidth - Label14.Width - 5; } bevel1.width:=form1.clientwidth; // Label11.Caption := IntToStr(Height) + ' ' + IntToStr(Width); end; procedure TForm1.Timer1Timer(Sender: TObject); Var S : String; I : Integer; begin // S := ''; //450 width is no space, 4 pixels per space If Neg Then Begin K := K - 1; K := K - (Width-450) div 128; End Else Begin k := k+1; K := K + (Width-450) div 128; End; If Width < 4*k+450 Then Begin Neg := true; K := (width-450) div 4; end; If K < 0 Then Begin K := 0; Neg := false; End; Form1.Caption := Copy(BlankString,1,k) + Scroll; (* S := ''; // If Lead > 0 Then For I := 1 to Lead Do S := S + ' '; {For I := Start To Start+75-Lead Do If (I+lead) <= Length(Scroll) Then S := S + Scroll[i+lead] Else S := S + Scroll[i+lead-length(scroll)];} If Start >= Length(Scroll) Then Start := 1 Else Inc(Start); // Caption := ''; If Lead > 0 Then Begin Dec( Lead ); //for I := 1 to Lead Do Caption := Caption + ' '; Caption := Copy(BlankString,1,Lead) + Copy(Scroll,1,50-Lead); If Lead = 0 Then End Else If Start+50 < Length(Scroll) Then Form1.Caption := copy(Scroll,Start,50) Else Form1.Caption := copy(Scroll,Start,Length(Scroll)-Start+1) + copy(Scroll,1,50-Length(Scroll)+Start); Application.Title := ''; For I := Start To Start+20 Do; // If*) Inc(Start); If Start > Length(Title) Then Start := 0; Application.Title := copy( Title,Start,Length(Title)-Start+1 ) + copy( Title,1,Start); end; procedure TForm1.Image2Click(Sender: TObject); begin ShellExecute(handle, nil, 'http://www.team188.com', nil, nil, SW_SHOWNORMAL); end; begin K := 0; FirstRun := True; Start := 1; Lead := 50; Link := 'http://www.team188.com'; end.