//EKON Code Review Project Game of Life GOL 4 {*************************************************************** * LED SONAR bITbox GOL * Project : Game of Life * Unit Name: #file:4.TXT423_game_of_life4.TXT * Purpose : Game of Life with StringGrid logic * Date : 18/02/2013 - 14:38:56, loc's=466, 4 intf * Release : check all conversion : open StringGrid : keyword check on all files with regEx : auto mode of GOL and first configuration * last changed 03.12.2013 - 11:03:2013, max, #locs=625 * #sign:4:59 max: APSN21: 03.12.2013 19:35:31 * #path\ples\E:\maxbox\maxbox3\examples\es\ * The simplest version of Conway's Life "game" * http://www.delphiforfun.org/Programs/Conways_Life.htm * add auto mode to run forever - the grand design ****************************************************************} //TODO: transfer the App to a LED Matrix on Arduino ex. I^2C Adafruit Shield!! Const AWORKPATH = 'D:\tzpas\review\'; FIREFOXPATH = 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'; AWORKPATHNET = '\\172.31.40.110\PasReview\codereview2013_sonar_start.TXT'; ALINK = 'http://www.delphiforfun.org/Programs/Conways_Life.htm'; FBOX = 4; GPIC = 'examples\citymax.bmp'; BOSIZE= 42; {height and width of board} STEPSTOP = 50; SAVENAME = 'golgraph'; Type TBoardsize = array [0..BOSIZE-1] of boolean; var frmMon: TForm; frmsg, golstg: TStringGrid; stat: TStatusbar; panstep: TPanel; Progress: TProgressBar; FAuto: boolean; Cntr: integer; Currentgrid, NextGrid, oldgrid: array[0..BOSIZE-1] of TBoardsize; procedure Tfrm_btnNew(Sender: TObject); forward; //ReSetFirstForm procedure openSonarWebStart(aport: string); var idHTTP: TIDHTTP; S_SonarServer: boolean; begin idHTTP:= TIdHTTP.create(NIL) try //memo2.lines.text:= idhttp.get2('http://www.softwareschule.ch/maxbox.htm') if (isValidIP('127.0.0.1') and (S_SonarServer = true)) then //memo2.lines.text:= //sonar default port:9000 idhttp.get2('http://localhost:'+aport); //idhttp.get2('http://www.softwareschule.ch') ShellExecute3('http://127.0.0.1:'+aport+'/dashboard','',seCMDOPen) finally idHTTP.Free S_SonarServer:= false; //maxform1.color:= clyellow; end; end; function Head(Str: string; SubStr: string; var TailStr: string): string; var I: Integer; begin I:= Pos(SubStr, Str); if I = 0 then begin Result:= Str; TailStr:= ''; end else begin TailStr:= Str; Delete(TailStr, 1, I + Length(SubStr) - 1); Delete(Str, I, Length(Str)); Result:= Str; end; end; //****************************** GOL Begin ************************* function CountPrevNeighbors(const i,j:integer):integer; {local function to count the number of neighbors} var L,R,U,D:integer; {Left, Right, Up, Down offsets for neighbors} begin result:=0; if i>0 then L:=i-1 else L:= BOSIZE-1; {counters loop around as if the } if j>0 then U:=j-1 else U:= BOSIZE-1; {board is a closed torus (a doughnut)} if i3)) then begin {Rule 1} nextgrid[i][j]:=false; golstg.cells[i,j]:=''; end; end else {check dead cell} if n=3 then begin {Rule 2} Nextgrid[i][j]:=true; golstg.cells[i,j]:='1'; end; end; {make the new (next) grid the current grid} for i:=0 to BOSIZE-1 do for j:= 0 to BOSIZE-1 do Currentgrid[i][j]:=NextGrid[i][j]; end; Procedure TFrm_makestepback(Sender: TObject); var i,j:integer; {n is neighbor count} begin for i:=5 to BOSIZE-1 do for j:=1 to BOSIZE-1 do begin currentGrid[i][j]:= oldgrid[i][j]; if currentgrid[i][j]= true then golstg.cells[i,j]:= '1' else golstg.cells[i,j]:= ''; end; dec(Cntr); panstep.caption:= inttoStr(cntr)+' % step'; end; Procedure TFrm_makeloop(count: integer); var i: integer; begin FAuto:= true; for i:= 1 to count do Tfrm_makestep; end; {************** Event Handlers ******************************************} procedure Tfrm_btnClose(Sender: TObject); begin stat.SimpleText:= 'Closed Clicked Event'; frmMon.Close; Screen.Cursor:= crDefault; end; procedure CloseHandler(Sender: TObject; var action: TCloseAction); begin //if MessageDlg('Wanna Leave?',mtConfirmation,[mbYes, mbNo],0)= mrYes then begin action:= caFree; writeln('Free Game and Closer test finished'); //Action:= caNone; end; {************** StartBtnClick ***********} procedure Tfrm_StartBtn(Sender: TObject); begin Tfrm_makestep; TBitBtn(sender).caption:= 'Step by GOL'; end; {************** StartBtnNext ***********} procedure Tfrm_StartBtnNext(Sender: TObject); //event driven interrupt begin FAuto:= NOT FAuto; if FAuto then begin TBitBtn(sender).caption:= 'Stop' TBitBtn(sender).glyph.LoadFromRes(getHINSTANCE,'CL_MPSTOP'); if FAuto then begin writeln('game of life demo go forever mode...'); repeat Tfrm_makestep; Sleep(STEPSTOP); //application.ProcessMessages; in main -->ProcessmessagesON; until NOT FAuto; end; end else begin TBitBtn(sender).caption:= 'Go Loop' TBitBtn(sender).glyph.LoadFromRes(getHINSTANCE,'CL_MPNEXT'); writeln('GOL demo loop stopped'); end; end; {************ StringGrid1Click ***********} procedure Tfrm_StringGrid1Click(Sender: TObject); {Set up a board, switch state of clicked cell} begin with golstg do if cells[col,row]='' then begin {make "live" } cells[col,row]:='1'; currentgrid[col][row]:=true; writeln(inttostr(col)+' pos: '+ inttostr(row)); end else begin {make "not alive"} cells[col,row]:=''; currentgrid[col][row]:=false; end; end; {************ StringgridDrawCell **************} procedure Tfrm_StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); {OnDrawCell exit updates the board image cell by cell as it is drawn } begin with golstg do begin if cells[acol,arow]<>'' then canvas.brush.color:=clred else canvas.brush.color:= clwhite; canvas.fillrect(rect); end; //writeln('this is draw '+inttostr(acol)); //@debug end; procedure Tfrm_StaticText1Click(Sender: TObject); begin {link to delphiforrun when text is clicked} //Showmessage('winExecAndWait(Exepath+''firstdemo.txt'',1)'); if (GetHostByName('www.ask.com')) > '0' then ExecuteCommand('http://www.delphiforfun.org/Programs/Conways_Life.htm','') else searchAndOpenDoc(ExePath+'\docs\maxboxnews.htm'); Voice('Welcome to max box 3.9 and game of life') end; {************** FormActivate ***********} procedure Tfrm_FormActivate(Sender: TObject); var i,j:integer; begin {Initialize the active grid} for i:=0 to high(Currentgrid) do for j:=0 to high(Currentgrid) do Currentgrid[i][j]:= false; Screen.Cursor:= crHandPoint; FAuto:= false; Cntr:= 0; end; {************** New Game Reset ***********} procedure Tfrm_btnNew(Sender: TObject); var i,j:integer; begin {Initialize grid and vector} for i:=0 to high(Currentgrid) do for j:=0 to high(Currentgrid) do begin Currentgrid[i][j]:= false; golstg.cells[i+5,j+1]:= ''; end; FAuto:= false; cntr:= 0; end; {************** Game Graph Save ***********} procedure Tfrm_btnSave(Sender: TObject); begin saveCanvas2(golstg.canvas,exepath+SAVENAME+inttostr(cntr)+'.png'); SearchAndOpenDoc(ExePath+SAVENAME+inttostr(cntr)+'.png'); stat.simpletext:= datetimetostr(now)+' Graph saved: '+ExePath+SAVENAME+itoa(cntr)+'.png'; writeln('Graph saved at '+ExePath+SAVENAME+itoa(cntr)+'.png'); end; //THE GRAND DESIGN procedure Tfrm_btnLoad(Sender: TObject); begin {proof of concept stephen hawking the grand design} stat.simpletext:= datetimetostr(now) +' Runs the Grand Design Book Demo...'; ShowmessageBig(' Runs the Grand Design Book Demo...till step 115'); Tfrm_btnNew(Self); with golstg do begin cells[2,8]:= '1' {make "first form" } cells[2,9]:= '1' cells[3,9]:= '1' cells[3,8]:= '1' cells[13,9]:= '1' cells[13,8]:= '1' cells[13,7]:= '1' cells[14,10]:= '1' cells[15,11]:= '1' cells[16,10]:= '1' cells[14,6]:= '1' cells[15,5]:= '1' cells[16,6]:= '1' cells[17,7]:= '1' cells[17,8]:= '1' cells[17,9]:= '1' cells[18,9]:= '1' cells[18,8]:= '1' cells[18,7]:= '1' cells[23,7]:= '1' cells[24,7]:= '1' cells[25,7]:= '1' cells[26,7]:= '1' cells[24,8]:= '1' cells[25,8]:= '1' cells[26,8]:= '1' cells[27,8]:= '1' cells[27,9]:= '1' cells[23,6]:= '1' cells[23,5]:= '1' cells[24,5]:= '1' cells[25,5]:= '1' cells[26,5]:= '1' cells[26,6]:= '1' cells[24,4]:= '1' cells[25,4]:= '1' cells[26,4]:= '1' cells[27,4]:= '1' cells[27,3]:= '1' cells[32,4]:= '1' cells[32,5]:= '1' cells[36,6]:= '1' cells[36,7]:= '1' cells[37,7]:= '1' cells[37,6]:= '1' currentgrid[2][8]:= true {make "first form" } currentgrid[2][9]:= true currentgrid[3][9]:= true currentgrid[3][8]:= true currentgrid[13][9]:= true currentgrid[13][8]:= true currentgrid[13][7]:= true currentgrid[14][10]:= true currentgrid[15][11]:= true currentgrid[16][10]:= true currentgrid[14][6]:= true currentgrid[15][5]:= true currentgrid[16][6]:= true currentgrid[17][7]:= true currentgrid[17][8]:= true currentgrid[17][9]:= true currentgrid[18][9]:= true currentgrid[18][8]:= true currentgrid[18][7]:= true currentgrid[23][7]:= true currentgrid[24][7]:= true currentgrid[25][7]:= true currentgrid[26][7]:= true currentgrid[24][8]:= true currentgrid[25][8]:= true currentgrid[26][8]:= true currentgrid[27][8]:= true currentgrid[27][9]:= true currentgrid[23][6]:= true currentgrid[23][5]:= true currentgrid[24][5]:= true currentgrid[25][5]:= true currentgrid[26][5]:= true currentgrid[26][6]:= true currentgrid[24][4]:= true currentgrid[25][4]:= true currentgrid[26][4]:= true currentgrid[27][4]:= true currentgrid[27][3]:= true currentgrid[32][4]:= true currentgrid[32][5]:= true currentgrid[36][6]:= true currentgrid[36][7]:= true currentgrid[37][7]:= true currentgrid[37][6]:= true TFrm_makeloop(115); stat.simpletext:= datetimetostr(now) +' End of the Grand Design Book Demo...'; end; end; {************** FormActivate ***********} procedure SetFirstForm; begin {Initialize the active grid} with golstg do begin cells[20,15]:= '1' {make "first form" } cells[19,15]:= '1' cells[18,15]:= '1' cells[18,16]:= '1' cells[18,17]:= '1' cells[19,14]:= '1' //cells[col,row]:='1'; currentgrid[20][15]:=true; currentgrid[19][15]:=true; currentgrid[18][15]:=true; currentgrid[18][16]:=true; currentgrid[18][17]:=true; currentgrid[19][14]:=true; end; //repaint; end; {************** Form Builder ***********} procedure InitCreateForms; var panImg, panR: TPanel; bmp: TBitmap; begin // seq --> panel-image-drawgrid-bitmap //for i:= 1 to QB+1 do bArr[i]:= TBitMap.Create; //HideGridCursor(frmsg); frmMon:= TForm.Create(self); with frmMon do begin //FormStyle := fsStayOnTop; Position:= poScreenCenter; BorderIcons:= [biSystemMenu, biMinimize]; BorderStyle:= bsSingle; PixelsPerInch:= 96; Caption:= 'Conway'#39's Game of Life - V1.4 by maXbox'; color:= clBtnFace; color:= clblack; width:= 1000; height:= 660; Show; Canvas.stretchDraw(Rect(0,0,width,height), getbitmap(Exepath+GPIC)); onClose:= @CloseHandler; end; Tfrm_FormActivate(self); panImg:= TPanel.Create(frmMon) with panImg do begin parent:= frmMon; setBounds(15,8,740,570) BevelOuter:= bvLowered //DoubleBuffered:= true; end; PanR:= TPanel.create(frmMon); with PanR do begin parent:= frmMon; setBounds(772,8,155,570); BevelOuter:= bvLowered TabOrder:= 1 end; with TBitBtn.Create(frmMon) do begin Parent:= frmMon; SetBounds(788,30,121,30) //30 Caption:= '&Load/Run GOL' Hint:= 'Loads the GRAND DESIGN and runs your own game of life!'; ShowHint:= true; glyph.LoadFromRes(getHINSTANCE,'CL_MPEJECT'); OnClick:= @Tfrm_btnLoad; end; with TBitBtn.Create(frmMon) do begin Parent:= frmMon; SetBounds(788,80,121,30) //68 glyph.LoadFromRes(getHINSTANCE,'CL_MPSTEP'); Caption:= 'Start GOL' //Enabled:= False OnClick:= @Tfrm_StartBtn; end; with TBitBtn.Create(frmMon) do begin Parent:= frmMon; SetBounds(788,160,121,30) //68 glyph.LoadFromRes(getHINSTANCE,'CL_MPPLAY'); Caption:= '&Run Loop' Hint:= 'Let it run till the end of life!'; ShowHint:= true; //Enabled:= False OnClick:= @Tfrm_StartBtnNext; end; with TBitBtn.Create(frmMon) do begin Parent:= frmMon; SetBounds(788,120,121,30) //68 glyph.LoadFromRes(getHINSTANCE,'CL_MPPREV'); Caption:= 'Run Back' //Enabled:= False //TabOrder = 7 OnClick:= @Tfrm_makestepback; end; with TBitBtn.Create(frmMon) do begin Parent:= frmMon; SetBounds(788,480,121,30) glyph.LoadFromRes(getHINSTANCE,'CL_MPSTOP'); Caption:= 'Close' OnClick:= @Tfrm_btnClose end; with TBitBtn.Create(frmMon) do begin Parent:= frmMon; SetBounds(788,230,121,30) glyph.LoadFromRes(getHINSTANCE,'CL_MPPAUSE'); Caption:= 'New Evolution' Hint:= 'just for a New Game'; ShowHint:= true; OnClick:= @Tfrm_btnNew; end; with TBitBtn.Create(frmMon) do begin Parent:= frmMon; SetBounds(788,270,121,30) glyph.LoadFromRes(getHINSTANCE,'TCHART16'); Caption:= 'Save Graph' OnClick:= @Tfrm_btnSave; end; panstep:= TPanel.Create(frmMon); with panstep do begin Parent:= frmMon; SetBounds(788,420,121,25) BevelOuter:= bvLowered font.color:= clblue; color:= clyellow; Caption:= '0 steps' //Color:= clyellow;//$30809000; //Color:= 8404992 end; frmsg:= TStringGrid.Create(frmMon); with frmsg do begin //SetBounds(512,320,79,79) parent:= panR; Left:= 35; Top:= 320; Width:= 79; Height:= 79; ColCount:= 4 DefaultColWidth:= 18 DefaultRowHeight:= 18 FixedCols:= 0 RowCount:= 4 FixedRows:= 0 end; golstg:= TStringGrid.Create(frmMon); with golstg do begin Left:= 25; Top:= 20; Width:= 719; Height:= 538; parent:= frmMon; parentcolor:= false; Anchors:= [akLeft,akTop,akRight,akBottom] ColCount:= 42 DefaultColWidth:= 16 DefaultRowHeight:= 16 DefaultDrawing:= False FixedCols:= 0 RowCount:= 42 FixedRows:= 0 color:= clblue; OnClick:= @Tfrm_StringGrid1Click; OnDrawCell:= @Tfrm_StringGrid1DrawCell; end; SetFirstForm; Bmp:= TBitmap.Create; try Bmp.LoadFromFile(Exepath+'examples\mxlogoball.bmp'); golstg.Canvas.Draw(18,18, Bmp); finally Bmp.Free; end; stat:= TStatusbar.Create(FrmMon); with Stat do begin parent:= frmMon; stat.SimplePanel:= true; simpletext:= datetimetostr(now) +' Set a few boxes in the grid to start...'; end; with TStaticText.create(frmmon) do begin //setBounds(10,100,100,30); Cursor:= crHandPoint; parent:= panImg; //frmmon; Align:= alBottom; parentcolor:= false; //Color:= clRed; Caption:= ' Game of Life GOL © 1970, by Conway and maXbox Copyleft'; //Font.Charset:= DEFAULT_CHARSET Font.Color:= clBlue; Font.Height:= 12 Font.Name:= 'MS Arial' Font.Style:= [fsUnderline] //Show; OnClick:= @Tfrm_StaticText1Click; end; end; procedure testDecimal; // collection-list-vector-stack (list, map, set) var tf: extended; begin tf:= 0.99999999999999999; tf:= 10.0 * tf; printF('more prec %.18f ',[tf]); writeln(floattostr(0.5 * log2(2))); maxCalcF('1/2 * ln(2)/ln(2) + 1/2 * ln(2)/ln(2)'); maxCalcF('3/4 * ln(4/3)/ln(2) + 1/4 * ln(4)/ln(2)'); //dice 1/4 + 3/4 writeln(floattoStr(tf)) writeln('total qual: '+floatToStr(maxCalc('100 - (225/6790*100)'))); end; procedure listAllWinProcesses; var myproclist: TStringlist; i: integer; begin myProclist:= TStringList.Create; GetApplicationsRunning(myProclist); //Jedi for i:= 1 to myProclist.count - 1 do Writeln(inttoStr(i)+' '+myProclist[i]); myProclist.Free; end; Begin //GOL main app ProcessmessagesON; // to interrupt the loop if iswin64 then writeln(' is win64 machine: '+ gethostname); //listAllWinProcesses; InitCreateForms; // ant maven jenkins reinstall Testdecimal; //TFrm_makeloop(68); //test 68 End. http://math.uww.edu/~harrisb/courses/cs171/sets.htm http://www.delphiforfun.org/Programs/Conways_Life.htm unit U_ConwaysLife1; {Copyright © 2007, Gary Darby, www.DelphiForFun.org This program may be used or modified for any non-commercial purpose so long as this original notice remains in place. All other rights are reserved } {The simplest version of Conway's Life "game"} interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls, ExtCtrls, shellAPI; const boardsize=25; {The height and width of the board} type TForm1 = class(TForm) StringGrid1: TStringGrid; StartBtn: TButton; Memo1: TMemo; StaticText1: TStaticText; procedure StringGrid1Click(Sender: TObject); procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure StartBtnClick(Sender: TObject); procedure FormActivate(Sender: TObject); procedure StaticText1Click(Sender: TObject); public {CurrentGrid and NextGrid are 2-dimensional arrays defining two boards, the current and next generations} Currentgrid,NextGrid:array [0..boardsize-1, 0..boardsize-1] of boolean; Procedure makestep; {Procedure to generate the next generation grid} end; var Form1: TForm1; implementation //{$R *.DFM} {************ StringGrid1Click ***********} procedure TForm1.StringGrid1Click(Sender: TObject); {Set up a board, switch state of clicked cell} begin with stringgrid1 do if cells[col,row]='' then begin {make "live" } cells[col,row]:='1'; currentgrid[col,row]:=true; end else begin {make "dead"} cells[col,row]:=''; currentgrid[col,row]:=false; end; end; {************ StringgridDrawCell **************} procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); {OnDrawCell exit updates the board image cell by cell as it is drawn } begin with stringgrid1,canvas do begin if cells[acol,arow]<>'' then brush.color:=clblack else brush.color:=clwhite; fillrect(rect); end; end; {************** MakeStep *************} Procedure TForm1.makestep; {The meat of the program - create next generation, return true if pattern changed} function CountPrevNeighbors(const i,j:integer):integer; {local function to count the number of neighbors} var L,R,U,D:integer; {Left, Right, Up, Down offsets for neighbors} begin result:=0; if i>0 then L:=i-1 else L:=boardsize-1; {counters loop around as if the } if j>0 then U:=j-1 else U:=boardsize-1; {board were a closed torus (a doughnut)} if i3)) then {Rule 1} begin nextgrid[i,j]:=false; stringgrid1.cells[i,j]:=''; end; end else {check dead cell} if n=3 then {Rule 2} begin Nextgrid[i,j]:=true; stringgrid1.cells[i,j]:='1'; end; end; {make the new (next) grid the current grid} for i:=0 to boardsize-1 do for j:= 0 to boardsize-1 do Currentgrid[i,j]:=NextGrid[i,j]; end; {************** FormActivate ***********} procedure TForm1.FormActivate(Sender: TObject); var i,j:integer; begin {Initialize the active grid} for i:=0 to high(Currentgrid) do for j:=0 to high(Currentgrid) do Currentgrid[i,j]:=false; end; {************** StartBtnClick ***********} procedure TForm1.StartBtnClick(Sender: TObject); begin makestep; end; procedure TForm1.StaticText1Click(Sender: TObject); begin {link to delphiforfun when text is clicked} ShellExecute(Handle, 'open', 'http://www.delphiforfun.org/', nil, nil, SW_SHOWNORMAL) ; end; end. object Form1: TForm1 Left = 192 Top = 122 Width = 930 Height = 600 Caption = 'Conway'#39's Game of Life V1.0' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False OnActivate = FormActivate PixelsPerInch = 96 TextHeight = 13 object StringGrid1: TStringGrid Left = 448 Top = 8 Width = 433 Height = 433 Anchors = [akLeft, akTop, akRight, akBottom] ColCount = 25 DefaultColWidth = 16 DefaultRowHeight = 16 DefaultDrawing = False FixedCols = 0 RowCount = 25 FixedRows = 0 TabOrder = 0 OnClick = StringGrid1Click OnDrawCell = StringGrid1DrawCell end object StartBtn: TButton Left = 456 Top = 456 Width = 129 Height = 25 Caption = 'Step' TabOrder = 1 OnClick = StartBtnClick end object Memo1: TMemo Left = 24 Top = 24 Width = 409 Height = 385 Lines.Strings = ( 'This is the simplest version of Conway'#39's Game of Life that I cou' + 'ld come up with.' '' 'From the Wikipedia entry for Conway'#39's Life":' '--------------------------' 'The Game of Life is a cellular automaton devised by the British ' + 'mathematician John ' 'Horton Conway in 1970. It is the best-known example of a cellula' + 'r automaton.' '' 'The "game" is actually a zero-player game, meaning that its evol' + 'ution is determined ' 'by its initial state, needing no input from human players. One i' + 'nteracts with the Game ' 'of Life by creating an initial configuration and observing how i' + 't evolves.' '--------------------------' '' 'From each board there are two basic rules for forming the next g' + 'eneration:' '' 'For each square, count the "neighbors", number of adjoining sqau' + 'res (in all 8 ' 'directions) that are occupied.' '' 'Rule 1: If an occupied square has less than 2 or more than 3 nei' + 'ghbors, it "dies" (the ' 'square becomes unoccupied).' '' 'Rule 2: if an unoccupied square has exactly 3 neighbors, a "birt' + 'h" occurs (it becomes ' 'occupied).' '' 'Click a square to switch its state. Click the "Step" button to ' + 'see the next generation.' '' '') TabOrder = 2 end object StaticText1: TStaticText Left = 0 Top = 540 Width = 914 Height = 24 Cursor = crHandPoint Align = alBottom Alignment = taCenter Caption = 'Copyright © 2007, Gary Darby, www.DelphiForFun.org' Font.Charset = DEFAULT_CHARSET Font.Color = clBlue Font.Height = -16 Font.Name = 'MS Sans Serif' Font.Style = [fsUnderline] ParentFont = False TabOrder = 3 OnClick = StaticText1Click end end Background & Techniques Every puzzle and game programmer's portfolio should include two standards, John Conway's Game of Life and Fractals, neither one of which currently appears here on DFF. Today's posting will fill one of those gaps. I decided to do it while searc Mathematician John Conway designed the game in 1970 based on two simple rules. The board is a rectangular grid of cells each of which is either occupied or empty. After setting an initial starting set of occupied cells, we move to the next gen Rule 1: If an occupied cell has two or three neighbors, it is happy and remains unchanged. Otherwise it is too lonely or too crowded and dies (cell becomes unoccupied). Rule 2: If an empty cell has exactly 3 neighbors, a birth occurs and the cell becomes occupied. Don't ask me what kind of life form requires 3 parents for a birth - I didn't make the rules! That's it. Search the web for Conway's Life and you'll find many, many pages of sample patterns, an entire lexicography of named terms for patterns and behaviors, and a number of other programs including one written in Delphi which handles boar The simple version, V1, changes the state of each cell that gets a mouse click for setting up a pattern. The Step button creates the next generation. The board is 25x25 cells. That's about it. Version 2 adds the ability to load and save pattern files, automatically moves from generation to generation at a user specified rate, and allows board to be set to 25x25, 50x50, or 100x100 cells. I have included a few sample pattern files a For either version, patterns that expand beyond the limits of the grid "wrap around" as if the first column was to the right of the last column and the top row was below the bottom row. Topologically its as if the board was printed on a cylind Non-programmers are welcome to read on, but may want to skip to the bottom of this page to download executable version of Version 2 of the program. Notes for Programmers Version 1 uses two 2-dimensional arrays of Boolean (true/false) variables, CurrentGrid and NextGrid, to hold the current and the next generation configurations, (True for occupied, False for empty). The new generation depends on the old generati MakeStep contains about half of the 100 user written instructions in the program. The other routines are event exits which are called automatically when certain events occur: bullet Form1Activate is an OnActivate exit which initializes CurrentGrid with False values at startup time. bullet StringGrid1DrawCell is an OnDrawCell exit for Stringgrid1 which is called when windows wants to write each cell. It fills the cell with a black or white rectangle depending on whether cell text is empty or contains a value. bullet StringGrid1Click responds to user clicks on Sringgrid1 (an OnClick event exit) to change the cell value from empty to '1' or from '1' to empty. Process ID: 4424 MemoryLoad: 36% used Free Mem: -1614880MB 11.2.2013 Source has been set in SVN Turtoise 31301 add file, 1.525 GByte, transfer 7 min. at revision 211 Total Files Listed: 23205 File(s) 3'519'959'913 bytes 24287 Dir(s) 53'073'997'824 bytes free Set up for SONAR Java, C#, PL/SQL Link StartSonar - Shortcut D:\software\sonar-3.4.1\bin\windows-x86-32\StartSonar.bat add rule checked exceptions add path to sonar runner in environment variables //C:\maXbox\sonar-3.4.1\bin\windows-x86-64\StartSonar.bat C:\maXbox\sonar-3.4.1\sonar_runner_home\sonar-runner.bat http://www.ifunky.net/Blog/post/Install-and-Configure-Sonar-on-Windows-2008.aspx I'm currently looking at integrating Sonar into our build environment which intially didn't go too well interms of installation so I thought I'd document what I did and what was required for future reference. In this first part I will show you h PREREQUISITES - VERY IMPORTANT! Download Java JDK, it's works with 1.5+ but I installed 1.7. http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html INSTALL SONAR Download Sonar: http://sonar.codehaus.org/downloads/ Extract to a directory i.e. c:\Sonar Run \bin\windows-x86-32\StartSonar.bat or \bin\windows-x86-64\StartSonar.bat depending on your OS Navigate to http://localhost:9000 to view the default console At this point Sonar is configured to use the default database. CONFIGURE SONAR WITH VS2010 Download the "C# Plugins Ecosystem" - Version 1.0 http://docs.codehaus.org/download/attachments/201228384/CSharpPluginsEcosystem-1.0-RC2.zip (Lastest version can be found on the top right here: http://docs.codehaus.org/display/SONAR/C-Sharp+Plugins+Ecosystem) Extract to the plugins directory C:\Sonar\sonar-2.9\extensions\plugins INSTALL JAVA RUNNER Rather than using Mavern it's much easier to to use the Java Runner to kick off Sonar. Download the Java Runner: http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+Runner#AnalysewithasimpleJavaRunner-Installation Extract to dir i.e. c:\Sonar\sonar-runner-1.1 Modify C:\Sonar\sonar-runner-1.1\conf\sonar-runner.properties to enble the default site and Derby DB My modifed file looks like this: #----- Default directory layout sources=src/main/java tests=src/test/java binaries=target/classes sonar.sourceEncoding=UTF-8 #----- Default Sonar server sonar.host.url=http://localhost:9000 #----- Global database settings sonar.jdbc.username=sonar sonar.jdbc.password=sonar Make sure you have the following environment varaibles: JAVA_HOME = C:\Program Files\Java\jdk1.6.0_23 SONAR_RUNNER_HOME = C:\Sonar\sonar-runner-1.1 Add the sonar runner bin path to your PATH environment (for my install this is C:\Sonar\sonar-runner-1.1\bin) There are two ways to tell Sonar where your .sln file is located a) You can create a sonar-project.properties file in the same directory as your solution file, Sonar will find it OR b) Create a sonar-project.properties file but use the sonar.dotnet.visualstudio.solution.file property to specify the path (this is my prefered option) Create a file called "sonar-project.properties" as descrivbed in the above step (literally as it is don't replace project with your project name!) placing it Here's my sample properties file located on the root of my application: AppName ---->BuildTools ---->Lib ---->src --------->AppName.sln build.proj sonar-project.properties # Project identification sonar.projectKey=DMG:AppName sonar.projectVersion=1.0-SNAPSHOT sonar.projectName=AppName # Info required for Sonar sources=. sonar.language=cs #Core C# Settings sonar.dotnet.visualstudio.solution.file=\src\\AppName.sln #Gendarme sonar.gendarme.assemblies=\build\\DmgTech*.* sonar.gendarme.mode=skip # Gallio sonar.gallio.mode=skip # FXCop sonar.fxcop.mode=skip #StyleCop sonar.stylecop.mode=skip To run Sonar-Runner against your project - Shell out to DOS - Change directory to the location of your "sonar-project.properties" file - Execute "sonar-runner" View your reports at http://localhost:9000 Troubleshooting If you receive something like: Fail to connect to database: undefined method `getActiveRecordDialectCode' for nil Check the JDK version you are running If you receive a maintenance warning then try http://localhost:9000\setup View the logs \logs\sonar.log If you receive the following error make sure the path to Java is in the environment path (I had to put C:\Program Files\Java\jdk1.7.0\bin). To test head to DOS and type java VirSCAN.org Scanned Report : Scanned time : 2013/12/03 17:09:41 (CET) Scanner results: 8% Scanner(s) (3/37) found malware! File Name : maxbox3.exe File Size : 15590400 byte File Type : PE32 executable for MS Windows (GUI) Intel 80386 32-bit MD5 : d5cf2271722e8affd4819db5a3db9f3a SHA1 : fff0205def64c8f7f714c1daf382f2e12522bc83 Online report : http://r.virscan.org/8ac46c4aed95ca924139551762e75977 Scanner Engine Ver Sig Ver Sig Date Time Scan result a-squared 5.1.0.4 00050000000000 0005-00-00 1.92 - AhnLab V3 2013.05.28.00 2013.05.28 2013-05-28 6.93 - AntiVir 8.2.10.202 7.11.50.58 2012-11-16 10.64 - Antiy 2.0.18 2.0.18. 0002-18-00 0.22 - Arcavir 2011 201311271241 2013-11-27 8.55 - Authentium 5.3.14 5.3.14 0005-14-00 1.24 W32/SurfAccuracy.A.gen!Eldorado (Possible) AVAST! 4.7.4 131202-2 2013-12-02 1.73 - AVG 10.0.1405 2109/6386 2013-12-02 0.27 - BitDefender 7.90123.105350167.51915 2013-12-04 6.42 - Comodo 5.1 15023 2013-10-10 2.65 - CP Secure 1.3.0.5 2013.10.19 2013-10-19 0.20 - Dr.Web 5.0.2.3300 2013.12.04 2013-12-04 25.16 - F-Secure 7.02.73807 2013.12.03.03 2013-12-03 3.88 - Fortinet 4.3.392 16.549 2013-10-12 0.14 - GData 22.12903 20131001 2013-10-01 8.93 - ViRobot 20131011 2013.10.11 2013-10-11 0.43 - Ikarus T3.1.32.10.0 ..1.32.10.0. --1.32.10.0 3.82 - JiangMin 16.0.100 2013.02.09 2013-02-09 30.56 - Kaspersky 5.5.10 2013.07.09 2013-07-09 0.00 - KingSoft 2009.2.5.15 2013.11.4.9 2013-11-04 5.51 - McAfee 5400.1158 5805 2009-11-17 4.95 - Microsoft 1.9901 2013.10.09 2013-10-09 9.77 - NOD32 3.0.21 9124 2013-12-03 2.37 - Norman 6.8.3 201305031020 2013-05-03 0.21 - Panda 9.05.01 2013.01.22 2013-01-22 16.64 - Trend Micro 9.500-1005 10.450.03 2013-12-02 0.56 - Quick Heal 11.00 2013.11.05 2013-11-05 6.21 - Rising 20.0 24.46.00.03 2013-01-21 7.26 - Sophos 3.16.1 4.62 2013-12-03 3.20 - Sunbelt 3.9.2570.2 22124 2013-10-05 0.26 - Symantec 1.3.0.24 20130909.001 2013-09-09 1.74 - nProtect 20131011.03 15523128 2013-10-11 2.74 - The Hacker 6.8.0.5 v00346 2013-10-10 0.81 - VBA32 3.12.24.3 20131202.0734 2013-12-02 4.02 - VirusBuster 5.0.27.0 12.13.1.0/3039193 2010-02-05 24.05 - When Adware.SurfAccuracy is executed, it performs the following actions: Creates the following files: %ProgramFiles%\sacc\sacc.cfg %ProgramFiles%\sacc\sacc.exe Note: %ProgramFiles% is a variable that refers to the program files folder. By default, this is C:\Program Files. Adds the value: "SACC" = "%ProgramFiles%\sacc\sacc.exe" to the registry subkey: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run so that the risk runs every time Windows starts. Creates the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\SAcc Records keywords typed in popular websearch engines like google and sends this information to a server belonging to the surfaccuracy.com domain. scanner of stephen hawking example the grand design { 19 pos: 16 2 pos: 8 2 pos: 9 3 pos: 9 3 pos: 8 13 pos: 9 13 pos: 8 13 pos: 7 14 pos: 10 15 pos: 11 16 pos: 10 14 pos: 6 15 pos: 5 16 pos: 6 17 pos: 7 17 pos: 8 17 pos: 9 18 pos: 9 18 pos: 8 18 pos: 7 23 pos: 7 24 pos: 7 25 pos: 7 26 pos: 7 24 pos: 8 25 pos: 8 26 pos: 8 27 pos: 8 27 pos: 9 23 pos: 6 23 pos: 5 24 pos: 5 25 pos: 5 26 pos: 5 26 pos: 6 24 pos: 4 25 pos: 4 26 pos: 4 27 pos: 4 27 pos: 3 32 pos: 4 32 pos: 5 36 pos: 6 36 pos: 7 37 pos: 7 37 pos: 6 }