Giter VIP home page Giter VIP logo

intro-to-tic-tac-toe-rb's Introduction

Intro To Tic Tac Toe in Ruby

Objectives

  1. Learn about building Tic Tac Toe in Ruby.

Introduction

We're going to be learning how to build Tic Tac Toe in Ruby. If you're unfamiliar with the game, it is played on a 3 by 3 grid of available cells. The goal of the game is to get three of your tokens, X or O, in a row, including diagonals.

The following example game is won by the first player, X:

X Wins

Why build Tic Tac Toe?

I'm sure you're really excited about building the next Facebook or Instagram, but like most things in life, we have to crawl before we walk, and walk before we run, and build Tic Tac Toe before we build large and complex applications.

Tic Tac Toe is a simple ruleset that flexes the basic concepts in programming, like data structures for storing the board, conditional logic for knowing whose turn it is or if someone has won.

Because of the simple game rules, Tic Tac Toe is very easy to decompose into discrete, small, functionality, that we can then put together to create a complete game. This process of decomposition and synthesis, breaking something down and putting it back together, is absolutely essential to programming.

The simple interface Tic Tac Toe requires, a basic 3 x 3 grid, is also easy to port to multiple interfaces. We can build a command line version of Tic Tac Toe or a web-based version. We can even build a SMS version of Tic Tac Toe if we wanted.

Web Tic Tac Toe

CLI Tic Tac Toe

Beyond being able to move easily between interfaces, we can also move between programming styles, building Tic Tac Toe in a procedural or functional style first, then moving that to an Object Oriented version, and finally, adding our Tic Tac Toe model to a Sinatra Web Application.

Once you've built your basic 2-player version of Tic Tac Toe, you are free to extend it by creating a 1 player version and trying to program an unbeatable AI.

<iframe width="753" height="380" src="https://www.youtube.com/embed/F7qOV8xonfY?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>

Pseudo-Code for Tic Tac Toe

The general procedure for Tic Tac Toe is as follows:

  1. Create a structure to store and represent the state of the board.
  2. Welcome the players.
  3. Get the user's move in the form of some input.
  4. Make sure their move is valid.
  5. Check to see if the game has been won or draw.
  6. Change the player turn and let the next player make a move.
  7. Repeat until the game is over.

As your progress through this course, we'll break all these requirements down into simple, cumulative labs throughout the track. You'll be surprised at how quickly you'll learn to do something this complex.

Let's get started learning enough Ruby to build our Tic Tac Toe.

intro-to-tic-tac-toe-rb's People

Contributors

aviflombaum avatar sammarcus avatar sophiedebenedetto avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.