GithubHelp home page GithubHelp logo

tic-tac-toe's Introduction

This program implements an unbeatable Tic-Tac-Toe AI in Ruby

requires Ruby 1.9

To play the game run rake play

To run the included unit tests run rake test

The implementation of the AI is explained in the comments for AIPlayer#get_move

Changes in V3

Changes in V2

Rakefile

  • Now use rake play to play game, rake test to run tests
  • Test coverage extended, includes testing methods that take user input (which puts a lot of garbage to the terminal but you can still see all the tests passing)

User Interface

  • User now enters a cell number (0-8) instead of row/column
  • Improved ANSI art with UTF-8 box symbols
  • Slightly changed the user prompts

AIPlayer

  • Now is its own class, does not inherit from player
  • Move was only used by the AIPlayer so that class is now internal to the AIPlayer

Player

  • Now prompts player for cell number 0-8
  • No parts that are only necessary for the AIPlayer

Board

  • Current player now represented by a symbol :X or :O
  • Board state representaion now 3x3 array of nil, :X, :O Much easier to understand
  • Moves now made by row/column, only AIPlayer knows about Moves
  • Simplified win/tie checking into one method Now returns :X, :O, :tie, :none; clearer meaning
  • Made board larger, better looking, easier to read
  • separated display of board from board class

Tic-Tac-Toe

  • Separated different phases of game into their own methods
  • Game now played by creating an instance of the TicTacToe class
  • Made game logic easier to follow

Overall

  • Removed extraneous exceptions and state checking that never occur when playing the game
  • Code easier to read and understand

tic-tac-toe's People

Contributors

robertjlooby avatar

Watchers

James Cloos 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.