Reversi Ray

A variant on the true game of Reversi.

This variation on the game of Reversi is simpler to implement than the “full version”, so we will do it first. In this version, we place one piece on the board and then choose a direction to extend a line of pieces in one direction.

A line that extends in only one direction is called a ray, so this version is called the “ray”.

In this version the mode part of the struct gets used to tell the difference between the mode of placing the anchor and the mode of choosing the direction.

Anchor Mode

The first piece you place is called the anchor. The mode for placing an anchor is the same as the normal mode that you have already written, except that after you place the piece, then it changes to “direction mode”.

(Pick a number of “anchor mode”, I used 3. You could even use 1!)

(define ANCHOR-MODE 3)

Important: write a check-expect for the mouse-handler showing how a piece gets placed and the mode gets changed to DIRECTION-MODE.

Direction Mode

The second click selects a direction for the ray to extend. The action in this step is quite a bit more complex.

(Pick a number for “direction mode”, I used 4.)

(define DIRECTION-MODE 4)
  • Write the helper functions (see below).
  • Change back to “anchor mode” after the pieces are placed.
  • Refuse to place the direction piece if it is not adjacent to the anchor piece.

Ray Helpers

Write a helper function ray-one that produces a list of a given number of posns beginning at a start posn and going in a direction posn.

ray-one: posn(start) posn(direction) number(steps) -> list-of-posn 

Hopefully you can do this with your recursive function-writing skills. Start with a check in a simple case, like steps=1 or even steps=0.

Then write a helper function that converts these posns to pieces. The additional information you need is who is playing the pieces.

ray-two: player list-of-posn -> list-of-piece
Last modified August 18, 2023: 2022-2023 End State (7352e87)