In this assignment, we'll implement a version of tic-tac-toe that we can play from the command line. You should push what you have by Monday at 8am. Incomplete work that is on time and later refined is preferred to late work that is complete and bug-free.
-
I would prefer you submit the script as one file and prompt the user for different options (e.g. computer or human 2nd player, hard mode, etc.)
-
Please do not use Classes for this assignment. It is possible we will revisit it once we have learned classes next week.
After completing this assignment, you should…
- Understand IO and be able to interact with users
- Know how to use data structures to model state
- Think about how to structure logic and break things into functions in longer programs
After completing this assignment, you be able to effectively use
def
to define functions and express functionalitygets
andputs
to handle IO- control flow via
if
/else
- looping constructs like
while
anduntil
- A script
tic-tac-toe.rb
- Running
ruby tic-tac-toe.rb
should play a game of tic-tac-toe in the terminal.
The script should play a game of tic-tac-toe to completion and print the game's outcome. Each turn, the script displays the current board and prompts the user for a move. It may either have two human players or a human player and a computer player that chooses a move randomly.
The script should fulfill the Easy Mode requirements and support both a human and computer second player.
The AI should try to do something intelligent instead of choosing random empty spaces. Hardcoding "if the board is this, play this" is tractable, but there are several valid approaches.
Make it so that the computer will never lose.
This project is deliberately non-proscriptive. Start. Write some code. Don't worry too much about getting it perfect. Make some mistakes. We'll revisit this shortly.