|
1 | 1 | # Instructions append |
2 | 2 |
|
3 | | -In Chess, rows are called "ranks", and columns are called "files". Ranks range |
4 | | -from 1 to 8, while files range from A to H. |
| 3 | +## Implementation |
5 | 4 |
|
6 | | -In this exercise, `Square` is an opaque type which represents a square on a |
7 | | -chessboard. It uses 0-indexed `row` & `column` fields internally, and it |
8 | | -guarantees that they are always valid (i.e., from 0 to 7). |
| 5 | +In Chess, rows are called "ranks", and columns are called "files". |
| 6 | +Ranks range from 1 to 8, while files range from A to H. |
9 | 7 |
|
10 | | -The `create` function takes a `Str` as input, representing a valid square on |
11 | | -the chessboard using the official notation, such as `"C5"`. The `create` |
12 | | -function must parse this `Str`, verify that it represents a valid square, and if |
13 | | -so it must return a `Square` value containing the appropriate `row` and `column` |
14 | | -fields. Rank 1 corresponds to row 0, and rank 8 corresponds to row 7. For |
15 | | -example, `create "C5"` must return `@Square { row : 2, column : 3 }`. |
| 8 | +In this exercise, `Square` is an opaque type which represents a square on a chessboard. |
| 9 | +It uses 0-indexed `row` & `column` fields internally, and it guarantees that they are always valid (i.e., from 0 to 7). |
16 | 10 |
|
17 | | -The `QueenAttack` module also exposes handy `rank` & `file` functions. In the |
18 | | -example above, `rank` must return the integer `5`, and `file` must return the |
19 | | -character `'C'`. |
| 11 | +The `create` function takes a `Str` as input, representing a valid square on the chessboard using the official notation, such as `"C5"`. |
| 12 | +The `create` function must parse this `Str`, verify that it represents a valid square, and if so it must return a `Square` value containing the appropriate `row` and `column` fields. |
| 13 | +Rank 1 corresponds to row 0, and rank 8 corresponds to row 7. |
| 14 | +For example, `create "C5"` must return `@Square { row : 2, column : 3 }`. |
20 | 15 |
|
21 | | -Lastly, the `queen_can_attack` function takes two different `Square` values and |
22 | | -checks whether or not queens placed on these squares can attack each other. |
| 16 | +The `QueenAttack` module also exposes handy `rank` & `file` functions. |
| 17 | +In the example above, `rank` must return the integer `5`, and `file` must return the character `'C'`. |
23 | 18 |
|
24 | | -Take-away: opaque types such as `Square` are great when you want to offer some |
25 | | -guarantees, such as the fact that `row` and `column` are always between 0 and 7. |
26 | | -Opaque types also hide implementation details from the users, which makes the |
27 | | -API cleaner. |
| 19 | +Lastly, the `queen_can_attack` function takes two different `Square` values and checks whether or not queens placed on these squares can attack each other. |
| 20 | + |
| 21 | +Take-away: opaque types such as `Square` are great when you want to offer some guarantees, such as the fact that `row` and `column` are always between 0 and 7. |
| 22 | +Opaque types also hide implementation details from the users, which makes the API cleaner. |
0 commit comments