Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ls/life #69

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/ComputationalArt/CAGame.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,28 @@ CAGame >> setActiveCellTypeTo: cellType [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:50'
#'squeak_changestamp' : 'Sars 7/10/2024 14:42'
}
CAGame >> skipAhead: stepCount [

stepCount timesRepeat: [grid := ruler applyRules: ruleSet to: grid.].
stepCount timesRepeat: [ruler applyRules: ruleSet to: grid.].
screen step
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 7/3/2024 15:48'
#'squeak_changestamp' : 'Sars 7/10/2024 15:46'
}
CAGame >> start [
| maxIterations iterationCount gameloop ui |
isRunning := true.
frameDelay := 0.2.
frameDelay := 0.01.
brushSize := 1.
brushActive := false.
ruler := CARuler new.
activeCellType := CABlocks tnt.
ruleSet := OrderedCollection new add: CARuleFallDown new;
add: CARuleSink new;
add: CARuleSink new;
add: CARuleFluidFlowLeft new;
add: CARuleFluidFlowRight new;
add: CARulePyramidLeft new;
Expand All @@ -139,6 +139,8 @@ CAGame >> start [
add: CARuleFishSwimDown new;
add: CARuleFishDie new;
add: CARuleTntSpread new;
add: CARuleStonerLife new;

yourself.
grid := CAGrid new.
CAGrid fill: grid.
Expand All @@ -152,12 +154,12 @@ CAGame >> start [
cellViewMorph addMorph: ui.
cellViewMorph position: 750 @ 250.
screen step.
maxIterations := 200.
maxIterations := 100.
iterationCount := 0.
gameloop := [[iterationCount < maxIterations]
whileTrue: [(Delay forSeconds: frameDelay) wait.
isRunning
ifTrue: [grid := ruler applyRules: ruleSet to: grid.
ifTrue: [ruler applyRules: ruleSet to: grid.
screen step.
iterationCount := iterationCount + 1]].
Transcript show: 'Game loop terminated after ' , maxIterations printString , ' iterations.';
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleAlgaeDie.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 13:32'
#'squeak_changestamp' : 'Sars 7/10/2024 14:49'
}
CARuleAlgaeDie >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
|me waterCount chance tempCell|

me := neighborMatrix at: 2 at: 2.


chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.

waterCount := 1.

Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleAlgaeGrow.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 13:31'
#'squeak_changestamp' : 'Sars 7/10/2024 14:50'
}
CARuleAlgaeGrow >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
|me algaeCount chance tempCell|

me := neighborMatrix at: 2 at: 2.


chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.

algaeCount := 0.

Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleBurn.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 22:08'
#'squeak_changestamp' : 'Sars 7/10/2024 14:50'
}
CARuleBurn >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me fireCount chance tempCell |
me := neighborMatrix at: 2 at: 2.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
fireCount := 0.
1
to: 3
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleFireOut.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 22:04'
#'squeak_changestamp' : 'Sars 7/10/2024 14:50'
}
CARuleFireOut >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me waterCount woodCount chance tempCell |
me := neighborMatrix at: 2 at: 2.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
waterCount := 0.
1
to: 3
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleFishDie.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/14/2024 11:54'
#'squeak_changestamp' : 'Sars 7/10/2024 14:50'
}
CARuleFishDie >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me belowMe aboveMe rightMe leftMe futureAboveMe swimmingBlocks swimThroughBlocks chance |
Expand All @@ -16,7 +16,7 @@ CARuleFishDie >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
rightMe := neighborMatrix at: 2 at: 3.
leftMe := neighborMatrix at: 2 at: 1.
futureAboveMe := newNeighborMatrix at: 1 at: 2.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
swimmingBlocks := OrderedCollection new add: CABlocks fish;
yourself.
swimThroughBlocks := OrderedCollection new add: CABlocks water;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleFishSwimDown.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/14/2024 12:12'
#'squeak_changestamp' : 'Sars 7/10/2024 14:51'
}
CARuleFishSwimDown >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me belowMe aboveMe futureAboveMe swimmingBlocks swimThroughBlocks eatBlocks chance |
me := neighborMatrix at: 2 at: 2.
belowMe := neighborMatrix at: 3 at: 2.
aboveMe := neighborMatrix at: 1 at: 2.
futureAboveMe := newNeighborMatrix at: 1 at: 2.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
swimmingBlocks := OrderedCollection new add: CABlocks fish;
yourself.
swimThroughBlocks := OrderedCollection new add: CABlocks water;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleFishSwimLeft.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/14/2024 12:14'
#'squeak_changestamp' : 'Sars 7/10/2024 14:51'
}
CARuleFishSwimLeft >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me rightMe leftMe futureLeftMe swimmingBlocks swimThroughBlocks eatBlocks chance |
me := neighborMatrix at: 2 at: 2.
rightMe := neighborMatrix at: 2 at: 3.
leftMe := neighborMatrix at: 2 at: 1.
futureLeftMe := newNeighborMatrix at: 2 at: 1.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
swimmingBlocks := OrderedCollection new add: CABlocks fish;
yourself.
swimThroughBlocks := OrderedCollection new add: CABlocks water;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleFishSwimRight.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/14/2024 12:15'
#'squeak_changestamp' : 'Sars 7/10/2024 14:51'
}
CARuleFishSwimRight >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me rightMe leftMe futureLeftMe swimmingBlocks swimThroughBlocks eatBlocks chance |
me := neighborMatrix at: 2 at: 2.
rightMe := neighborMatrix at: 2 at: 3.
leftMe := neighborMatrix at: 2 at: 1.
futureLeftMe := newNeighborMatrix at: 2 at: 1.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
swimmingBlocks := OrderedCollection new add: CABlocks fish;
yourself.
swimThroughBlocks := OrderedCollection new add: CABlocks water;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleFishSwimUp.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'HaMa 6/14/2024 12:16'
#'squeak_changestamp' : 'Sars 7/10/2024 14:51'
}
CARuleFishSwimUp >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me belowMe aboveMe futureAboveMe swimmingBlocks swimThroughBlocks eatBlocks chance |
me := neighborMatrix at: 2 at: 2.
belowMe := neighborMatrix at: 3 at: 2.
aboveMe := neighborMatrix at: 1 at: 2.
futureAboveMe := newNeighborMatrix at: 1 at: 2.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
swimmingBlocks := OrderedCollection new add: CABlocks fish;
yourself.
swimThroughBlocks := OrderedCollection new add: CABlocks water;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleFluidFlowLeft.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 22:02'
#'squeak_changestamp' : 'Sars 7/10/2024 14:51'
}
CARuleFluidFlowLeft >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me rightMe belowRightMe leftMe futureLeftMe solidBlocks flowingBlocks flowThroughBlocks chance |
Expand All @@ -15,7 +15,7 @@ CARuleFluidFlowLeft >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
leftMe := neighborMatrix at: 2 at: 1.
belowRightMe := neighborMatrix at: 3 at: 3.
futureLeftMe := newNeighborMatrix at: 2 at: 1.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
solidBlocks := OrderedCollection new add: CABlocks sand;
add: CABlocks water;
add: CABlocks wood;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleFluidFlowRight.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 22:02'
#'squeak_changestamp' : 'Sars 7/10/2024 14:52'
}
CARuleFluidFlowRight >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me rightMe belowMe leftMe futureLeftMe solidBlocks flowingBlocks flowThroughBlocks chance |
Expand All @@ -15,7 +15,7 @@ CARuleFluidFlowRight >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
leftMe := neighborMatrix at: 2 at: 1.
belowMe := neighborMatrix at: 3 at: 2.
futureLeftMe := newNeighborMatrix at: 2 at: 1.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
solidBlocks := OrderedCollection new add: CABlocks sand;
add: CABlocks water;
add: CABlocks wood;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleGasDisappear.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 21:33'
#'squeak_changestamp' : 'Sars 7/10/2024 14:52'
}
CARuleGasDisappear >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me gasBlocks chance |
me := neighborMatrix at: 2 at: 2.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
gasBlocks := OrderedCollection new add: CABlocks smoke;
yourself.
((gasBlocks includes: me)
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleGasFlowLeft.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 21:17'
#'squeak_changestamp' : 'Sars 7/10/2024 14:52'
}
CARuleGasFlowLeft >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me rightMe belowRightMe leftMe futureLeftMe flowingBlocks flowThroughBlocks chance |
Expand All @@ -15,7 +15,7 @@ CARuleGasFlowLeft >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
leftMe := neighborMatrix at: 2 at: 1.
belowRightMe := neighborMatrix at: 3 at: 3.
futureLeftMe := newNeighborMatrix at: 2 at: 1.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
flowingBlocks := OrderedCollection new add: CABlocks smoke;
yourself.
flowThroughBlocks := OrderedCollection new add: CABlocks air;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleGasFlowRight.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/12/2024 21:23'
#'squeak_changestamp' : 'Sars 7/10/2024 14:52'
}
CARuleGasFlowRight >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me rightMe belowMe leftMe futureLeftMe flowingBlocks flowThroughBlocks chance |
Expand All @@ -15,7 +15,7 @@ CARuleGasFlowRight >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
leftMe := neighborMatrix at: 2 at: 1.
belowMe := neighborMatrix at: 3 at: 2.
futureLeftMe := newNeighborMatrix at: 2 at: 1.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
flowingBlocks := OrderedCollection new add: CABlocks smoke;
yourself.
flowThroughBlocks := OrderedCollection new add: CABlocks air;
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARulePyramidLeft.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:54'
#'squeak_changestamp' : 'Sars 7/10/2024 14:52'
}
CARulePyramidLeft >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me rightMe belowMe leftMe belowLeftMe futureLeftMe aboveRightMe futureAboveRightMe pyramidBlocks lightBlocks chance |
Expand All @@ -18,7 +18,7 @@ CARulePyramidLeft >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
aboveRightMe := neighborMatrix at: 1 at: 3.
futureLeftMe := newNeighborMatrix at: 2 at: 1.
futureAboveRightMe := newNeighborMatrix at: 1 at: 3.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
pyramidBlocks := OrderedCollection new add: CABlocks sand;
add: CABlocks algae;
yourself.
Expand Down
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARulePyramidRight.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/16/2024 20:54'
#'squeak_changestamp' : 'Sars 7/10/2024 14:53'
}
CARulePyramidRight >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me rightMe belowMe leftMe belowRightMe futureLeftMe aboveLeftMe futureAboveLeftMe pyramidBlocks lightBlocks chance |
Expand All @@ -18,7 +18,7 @@ CARulePyramidRight >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
aboveLeftMe := neighborMatrix at: 1 at: 1.
futureLeftMe := newNeighborMatrix at: 2 at: 1.
futureAboveLeftMe := newNeighborMatrix at: 1 at: 1.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
pyramidBlocks := OrderedCollection new add: CABlocks sand;
yourself.
lightBlocks := OrderedCollection new add: CABlocks air;
Expand Down
30 changes: 30 additions & 0 deletions src/ComputationalArt/CARuleStonerLife.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Class {
#name : #CARuleStonerLife,
#superclass : #CARule,
#category : #ComputationalArt
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 7/10/2024 15:19'
}
CARuleStonerLife >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me stoneCount chance |
me := neighborMatrix at: 2 at: 2.
chance := ThreadSafeRandom value nextInt: 100.
stoneCount := 0.
1
to: 3
do: [:rowIndex | 1
to: 3
do: [:colIndex | (neighborMatrix at: rowIndex at: colIndex)
= CABlocks stone
ifTrue: [stoneCount := stoneCount + 1]]].
me = CABlocks stone
ifTrue: [(stoneCount = 3 or: stoneCount = 4)
ifTrue: [^ me]
ifFalse: [^ CABlocks air]]
ifFalse: [stoneCount = 3
ifTrue: [^ CABlocks stone]].
^ me
]
4 changes: 2 additions & 2 deletions src/ComputationalArt/CARuleTntSpread.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/14/2024 17:14'
#'squeak_changestamp' : 'Sars 7/10/2024 14:53'
}
CARuleTntSpread >> applyRuleWith: neighborMatrix and: newNeighborMatrix [
| me tntCount chance tempCell poofBlocks |
me := neighborMatrix at: 2 at: 2.
chance := (1 to: 100) atRandom.
chance := ThreadSafeRandom value nextInt: 100.
poofBlocks := OrderedCollection new add: CABlocks air;
add: CABlocks air;
add: CABlocks smoke;
Expand Down
Loading
Loading