- 머리에 쥐나는줄 알았다.--; 사소한거 하나로 삽질한게 몇가진지... --; 문법이 왜 이리 하던거랑 다른지.;;
~cpp
RWBoard>>initialize: aSize
size := aSize.
numsOfWalked := Array2D width:size height:size.
numsOfWalked atAllPut:0.
RWBoard>>isAllPut
numsOfWalked do: [ :val | val = 0 ifTrue: [^false] ].
^true.
RWBoard>>row: aRow col: aCol
| numOfWalked |
numOfWalked _ numsOfWalked at: aRow at: aCol.
numsOfWalked at: aRow at:aCol put: numOfWalked + 1.
RWBoard>>setValidLocation: num
| newValue |
newValue := num + 3 atRandom - 2.
newValue = 0 ifTrue: [newValue := 1].
newValue = (1 + size) ifTrue: [newValue := size].
^newValue.
RWBoard Class>>make: aSize
^self new initialize:aSize.
~cpp
RWRoach>>abroad: aBoard row: aRow col: aCol
totalWalked := 1.
curRow _ aRow.
curCol _ aCol.
aBoard row: aRow col: aCol.
RWRoach>>moveOne: aBoard
totalWalked _ totalWalked + 1.
self selectDirection: aBoard.
aBoard row:curRow col:curCol.
RWRoach>>selectDirection: aBoard
curRow := aBoard setValidLocation: curRow.
curCol := aBoard setValidLocation: curCol.
RWRoach>>traverse: aBoard
[ aBoard isAllPut = false. ] whileTrue: [ self moveOne:aBoard. ].