Skip to content

Instantly share code, notes, and snippets.

@kingcons
Created June 15, 2015 00:20
Show Gist options
  • Save kingcons/93314b5f203c10f6631b to your computer and use it in GitHub Desktop.
Save kingcons/93314b5f203c10f6631b to your computer and use it in GitHub Desktop.
Example Assignment

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.

FAQ (based on questions)

  • 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.

Objectives

Learning Objectives

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

Performance Objectives

After completing this assignment, you be able to effectively use

  • def to define functions and express functionality
  • gets and puts to handle IO
  • control flow via if / else
  • looping constructs like while and until

Details

Deliverables

  • A script tic-tac-toe.rb

Requirements

  • Running ruby tic-tac-toe.rb should play a game of tic-tac-toe in the terminal.

Easy Mode

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.

Normal Mode

The script should fulfill the Easy Mode requirements and support both a human and computer second player.

Hard Mode

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.

Nightmare Mode

Make it so that the computer will never lose.

Notes

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment