Links
Course Documents
     Main Page
     Assignments
     Contact Information
     Course Announcement
     Course Participants
     Discussion Forum
     Lecture Material
     Previous Course
     Project
     Questionnaires
     Schedule and Syllabus
     Swiki Basics
Swiki Features:
  View this Page
  Edit this Page
  Printer Friendly View
  Lock this Page
  References to this Page
  Uploads to this Page
  History of this Page
  Top of the Swiki
  Recent Changes
  Search the Swiki
  Help Guide
Related Links:
     Atlas Program
     Center for LifeLong Learning and Design
     Computer Science Department
     Institute of Cognitive Science
     College of Architecture and Planning
     University of Colorado at Boulder

Homework Assignment 5-Appendix A
Tomohiro Oda





board := JunMatrix new: 10.
1 to: 10 do: [ :x | board atPoint: x@1 put: 0. board atPoint: x@10 put: -1].
1 to: 10 do: [ :y | board atPoint: 1@y put: 0. board atPoint: 10@y put: -1].
board atPoint: 2@2 put: -1.
board atPoint: 9@9 put: -1.
at := [ :p | board atPoint: p+(1@1)].
place := [:p :value | board atPoint: p+(1@1) put: value ].
remove := [:p | board atPoint: p+(1@1) put: nil ].
isClear := [ :p | (at value: p) isNil].
isClearH := [ :p | (isClear value: p) and: [isClear value: p +(1@0)]].
isClearV := [ :p | (isClear value: p) and: [isClear value: p +(0@1)]].
piecesLeft := 31.
placeH :=
[ :p |
(isClearH value: p)
and:
[place value: p value: piecesLeft.
place value: p + (1@0) value: piecesLeft.
piecesLeft := piecesLeft - 1.
true]].
placeV :=
[ :p |
(isClearV value: p)
and:
[place value: p value: piecesLeft.
place value: p+(0@1) value: piecesLeft.
piecesLeft := piecesLeft - 1.
true]].
unplaceH :=
[ :p |
place value: p value: nil.
place value: p+(1@0) value: nil.
piecesLeft := piecesLeft + 1].
unplaceV :=
[ :p |
place value: p value: nil.
place value: p+(0@1) value: nil.
piecesLeft := piecesLeft + 1].
isLeftTopCorner :=
[ :p |
(isClear value: p-(1@1)) not and: [(isClear value: p-(1@0)) not and: [(isClear value: p-(0@1)) not and: [isClear value: p]]]].
findPlace :=
[ | x y |
x := (1 to: 8) detect: [ :t | y := (1 to: 8) detect: [ :u | isLeftTopCorner value: t@u ] ifNone: [nil]. y notNil] ifNone: [nil].
x notNil ifTrue: [x@y] ifFalse: [nil]].
step := nil.
tryH := [ :p | (placeH value: p) and: [step value or: [unplaceH value: p. false]]].
tryV := [ :p | (placeV value: p) and: [step value or: [unplaceV value: p. false]]].
step :=
[piecesLeft = 0
ifTrue: [true]
ifFalse:
[| p |
p := findPlace value.
p isNil
ifTrue: [self halt. false]
ifFalse:
[(tryH value: p) or: [tryV value: p]]]].
step value ifTrue: [board] ifFalse: [false]

View this PageEdit this PagePrinter Friendly ViewLock this PageReferences to this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide