|
| 1 | +# Example-based programming that mixes symbolic and direct manipulation |
| 2 | + |
| 3 | + |
| 4 | +## Case study: programming an interactive goban |
| 5 | + |
| 6 | + |
| 7 | +### Draw static content, then generalize |
| 8 | + |
| 9 | +* board |
| 10 | + * draw background |
| 11 | + * draw grid lines |
| 12 | + * listify line rows and columns |
| 13 | + * parameterize and constrain list sizes (num rows must equal num cols) |
| 14 | + * parameterize spacing dimensions |
| 15 | + * draw star points |
| 16 | + * describe and parameterize star point placement conditions in terms of board size |
| 17 | +* stones |
| 18 | + * draw colorless base stone |
| 19 | + * parameterize dimensions |
| 20 | + * instantiate and draw black and white versions |
| 21 | +* board + stones |
| 22 | + * instantiate and snap stones of both colors over board intersections |
| 23 | + * listify these stones/positions |
| 24 | + * transform list -> dict (pos => stone) |
| 25 | + * also indicates position uniqueness |
| 26 | + * parameterize over the stone dict |
| 27 | + * factor stone absolute position dimensions in terms of intersection position |
| 28 | + * parameterize over dimension factor |
| 29 | + |
| 30 | + |
| 31 | +### Demonstrate dynamic rules, then generalize |
| 32 | + |
| 33 | +* stone placement |
| 34 | + * correlate mouse click with appropriate intersection position |
| 35 | + * if position is not empty, do nothing |
| 36 | + * otherwise, correlate clicked intersection with stone placement |
| 37 | +* removal |
| 38 | + * correlate a placed stone with starting a new process |
| 39 | + * remember stone |
| 40 | + * identify and remember stone neighbors |
| 41 | + * if any neighbor is empty, full process ends successfully |
| 42 | + * for each non-empty neighbor of the same color, recurse |
| 43 | + * if process does not end successfully before we run out of candidate neighbors to follow, process ends in failure |
| 44 | + * all remembered stones (those traversed of the same color) are removed |
| 45 | +* capture |
| 46 | + * correlate stone placement intersection with neighboring intersections |
| 47 | + * identify neighbors of opposite color |
| 48 | + * with each opposer, attempt removal process |
| 49 | + * finally, attempt removal process on newly placed stone |
| 50 | +* playing a move |
| 51 | + * start a list with empty goban |
| 52 | + * add new goban formed by placing a stone |
| 53 | + * generalize as procedure taking history list, stone, and placement position, producing a new history list |
| 54 | +* alternating play |
| 55 | + * correlate stone placement with color alternation |
| 56 | +* comparing two gobans |
| 57 | + * compare each corresponding intersection to determine whether all are identical |
| 58 | +* positional super ko |
| 59 | + * extend play-move procedure by comparing the newly-created goban with all gobans already in the history |
| 60 | + * if any are identical to the new goban, fail |
| 61 | + * otherwise, succeed with the new history |
0 commit comments