Skip to content

Commit

Permalink
Updated the model
Browse files Browse the repository at this point in the history
  • Loading branch information
olekscode committed Sep 1, 2024
1 parent 796f4e7 commit d733f48
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 209 deletions.
31 changes: 16 additions & 15 deletions src/FireAutomata-Model-Tests/FireAutomataCellStateTest.class.st
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
Class {
#name : #FireAutomataCellStateTest,
#superclass : #TestCase,
#name : 'FireAutomataCellStateTest',
#superclass : 'TestCase',
#instVars : [
'emptyCellState',
'treeCellState',
'fireCellState',
'ashCellState'
],
#category : #'FireAutomata-Model-Tests'
#category : 'FireAutomata-Model-Tests',
#package : 'FireAutomata-Model-Tests'
}

{ #category : #initialization }
{ #category : 'initialization' }
FireAutomataCellStateTest >> setUp [

super setUp.
Expand All @@ -21,13 +22,13 @@ FireAutomataCellStateTest >> setUp [
ashCellState := FireAutomataAshState new.
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
FireAutomataCellStateTest >> testAshCellStateColor [

self assert: ashCellState color equals: Color gray.
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellStateTest >> testAshTurnsToEmpty [

| cellState |
Expand All @@ -41,13 +42,13 @@ FireAutomataCellStateTest >> testAshTurnsToEmpty [
self assert: cellState isEmpty.
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
FireAutomataCellStateTest >> testEmptyCellStateColor [

self assert: emptyCellState color equals: Color black.
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellStateTest >> testEmptyRemainsEmpty [

| cellState |
Expand All @@ -58,13 +59,13 @@ FireAutomataCellStateTest >> testEmptyRemainsEmpty [
self assert: cellState isEmpty ].
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
FireAutomataCellStateTest >> testFireCellStateColor [

self assert: fireCellState color equals: Color red.
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellStateTest >> testFireTurnsToAsh [

| cellState |
Expand All @@ -78,7 +79,7 @@ FireAutomataCellStateTest >> testFireTurnsToAsh [
self assert: cellState isAsh.
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
FireAutomataCellStateTest >> testIsAsh [

self deny: emptyCellState isAsh.
Expand All @@ -87,7 +88,7 @@ FireAutomataCellStateTest >> testIsAsh [
self assert: ashCellState isAsh.
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
FireAutomataCellStateTest >> testIsEmpty [

self assert: emptyCellState isEmpty.
Expand All @@ -96,7 +97,7 @@ FireAutomataCellStateTest >> testIsEmpty [
self deny: ashCellState isEmpty.
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
FireAutomataCellStateTest >> testIsFire [

self deny: emptyCellState isFire.
Expand All @@ -105,7 +106,7 @@ FireAutomataCellStateTest >> testIsFire [
self deny: ashCellState isFire.
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
FireAutomataCellStateTest >> testIsTree [

self deny: emptyCellState isTree.
Expand All @@ -114,7 +115,7 @@ FireAutomataCellStateTest >> testIsTree [
self deny: ashCellState isTree.
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
FireAutomataCellStateTest >> testTreeCellStateColor [

self assert: treeCellState color equals: Color green.
Expand Down
30 changes: 13 additions & 17 deletions src/FireAutomata-Model-Tests/FireAutomataCellTest.class.st
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
Class {
#name : #FireAutomataCellTest,
#superclass : #TestCase,
#name : 'FireAutomataCellTest',
#superclass : 'TestCase',
#instVars : [
'cell'
],
#category : #'FireAutomata-Model-Tests'
#category : 'FireAutomata-Model-Tests',
#package : 'FireAutomata-Model-Tests'
}

{ #category : #initialization }
{ #category : 'initialization' }
FireAutomataCellTest >> setUp [

super setUp.
cell := FireAutomataCell new.
]

{ #category : #tests }
FireAutomataCellTest >> testEntityName [

self assert: cell class entityName equals: 'Cell'
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellTest >> testGenerateTree [

cell generateTree.
self assert: cell isTreeCell.
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellTest >> testGenerateTreeWithProbability [

"With random seed 42 the PMFishmanMooreRandomGenerator generates the following numbers:
Expand All @@ -36,7 +31,8 @@ FireAutomataCellTest >> testGenerateTreeWithProbability [
This means that if we ask a cell 4 times to generate a tree with probability 0.1,
then the first 3 times, nothing will happen. And on the 4th request, the tree will appear."

Cormas randomGenerator: (PMFishmanMooreRandomGenerator seed: 42).
cell randomNumberGenerator: PMFishmanMooreRandomGenerator new.
cell randomSeed: 42.

3 timesRepeat: [
cell generateTreeWithProbability: 0.1.
Expand All @@ -46,13 +42,13 @@ FireAutomataCellTest >> testGenerateTreeWithProbability [
self assert: cell isTreeCell.
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellTest >> testInitializedEmpty [

self assert: cell isEmptyCell
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellTest >> testNewState [

cell setOnFire.
Expand All @@ -67,13 +63,13 @@ FireAutomataCellTest >> testNewState [
self assert: cell isAshCell.
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellTest >> testPov [

self assert: cell pov isColor.
]

{ #category : #tests }
{ #category : 'tests' }
FireAutomataCellTest >> testSetOnFire [

cell setOnFire.
Expand Down
2 changes: 1 addition & 1 deletion src/FireAutomata-Model-Tests/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'FireAutomata-Model-Tests' }
Package { #name : 'FireAutomata-Model-Tests' }
19 changes: 10 additions & 9 deletions src/FireAutomata-Model/FireAutomataAshState.class.st
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
Class {
#name : #FireAutomataAshState,
#superclass : #FireAutomataCellState,
#name : 'FireAutomataAshState',
#superclass : 'FireAutomataCellState',
#instVars : [
'iterationsToDisappear'
],
#category : #'FireAutomata-Model'
#category : 'FireAutomata-Model',
#package : 'FireAutomata-Model'
}

{ #category : #'default values' }
{ #category : 'default values' }
FireAutomataAshState class >> defaultIterationsToDisappear [

^ 2
]

{ #category : #accessing }
{ #category : 'accessing' }
FireAutomataAshState >> color [

^ Color gray
]

{ #category : #initialization }
{ #category : 'initialization' }
FireAutomataAshState >> initialize [

super initialize.
iterationsToDisappear := self class defaultIterationsToDisappear.
]

{ #category : #testing }
{ #category : 'testing' }
FireAutomataAshState >> isAsh [

^ true
]

{ #category : #accessing }
{ #category : 'accessing' }
FireAutomataAshState >> iterationsToDisappear: aNumber [
"Set the number of iterations during which the cell should remain in the state of ash. After those iterations, the ash will disappear and the state will be changed"
iterationsToDisappear := aNumber
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
FireAutomataAshState >> newState [

iterationsToDisappear := iterationsToDisappear - 1.
Expand Down
35 changes: 15 additions & 20 deletions src/FireAutomata-Model/FireAutomataCell.class.st
Original file line number Diff line number Diff line change
@@ -1,73 +1,68 @@
Class {
#name : #FireAutomataCell,
#superclass : #CMSpatialEntityCell,
#category : #'FireAutomata-Model'
#name : 'FireAutomataCell',
#superclass : 'CMSpatialEntityCell',
#category : 'FireAutomata-Model',
#package : 'FireAutomata-Model'
}

{ #category : #accessing }
FireAutomataCell class >> entityName [

^ 'Cell'
]

{ #category : #initialization }
{ #category : 'initialization' }
FireAutomataCell >> generateTree [

self state: (FireAutomataTreeState forCell: self)
]

{ #category : #initialization }
{ #category : 'initialization' }
FireAutomataCell >> generateTreeWithProbability: aNumber [
"Probability that a cell is initialized with a tree in it"

Cormas random < aNumber
self random < aNumber
ifTrue: [ self generateTree ]
]

{ #category : #initialization }
{ #category : 'initialization' }
FireAutomataCell >> initialize [

super initialize.
self state: (FireAutomataEmptyState forCell: self).
]

{ #category : #testing }
{ #category : 'testing' }
FireAutomataCell >> isAshCell [

^ state isAsh
]

{ #category : #testing }
{ #category : 'testing' }
FireAutomataCell >> isEmptyCell [

^ state isEmpty
]

{ #category : #testing }
{ #category : 'testing' }
FireAutomataCell >> isFireCell [

^ state isFire
]

{ #category : #testing }
{ #category : 'testing' }
FireAutomataCell >> isTreeCell [

^ state isTree
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
FireAutomataCell >> newState [

self bufferState: state newState.
]

{ #category : #pov }
{ #category : 'pov' }
FireAutomataCell >> pov [

^ state color
]

{ #category : #initialization }
{ #category : 'initialization' }
FireAutomataCell >> setOnFire [

self state: (FireAutomataFireState forCell: self)
Expand Down
Loading

0 comments on commit d733f48

Please sign in to comment.