Giter VIP home page Giter VIP logo

ttt-2-board-rb's Introduction

Tic Tac Toe Board

Overview

The Tic Tac Toe Board

When building a Tic Tac Toe program, you're going to have to figure out a way to store or represent the game board. Looking at a Tic Tac Toe board, we can identify a few properties.

   |   |
-----------      
   |   |
-----------   
   |   |

A Tic Tac Toe board is basically a 3x3 grid with 9 total positions. You could think of the positions as being numbered, from top left to bottom right, as:

 1 | 2 | 3
-----------      
 4 | 5 | 6
-----------   
 7 | 8 | 9

Each cell in the Tic Tac Toe board can thus be referred to by a simple single number identifier. The middle square would be referred to as 5.

This is super useful because it will eventually allow players to easily tell the program where they want to move. The player X could tell the program they want to move to the top left corner by saying "1". The board would represent that graphically (through ASCII) via:

 X |   |
-----------      
   |   |
-----------   
   |   |

ASCII just means using standard keyboard characters, also known as the ASCII character set, to draw graphics.

An ASCII Cat:

/\     /\
{  `---'  }
{  O   O  }
~~>  V  <~~
 \  \|/  /
  `-----'__
  /     \  `^\_
 {       }\ |\_\_   W
 |  \_/  |/ /  \_\_( )
  \__/  /(_O     \__/
    (  /
     ME

Representing the Board as an Array

Now that we have simplified the concept of a Tic Tac Toe board to a collection of 9 positions or cells, easily identified by number, how can we represent this in code? What tool do we have at our disposal that can represent a collection of things? Is there some magical way to store data in ruby as an ordered, indexed, list? If you're thinking "We can use an Array!", you're absolutely right.

We need an array that has 9 elements. Each element in the array represents a position in the board. The first element in the array, index 0, is actually position 1 on the board, the top left corner. We'll represent the value of a position with a string that has a single space, " ".

As a simplified example, imagine only a single row of tic tac toe. You would represent that with the following array:

row = [" ", " ", " "]

# Position 1: Left
row[0]

# Position 2: Middle
row[1]

# Position 3: Right
row[2]

# Move X to the Position 2, Middle
row[1] = "X"
row #=> [" ", "X", " "]

*Note: You should create a simple array with one element for each position on the board. There are some more complex ways you could solve this with an array for each row of the board saved within the array for the board (a nested or multi-dimensional array). Don't do that - it'll just make your code harder to work with for now.

Remember: Represent a position in the board array as a string with a space in it: " "

Objectives

  1. Define a local variable board.
  2. Assign board to an array with 9 string elements.

Instructions

  1. Define a local variable in lib/board.rb called board
  2. Set the board local variable equal to an array.
  3. Fill the board array with 9 strings containing a single space: " ".
  4. Run learn and read output and fix any errors.
  5. Submit your solution with learn submit.

View Tic Tac Toe Board on Learn.co and start learning to code for free.

ttt-2-board-rb's People

Contributors

annjohn avatar aviflombaum avatar eaud avatar krishna-vempati avatar loganhasson avatar maxwellbenton avatar peterbell avatar pletcher avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ttt-2-board-rb's Issues

Tic Tac Toe Board - Variables

Looking for lesson...
Forking lesson...
Cloning lesson...
Opening lesson...
Sorry, there seems to be a problem with this lesson.Please submit a bug report to [email protected] and try again later.
If you'd like to work on your next lesson now, type:learn next

I am getting the above message when trying to complete the lesson in the IDE.

note seems out of place/not well enough explained

This:

Note: You should not create a multi-dimensional or nested array. The array should be flat and have only string values.

Remember: Represent a position in the board array as a string with a space in it: " "

2 things: 1) it feels like this should come after the instructions and 2) why mention multi-dimensional arrays at all? since they haven't been explained yet, this is kind of confusing. (if anything, there should at least be an explanation of what that means.)

Error Message

Could not find proper version of rspec-core (3.3.2) in any of the sources
Run bundle install to install missing gems.

When I type learn into nitrous I have been receiving the error above. How can I resolve the issue?

Trouble with Nitrous

Hello, I cannot get into Nitrous as of yesterday. I logged out and logged back in, refreshed my browser, refreshed Nitrous, to no avail.

Can someone help with this?

Thanks,

problem with 'learn' command

When testing solution to the problem with 'learn' command, nothing happens the terminal cursor returns to a new terminal line. When testing the solution to the problem with 'rspec' command, the solution passes with 0 failures.

See below...

Looking for lesson...
Forking lesson...
Cloning lesson...
Opening lesson...
Sorry, there seems to be a problem with this lesson.Please submit a bug report to [email protected] and try again later.
If you'd like to work on your next lesson now, type:learn next

I get this when I run learn:

You don't appear to be in a Learn lesson's directory. Please cd to an appropriate directory and try again

Define ASCII

Don't think the user has been told what ASCII is at this point

```ttt-2-board-rb-q-000``` folder only contains config file

When I open this lab in the Atom IDE, the ttt-2-board-rb-q-000 folder only contains the .bundle folder, which in return only contains the .config file.

pwd actually shows the correct files as being in the directory, but they do not exist in the actual .atom directory on my computer

The issue exists both when the lab is opened from the lab web page, and from the IDE, using learn open.

The bug makes the lab impossible to begin. :(

2016-05-06 1
2016-05-06 2
2016-05-06 3
2016-05-06

not working at all

Looking for lesson...
Hmm...Cannot find lesson with repo: ttt-2-board-rb-ruby-intro-000. Please check your input and try again.

This what I get every time I try to open the lab. Have tried a bunch of things to fix it and none of them working. Asked a question and it seems like a lot of other people are having this same problem rn.

Learn Submit

It will not let me learn submit this lesson so I can move on. Any suggestions on why and how to fix it. I have done all the basics relaunch, restart, login out, cookies

lib/board.rb
defines a local variable board
board is set to an array
board is an array with 9 elements
board is an array with 9 strings with an empty space va
lue, " "

Finished in 0.00669 seconds (files took 0.21962 seconds to
load)
4 examples, 0 failures

// ♥ learn submit
Adding changes...
Committing changes...
It looks like you have no changes to commit. Will still try
updating your submission...
Pushing changes to GitHub...
Submitting lesson...
Done.
[18:35:01] (master) ttt-2-board-rb-cb-gh-000

IDE not installing on desktop

Hi
When i run my Learn IDE install.exe it opens atom but does not open the login screen to login to learn.co. After initial successful installation, it crashed after 3 assignments and could not be resolved ever since.
Please help really stuck here
Parul

Table of Contents

We are not able to scroll the table of contents, therefore, the topics that are towards the bottom cannot be seen. For instance, in Book Intro to Ruby Development, I want to see the sub-topics for Iteration under Chapter Ruby Basics. However, I am only able to see one sub-topic because the list isn't scrollable.

Files not downloading to .atom folder or showing in file tree (ttt-2-board-rb-q-000)

I'm using Atom in the Learn IDE on Windows 10. I'm a very new student, only a few lessons in.

  1. Read the 'Tic Tac Toe Board' lesson at learn.co
    (https://learn.co/tracks/intro-to-ruby-development/ruby-basics/variables/tic-tac-toe-board)
  2. Open IDE (up to date, as far as I know, downloaded about a week ago)
  3. Type learn open into the command line.

Expected behavior: Current lesson is forked, bundled and opened. The .atom\ folder receives the lesson for the files, and the filetree is updated. The user's working directory is changed to the lesson folder.

*Actual Behavior: Current lesson(lab) is not downloaded into the labs folder. The filetree is not updated. However, the user's working directory is changed�, and pwd returns a location that seemingly does not exist.

I'm new to writing bug reports, but I hope this is usable. Thanks!

2016-04-26

Issues with atom

Cannot get IDE to fork code anymore... not even able to type into console...

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.