473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Tic Tac Toe Board

How who I go about printing a Tic Tac Toe Board that is 3 x 3<?.
Jul 22 '05 #1
3 1766
How is the board stored? If it's a two-dimensional array then it's as
simple as nested for loops.

Jul 22 '05 #2
In article <f2******************************@localhost.talkab outprogramming.com>,
tomakated <to*******@comcast.net> wrote:
How who I go about printing a Tic Tac Toe Board that is 3 x 3<?.


How about this?

cout << " | | \n"
<< "---+---+---\n"
<< " | | \n"
<< "---+---+---\n"
<< " | | \n";

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 22 '05 #3

"Jon Bell" <jt*******@presby.edu> wrote in message:
tomakated <to*******@comcast.net> wrote: How about this?

cout << " | | \n"
<< "---+---+---\n"
<< " | | \n"
<< "---+---+---\n"
<< " | | \n";


To generalize this a bit, if Tic Tac Toe boards are represented as instances of
vector< vector<char> >, you can do something like this:

#include <iostream>
#include <vector>
#include <boost/assign.hpp>
#include <boost/iostreams/format_lite.hpp>

int main()
{
using namespace std;
using namespace boost::io;
using namespace boost::assign;

typedef vector<char> row;
typedef vector<row> board;

board b =
list_of( list_of('X')(' ')('O') )
( list_of('O')('O')('X') )
( list_of('X')(' ')('X') );

std::cout << punctuate<row>(" ", " | ", " ")
<< punctuate< vector<_> >("", "\n---+---+---\n", "")
<< b;

}

Output (view with fixed-width font):

X | | O
---+---+---
O | O | X
---+---+---
X | | X

Here I'm using the new Boost Assign library to initialize the board, and my
Format Lite library to format it. (See
http://home.comcast.net/~jturkanis/format_lite/)

Of course, this might be using a sledge hammer to kill a mosquito -- or, to use
a phrase I am trying to popularize -- using a daisy-cutter to cut a daisy.

Jonathan


Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: delisonews | last post by:
I'm looking for a simple, filesystem-based message board. (No MySQL!) Something that I could include easily in my code: include '../inc/messageboard.php'; .... so that the board shows up at...
0
by: Mad Scientist Jr | last post by:
I'm not getting any answers on YAF's own board, so thought I'd ask here... how do you get YAF to work with >1 board? I clicked Admin and on the left, Boards, and we have created 3 boards *...
2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
2
by: Mark | last post by:
Hi, does anyone know of any *good* "job board" software which is available for purchase/ download. I did look @ the jobboard available from Ibuyspysolutions but do not really want to have to...
6
by: Supra | last post by:
i got board working using graphic window in vb.net but no controls adding to form. i am doing checker board game. when i clicked and moved the peg to another location(grid). but how do i get bitmap...
10
by: sam_cit | last post by:
Hi Everyone, I'm working on developing a chess game and i decided to use c++ for its object oriented approach. I have a bass class unit and is inherited to distinct number of units (like king,...
3
by: john | last post by:
I would like to view physical memory that is mapped to a pci board. I am using a tool called WinIO to try to create a virtual address to that physical memory. It works for both read and write of...
4
by: Hypnotik | last post by:
So I'm writing this program. I have the board constructed, and I'm having a problem making a move. At this point I just want to make a move, I'll work on whether it is a legal move after that. The...
8
by: PhongPham | last post by:
Hello, Info relate: OS : uclinux Platform : unix version 2.4.22 (or 2.4.26) Chip on board : ARM7 I want to get a python package on network to "make" in linux (Fedora core 1 or anything...
1
by: poopsy | last post by:
hi all, i'm trying out some examples on java..and i found this code where there is board and i cant find out what package to import to make this work, im getting error where there is "board".. i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.