CS 6510 Homework 1

Due: Monday, January 13th, 2014 11:45am

Implement homework assignments in whatever functional language you like. If you don't know what to use, then use Racket.

If you use Racket, you know something about functional programming, and you just need to learn the language, see the getting-started page in the documentation, which is also included in the distribution. You should also consider using Typed Racket.

If you're just starting out with functional programming, then start instead with these videos. They use a variant of Racket called Beginning Student Language, which is fine for now; you can learn more about full Racket later.

Part -1 – Subscribe to the mailing list

See the mailing list page.

Part 0 – Play Triple Town

Play the game online or on a mobile device (Andriod or iOS).

Part 1 – Representing a Triple Town Board

If you have enough functional-programming background: Choose a representation for Triple Town boards and write a useful function on the representation, such as as a function that takes a board that may have a match (after the user just placed a tile) and returns the new board. For now, you can simplify the game by leaving out tile variants, if you like.

If that's too much: implement collapse, which takes a list-of-tile (which is a kind of 1-dimensional town) that may include three of the same tile in a row, in which case it collapses the three tiles into a new tile. The new tile should go in place of the middle of the three matching tiles, and the other two tiles should be replaced by 'blank. Only the first match, if any should be collapsed, and castles should just collapse to a castle.

  ; A tile is either
  ;   - 'blank
  ;   - 'bush
  ;   - 'tree
  ;   - 'shack
  ;   - 'house
  ;   - 'mansion
  ;   - 'castle
  
  ; A list-of-tile is either
  ;  - empty
  ;  - (cons time list-of-tile)

The function collapse will mostly fall out of the design recipe for list-of-tile, but the cons? case of the function will need to use not only the list first, but also the first of the rest and the first of the rest of the rest — and only if the rest and the rest of the rest are not empty. You should probably have a helper function next-tile that takes a tile and returns the tile that is generated by a match.

Example:

  (check-equal (collapse (cons 'blank (cons 'bush (cons 'bush (cons 'bush empty)))))
               (cons 'blank (cons 'blank (cons 'tree (cons 'blank empty)))))

Last update: Monday, January 6th, 2014
mflatt@cs.utah.edu