Skip to content

Instantly share code, notes, and snippets.

@KazunoriUeda
Created December 19, 2018 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KazunoriUeda/8ac1842756a5f21939e3126ae0c5e82e to your computer and use it in GitHub Desktop.
Save KazunoriUeda/8ac1842756a5f21939e3126ae0c5e82e to your computer and use it in GitHub Desktop.
SmalltalkJenga
'From Pharo7.0.0rc1 of 5 December 2018 [Build information: Pharo-7.0.0+rc1.build.19.sha.1fcbcd5170ad832066c54be29dd6b9bd66dc9575 (64 Bit)] on 19 December 2018 at 6:24:50.740241 pm'!
Object subclass: #SmalltalkJenga
instanceVariableNames: 'random classList turn'
classVariableNames: ''
poolDictionaries: ''
category: 'SmalltalkJenga'!
!SmalltalkJenga methodsFor: 'actions' stamp: 'KazunoriUeda 12/19/2018 18:00'!
playAll
[ self play ] doWhileTrue: [ 0 < (self listSize) ].
! !
!SmalltalkJenga methodsFor: 'actions' stamp: 'KazunoriUeda 12/19/2018 18:00'!
play
(0 < self listSize)
ifTrue: [
| target |
self turn: (self turn) + 1.
Transcript cr; show: ('Turn ', (self turn asString), '!!').
target := self classList removeAt: self randomIndex.
Transcript cr; show: ('Delete ', target asString, '!!').
"target removeFromSystem." ]
ifFalse: [
Transcript cr; show: ('Awesome!! All classes are deleted!!') ]! !
!SmalltalkJenga methodsFor: 'initialize' stamp: 'KazunoriUeda 12/19/2018 18:00'!
initialize
random := nil.
classList := nil.
turn := 0.! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
classList
^ classList ifNil: [ classList := Smalltalk globals allClasses reject: [ :each | each = self class ] ]! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
randomIndex
^ self random nextInt: self listSize! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
random: anObject
random := anObject! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
turn: anObject
turn := anObject! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
classList: anObject
classList := anObject! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
turn
^ turn! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
random
^ random ifNil: [ random := Random seed: (DateAndTime now asUnixTime) ]! !
!SmalltalkJenga methodsFor: 'accessing' stamp: 'KazunoriUeda 12/19/2018 18:00'!
listSize
^ self classList size! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
SmalltalkJenga class
instanceVariableNames: 'default'!
!SmalltalkJenga class methodsFor: 'actions' stamp: 'KazunoriUeda 12/19/2018 18:00'!
playAll
self default playAll! !
!SmalltalkJenga class methodsFor: 'actions' stamp: 'KazunoriUeda 12/19/2018 18:00'!
play
self default play! !
!SmalltalkJenga class methodsFor: 'instance creation' stamp: 'KazunoriUeda 12/19/2018 18:00'!
default
default ifNil: [default := self new].
^default! !
!SmalltalkJenga class methodsFor: 'class initialization' stamp: 'KazunoriUeda 12/19/2018 18:00'!
initialize
default := nil! !
SmalltalkJenga initialize!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment