|
| 1 | +Connect Four |
| 2 | + |
| 3 | +[Connect Four](https://en.wikipedia.org/wiki/Connect_Four) is a board game. |
| 4 | +Players take turns placing tokens of their color into a vertical grid. |
| 5 | +They drop to the bottom, and if anyone has four of their color in a straight line, they've won! |
| 6 | + |
| 7 | +Define a module that simulates a Connect Four game. |
| 8 | + |
| 9 | +This will consist of the following classes: |
| 10 | + |
| 11 | +`Player`: |
| 12 | +- Properties |
| 13 | + - `name` |
| 14 | + - `color` |
| 15 | + |
| 16 | +`Game`: |
| 17 | +- Properties |
| 18 | + - `board`: 7x6 board representation |
| 19 | + |
| 20 | +- Methods |
| 21 | + - `get_height(position)`: returns int of how many pieces occupy a column |
| 22 | + - `move(player, position)`: adds a player token to a column after figuring out the current height of the column |
| 23 | + - `calc_winner()`: returns true if a match (four in a row) is found |
| 24 | + - `is_full()`: returns true if all board positions are occupied |
| 25 | + - `is_game_over()`: returns true if the game is over (a winner is found or the board is full) |
| 26 | + |
| 27 | + |
| 28 | +Create a program that simulates the _just playing moves_ of an existing Connect Four game. |
| 29 | +Do not concern yourself with figuring out who has won. |
| 30 | + |
| 31 | +It will read a file that contains a history of the moves in a game. |
| 32 | +Assume the playing board is made of columns numbered 1 through 7. |
| 33 | +The file will have one line for each move (players alternate). |
| 34 | +The number in that line is the column the current player placed a token in. |
| 35 | + |
| 36 | +Use the following [example move file](./connect_four/connect-four-moves.txt). |
| 37 | +Save it in something like `connect-four-moves.txt` |
| 38 | +This moves file recreates [this game](https://en.wikipedia.org/wiki/File:Connect_Four.gif). |
| 39 | + |
| 40 | +* Think about how to figure out how far that token will fall in a given column. |
| 41 | + |
| 42 | +* Think about how to place a token in a column. |
| 43 | + |
| 44 | +* Think about how to concisely store the tokens that have been dropped in the board. |
| 45 | + |
| 46 | +* Read in moves from the file. |
| 47 | + |
| 48 | +* After each move, print out a representation of the board. |
| 49 | + You can use `R` and `Y` to represent the pieces. |
| 50 | + |
| 51 | +## Version 2 |
| 52 | + |
| 53 | +* Once all moves are done, also print out what player, if any, won. |
| 54 | + |
| 55 | +## Version 3 |
| 56 | + |
| 57 | +* Make game playable |
0 commit comments