"Do it as a whole. Change stage from 0 to 3; close old windows." | stage table states board label x matched | stage := 0. table := #(0 0 1 2 3 0 1). states := OrderedCollection with: 5. matched := 5. [matched > 0] whileTrue: [matched := table at: matched. states add: matched]. board := SystemWindow labelled: 'KMP - follow the border chain'. board openInWorld; position: 30@30; extent: 1000@400. label := [:text :point :size | | m | m := StringMorph contents: text font: (StrikeFont familyName: 'DejaVu Sans' pointSize: size). m color: Color black; position: board position + point. board addMorph: m]. label value: 'Pattern ABABACA: a mismatch can require several fallbacks' value: 25@55 value: 21. label value: 'Already matched ABABA; next text character is X.' value: 25@105 value: 19. 1 to: states size do: [:i | | cell | x := 35 + ((i - 1) * 235). cell := RectangleMorph new. cell position: board position + (x@170); extent: 190@75; color: (i = (stage + 1) ifTrue: [Color lightGreen] ifFalse: [Color lightGray]). board addMorph: cell. label value: ('matched = ', (states at: i) printString) value: (x + 10)@195 value: 21]. label value: (stage = 0 ifTrue: ['Start with five matched characters.'] ifFalse: ['Fallback: table[', (states at: stage) printString, '] = ', (states at: stage + 1) printString]) value: 25@285 value: 23. label value: 'The text position stays fixed while we try shorter borders.' value: 25@340 value: 18. board