0 Members and 1 Guest are viewing this topic.

I never figured out how the heck to play minesweeper.

Yeah, I know why it's slow, and it's because my algorithm is pretty bad Here's my flood-fill code:Quote from: TI-BASIC{~1.01,~.01,.99,~1,1,~.99,.01,1.01->L3DelVar I{A+sub(B->L2Repeat I=dim(L2I+1->IL2(AnsF+pxl-Test(600fPart(Ans)+2,6iPart(Ans)+2->Fsum(seq(max(L1=L2(I)+L3(J)),J,1,8If AnsThen" "+sub("12345678",Ans,1)+" ElseFor(J,1,8)L2(I)+L3(JIf Ans>=0 and iPart(Ans)<C and |E2fPart(Ans)<D and prod(L2-AnsAns->L2(1+dim(L2End" EndText(600fPart(L2(I))+1,6iPart(L2(I))+2,AnsEndThe stuff between lines 11 and 15 are what's really slowing the thing down. It goes through the eight surrounding pixels and individually tests them to see if they're valid or not, and if so they get appended to the queue (L2). Because it has to do this for every element on the queue that doesn't have any mines surrounding it, blank squares take a while to show up.I tried to implement the third algorithm on the Wikipedia article, but since there are eight directions in Minesweeper and three classes of elements (blank, numbered, mine), it turned out to be even slower than the one I have.

{~1.01,~.01,.99,~1,1,~.99,.01,1.01->L3DelVar I{A+sub(B->L2Repeat I=dim(L2I+1->IL2(AnsF+pxl-Test(600fPart(Ans)+2,6iPart(Ans)+2->Fsum(seq(max(L1=L2(I)+L3(J)),J,1,8If AnsThen" "+sub("12345678",Ans,1)+" ElseFor(J,1,8)L2(I)+L3(JIf Ans>=0 and iPart(Ans)<C and |E2fPart(Ans)<D and prod(L2-AnsAns->L2(1+dim(L2End" EndText(600fPart(L2(I))+1,6iPart(L2(I))+2,AnsEnd

:A+sub(B:sum(seq(max(L₁=Ans+L₃(I)),I,1,8:If Ans:Then:Text(6B+1,6A+2," "+sub("12345678",Ans,1)+" :Else:Text(6B+1,6A+2," :DelVar I{A+sub(B➔L₂:Repeat I=dim(L₂:I+1➔I:For(J,1,8:L₂(I)+L₃(J:If Ans≥0 and iPart(Ans)<C and ᴇ2fPart(Ans)<D:Then:If pxl-Test(600fPart(Ans)+2,6iPart(Ans)+2:Then:sum(seq(max(L₁=L₂(I)+L₃(J)+L₃(K)),K,1,8:If Ans:Then:" "+sub("12345678",Ans,1)+" :Else:L₂(I)+L₃(J➔L₂(1+dim(L₂:" :End:Text(600fPart(L₂(I)+L₃(J))+1,6iPart(L₂(I)+L₃(J))+2,Ans:End:End:End:End:End