June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,56 +1,104 @@
|
|||
10 PAPER 6: CLS
|
||||
20 DIM n$(20,30)
|
||||
30 LET init=.5
|
||||
40 LET f=.02
|
||||
50 LET p=.05
|
||||
60 PAPER 0
|
||||
70 FOR i=0 TO 31
|
||||
80 PRINT AT 0,i;" "
|
||||
90 PRINT AT 21,i;" "
|
||||
100 NEXT i
|
||||
110 FOR i=0 TO 21
|
||||
120 PRINT AT i,0;" "
|
||||
130 PRINT AT i,31;" "
|
||||
140 NEXT i
|
||||
150 INK 7
|
||||
160 PRINT AT 0,1;"FOREST FIRE for Rosetta Code"
|
||||
170 LET generation=0
|
||||
180 PRINT AT 21,1;"Generation 0"
|
||||
190 LET trees=0
|
||||
200 PRINT AT 21,22;"Cover"
|
||||
210 FOR i=1 TO 20
|
||||
220 FOR j=1 TO 30
|
||||
230 IF RND<init THEN PAPER 4: INK 7: PRINT AT i,j;"T": LET trees=trees+1
|
||||
240 NEXT j
|
||||
250 NEXT i
|
||||
260 LET generation=generation+1
|
||||
270 INK 7
|
||||
280 PAPER 0
|
||||
290 PRINT AT 21,12;generation
|
||||
300 PRINT AT 21,28;" "
|
||||
310 PRINT AT 21,28;INT (trees/6+.5);"%"
|
||||
320 FOR i=1 TO 20
|
||||
330 FOR j=1 TO 30
|
||||
340 LET n$(i,j)=SCREEN$ (i,j)
|
||||
350 IF SCREEN$ (i,j)="B" THEN LET n$(i,j)=" ": GO TO 450
|
||||
360 IF SCREEN$ (i,j)="T" THEN GO TO 390
|
||||
370 IF RND<=p THEN LET n$(i,j)="T"
|
||||
380 GO TO 450
|
||||
390 FOR k=i-1 TO i+1
|
||||
400 FOR l=j-1 TO j+1
|
||||
410 IF SCREEN$ (k,l)="B" THEN LET n$(i,j)="B": LET k=i+2: LET l=j+2
|
||||
420 NEXT l
|
||||
430 NEXT k
|
||||
440 IF RND<=f THEN LET n$(i,j)="B"
|
||||
450 NEXT j
|
||||
460 NEXT i
|
||||
470 LET trees=0
|
||||
480 FOR i=1 TO 20
|
||||
490 FOR j=1 TO 30
|
||||
500 IF n$(i,j)="T" THEN INK 7: PAPER 4: PRINT AT i,j;"T": LET trees=trees+1: GO TO 540
|
||||
510 IF n$(i,j)="B" THEN INK 6: PAPER 2: PRINT AT i,j;"B": GO TO 540
|
||||
520 PAPER 6
|
||||
530 PRINT AT i,j;" "
|
||||
540 NEXT j
|
||||
550 NEXT i
|
||||
560 GO TO 260
|
||||
Public Class ForestFire
|
||||
Private _forest(,) As ForestState
|
||||
Private _isBuilding As Boolean
|
||||
Private _bm As Bitmap
|
||||
Private _gen As Integer
|
||||
Private _sw As Stopwatch
|
||||
|
||||
Private Const _treeStart As Double = 0.5
|
||||
Private Const _f As Double = 0.00001
|
||||
Private Const _p As Double = 0.001
|
||||
|
||||
Private Const _winWidth As Integer = 300
|
||||
Private Const _winHeight As Integer = 300
|
||||
|
||||
Private Enum ForestState
|
||||
Empty
|
||||
Burning
|
||||
Tree
|
||||
End Enum
|
||||
|
||||
Private Sub ForestFire_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
Me.ClientSize = New Size(_winWidth, _winHeight)
|
||||
ReDim _forest(_winWidth, _winHeight)
|
||||
|
||||
Dim rnd As New Random()
|
||||
For i As Integer = 0 To _winHeight - 1
|
||||
For j As Integer = 0 To _winWidth - 1
|
||||
_forest(j, i) = IIf(rnd.NextDouble <= _treeStart, ForestState.Tree, ForestState.Empty)
|
||||
Next
|
||||
Next
|
||||
|
||||
_sw = New Stopwatch
|
||||
_sw.Start()
|
||||
DrawForest()
|
||||
Timer1.Start()
|
||||
End Sub
|
||||
|
||||
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
|
||||
If _isBuilding Then Exit Sub
|
||||
|
||||
_isBuilding = True
|
||||
GetNextGeneration()
|
||||
|
||||
DrawForest()
|
||||
_isBuilding = False
|
||||
End Sub
|
||||
|
||||
Private Sub GetNextGeneration()
|
||||
Dim forestCache(_winWidth, _winHeight) As ForestState
|
||||
Dim rnd As New Random()
|
||||
|
||||
For i As Integer = 0 To _winHeight - 1
|
||||
For j As Integer = 0 To _winWidth - 1
|
||||
Select Case _forest(j, i)
|
||||
Case ForestState.Tree
|
||||
If forestCache(j, i) <> ForestState.Burning Then
|
||||
forestCache(j, i) = IIf(rnd.NextDouble <= _f, ForestState.Burning, ForestState.Tree)
|
||||
End If
|
||||
|
||||
Case ForestState.Burning
|
||||
For i2 As Integer = i - 1 To i + 1
|
||||
If i2 = -1 OrElse i2 >= _winHeight Then Continue For
|
||||
For j2 As Integer = j - 1 To j + 1
|
||||
If j2 = -1 OrElse i2 >= _winWidth Then Continue For
|
||||
If _forest(j2, i2) = ForestState.Tree Then forestCache(j2, i2) = ForestState.Burning
|
||||
Next
|
||||
Next
|
||||
forestCache(j, i) = ForestState.Empty
|
||||
|
||||
Case Else
|
||||
forestCache(j, i) = IIf(rnd.NextDouble <= _p, ForestState.Tree, ForestState.Empty)
|
||||
End Select
|
||||
Next
|
||||
Next
|
||||
|
||||
_forest = forestCache
|
||||
_gen += 1
|
||||
End Sub
|
||||
|
||||
Private Sub DrawForest()
|
||||
Dim bmCache As New Bitmap(_winWidth, _winHeight)
|
||||
|
||||
For i As Integer = 0 To _winHeight - 1
|
||||
For j As Integer = 0 To _winWidth - 1
|
||||
Select Case _forest(j, i)
|
||||
Case ForestState.Tree
|
||||
bmCache.SetPixel(j, i, Color.Green)
|
||||
|
||||
Case ForestState.Burning
|
||||
bmCache.SetPixel(j, i, Color.Red)
|
||||
End Select
|
||||
Next
|
||||
Next
|
||||
|
||||
_bm = bmCache
|
||||
Me.Refresh()
|
||||
End Sub
|
||||
|
||||
Private Sub ForestFire_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
|
||||
e.Graphics.DrawImage(_bm, 0, 0)
|
||||
|
||||
Me.Text = "Gen " & _gen.ToString() & " @ " & (_gen / (_sw.ElapsedMilliseconds / 1000)).ToString("F02") & " FPS: Forest Fire"
|
||||
End Sub
|
||||
End Class
|
||||
|
|
|
|||
56
Task/Forest-fire/BASIC/forest-fire-11.basic
Normal file
56
Task/Forest-fire/BASIC/forest-fire-11.basic
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
10 PAPER 6: CLS
|
||||
20 DIM n$(20,30)
|
||||
30 LET init=.5
|
||||
40 LET f=.02
|
||||
50 LET p=.05
|
||||
60 PAPER 0
|
||||
70 FOR i=0 TO 31
|
||||
80 PRINT AT 0,i;" "
|
||||
90 PRINT AT 21,i;" "
|
||||
100 NEXT i
|
||||
110 FOR i=0 TO 21
|
||||
120 PRINT AT i,0;" "
|
||||
130 PRINT AT i,31;" "
|
||||
140 NEXT i
|
||||
150 INK 7
|
||||
160 PRINT AT 0,1;"FOREST FIRE for Rosetta Code"
|
||||
170 LET generation=0
|
||||
180 PRINT AT 21,1;"Generation 0"
|
||||
190 LET trees=0
|
||||
200 PRINT AT 21,22;"Cover"
|
||||
210 FOR i=1 TO 20
|
||||
220 FOR j=1 TO 30
|
||||
230 IF RND<init THEN PAPER 4: INK 7: PRINT AT i,j;"T": LET trees=trees+1
|
||||
240 NEXT j
|
||||
250 NEXT i
|
||||
260 LET generation=generation+1
|
||||
270 INK 7
|
||||
280 PAPER 0
|
||||
290 PRINT AT 21,12;generation
|
||||
300 PRINT AT 21,28;" "
|
||||
310 PRINT AT 21,28;INT (trees/6+.5);"%"
|
||||
320 FOR i=1 TO 20
|
||||
330 FOR j=1 TO 30
|
||||
340 LET n$(i,j)=SCREEN$ (i,j)
|
||||
350 IF SCREEN$ (i,j)="B" THEN LET n$(i,j)=" ": GO TO 450
|
||||
360 IF SCREEN$ (i,j)="T" THEN GO TO 390
|
||||
370 IF RND<=p THEN LET n$(i,j)="T"
|
||||
380 GO TO 450
|
||||
390 FOR k=i-1 TO i+1
|
||||
400 FOR l=j-1 TO j+1
|
||||
410 IF SCREEN$ (k,l)="B" THEN LET n$(i,j)="B": LET k=i+2: LET l=j+2
|
||||
420 NEXT l
|
||||
430 NEXT k
|
||||
440 IF RND<=f THEN LET n$(i,j)="B"
|
||||
450 NEXT j
|
||||
460 NEXT i
|
||||
470 LET trees=0
|
||||
480 FOR i=1 TO 20
|
||||
490 FOR j=1 TO 30
|
||||
500 IF n$(i,j)="T" THEN INK 7: PAPER 4: PRINT AT i,j;"T": LET trees=trees+1: GO TO 540
|
||||
510 IF n$(i,j)="B" THEN INK 6: PAPER 2: PRINT AT i,j;"B": GO TO 540
|
||||
520 PAPER 6
|
||||
530 PRINT AT i,j;" "
|
||||
540 NEXT j
|
||||
550 NEXT i
|
||||
560 GO TO 260
|
||||
|
|
@ -1,104 +1,72 @@
|
|||
Public Class ForestFire
|
||||
Private _forest(,) As ForestState
|
||||
Private _isBuilding As Boolean
|
||||
Private _bm As Bitmap
|
||||
Private _gen As Integer
|
||||
Private _sw As Stopwatch
|
||||
|
||||
Private Const _treeStart As Double = 0.5
|
||||
Private Const _f As Double = 0.00001
|
||||
Private Const _p As Double = 0.001
|
||||
|
||||
Private Const _winWidth As Integer = 300
|
||||
Private Const _winHeight As Integer = 300
|
||||
|
||||
Private Enum ForestState
|
||||
Empty
|
||||
Burning
|
||||
Tree
|
||||
End Enum
|
||||
|
||||
Private Sub ForestFire_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||||
Me.ClientSize = New Size(_winWidth, _winHeight)
|
||||
ReDim _forest(_winWidth, _winHeight)
|
||||
|
||||
Dim rnd As New Random()
|
||||
For i As Integer = 0 To _winHeight - 1
|
||||
For j As Integer = 0 To _winWidth - 1
|
||||
_forest(j, i) = IIf(rnd.NextDouble <= _treeStart, ForestState.Tree, ForestState.Empty)
|
||||
Next
|
||||
Next
|
||||
|
||||
_sw = New Stopwatch
|
||||
_sw.Start()
|
||||
DrawForest()
|
||||
Timer1.Start()
|
||||
End Sub
|
||||
|
||||
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
|
||||
If _isBuilding Then Exit Sub
|
||||
|
||||
_isBuilding = True
|
||||
GetNextGeneration()
|
||||
|
||||
DrawForest()
|
||||
_isBuilding = False
|
||||
End Sub
|
||||
|
||||
Private Sub GetNextGeneration()
|
||||
Dim forestCache(_winWidth, _winHeight) As ForestState
|
||||
Dim rnd As New Random()
|
||||
|
||||
For i As Integer = 0 To _winHeight - 1
|
||||
For j As Integer = 0 To _winWidth - 1
|
||||
Select Case _forest(j, i)
|
||||
Case ForestState.Tree
|
||||
If forestCache(j, i) <> ForestState.Burning Then
|
||||
forestCache(j, i) = IIf(rnd.NextDouble <= _f, ForestState.Burning, ForestState.Tree)
|
||||
End If
|
||||
|
||||
Case ForestState.Burning
|
||||
For i2 As Integer = i - 1 To i + 1
|
||||
If i2 = -1 OrElse i2 >= _winHeight Then Continue For
|
||||
For j2 As Integer = j - 1 To j + 1
|
||||
If j2 = -1 OrElse i2 >= _winWidth Then Continue For
|
||||
If _forest(j2, i2) = ForestState.Tree Then forestCache(j2, i2) = ForestState.Burning
|
||||
Next
|
||||
Next
|
||||
forestCache(j, i) = ForestState.Empty
|
||||
|
||||
Case Else
|
||||
forestCache(j, i) = IIf(rnd.NextDouble <= _p, ForestState.Tree, ForestState.Empty)
|
||||
End Select
|
||||
Next
|
||||
Next
|
||||
|
||||
_forest = forestCache
|
||||
_gen += 1
|
||||
End Sub
|
||||
|
||||
Private Sub DrawForest()
|
||||
Dim bmCache As New Bitmap(_winWidth, _winHeight)
|
||||
|
||||
For i As Integer = 0 To _winHeight - 1
|
||||
For j As Integer = 0 To _winWidth - 1
|
||||
Select Case _forest(j, i)
|
||||
Case ForestState.Tree
|
||||
bmCache.SetPixel(j, i, Color.Green)
|
||||
|
||||
Case ForestState.Burning
|
||||
bmCache.SetPixel(j, i, Color.Red)
|
||||
End Select
|
||||
Next
|
||||
Next
|
||||
|
||||
_bm = bmCache
|
||||
Me.Refresh()
|
||||
End Sub
|
||||
|
||||
Private Sub ForestFire_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
|
||||
e.Graphics.DrawImage(_bm, 0, 0)
|
||||
|
||||
Me.Text = "Gen " & _gen.ToString() & " @ " & (_gen / (_sw.ElapsedMilliseconds / 1000)).ToString("F02") & " FPS: Forest Fire"
|
||||
End Sub
|
||||
End Class
|
||||
10 DIM F$(20,30)
|
||||
20 DIM N$(20,30)
|
||||
30 LET INIT=.5
|
||||
40 LET F=.02
|
||||
50 LET P=.05
|
||||
60 PRINT AT 0,1;"[FOREST FIRE FOR ROSETTA CODE]"
|
||||
70 FOR I=0 TO 21
|
||||
80 PRINT AT I,0;"[ ]"
|
||||
90 PRINT AT I,31;"[ ]"
|
||||
100 NEXT I
|
||||
110 FOR I=1 TO 30
|
||||
120 PRINT AT 21,I;"[ ]"
|
||||
130 NEXT I
|
||||
140 LET G=0
|
||||
150 LET T=0
|
||||
160 PRINT AT 21,1;"[GENERATION 0]"
|
||||
170 PRINT AT 21,20;"[COVER]"
|
||||
180 FOR I=1 TO 20
|
||||
190 FOR J=1 TO 30
|
||||
200 IF RND>=INIT THEN GOTO 240
|
||||
210 PRINT AT I,J;"0"
|
||||
220 LET F$(I,J)="0"
|
||||
230 LET T=T+1
|
||||
240 NEXT J
|
||||
250 NEXT I
|
||||
300 PRINT AT 21,26;"[ ]"
|
||||
310 LET N=INT (.5+T/6)
|
||||
320 GOSUB 1000
|
||||
330 PRINT AT 21,26;I$;"[ PC]"
|
||||
340 FOR I=1 TO 20
|
||||
350 PRINT AT I,0;"[>]"
|
||||
360 FOR J=1 TO 30
|
||||
380 IF F$(I,J)<>"[a]" THEN GOTO 410
|
||||
390 LET N$(I,J)=" "
|
||||
400 GOTO 530
|
||||
410 IF F$(I,J)<>" " THEN GOTO 433
|
||||
420 IF RND<=P THEN LET N$(I,J)="0"
|
||||
430 GOTO 530
|
||||
433 LET N$(I,J)=CHR$ (1+CODE F$(I,J))
|
||||
437 IF N$(I,J)>"Z" THEN LET N$(I,J)="£"
|
||||
440 FOR K=I-1 TO I+1
|
||||
450 FOR L=J-1 TO J+1
|
||||
460 IF K=0 OR L=0 OR K=21 OR L=21 THEN GOTO 480
|
||||
470 IF F$(K,L)="[a]" THEN GOTO 510
|
||||
480 NEXT L
|
||||
490 NEXT K
|
||||
500 GOTO 520
|
||||
510 LET N$(I,J)="[a]"
|
||||
520 IF RND<=F THEN LET N$(I,J)="[a]"
|
||||
530 NEXT J
|
||||
540 PRINT AT I,0;"[ ]"
|
||||
550 NEXT I
|
||||
552 LET G=G+1
|
||||
554 LET N=G
|
||||
556 GOSUB 1000
|
||||
558 PRINT AT 21,12;I$
|
||||
560 LET T=0
|
||||
570 FOR I=1 TO 20
|
||||
575 PRINT AT I,31;"[<]"
|
||||
580 FOR J=1 TO 30
|
||||
590 IF N$(I,J)<>"[a]" AND N$(I,J)<>" " THEN LET T=T+1
|
||||
600 NEXT J
|
||||
610 LET F$(I)=N$(I)
|
||||
620 PRINT AT I,1;F$(I)
|
||||
625 PRINT AT I,31;"[ ]"
|
||||
630 GOTO 300
|
||||
1000 LET S$=STR$ N
|
||||
1010 LET I$=""
|
||||
1020 FOR K=1 TO LEN S$
|
||||
1030 LET I$=I$+CHR$ (128+CODE S$(K))
|
||||
1040 NEXT K
|
||||
1050 RETURN
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue