473,396 Members | 1,971 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,396 software developers and data experts.

Writing code for a tic tac toe game in C++

I was wondering if anyone knows how to write a tic tac toe game in c++?

Nov 17 '06 #1
14 14377
<ha*********@hotmail.comwrote:
>I was wondering if anyone knows how to write a tic tac toe game in c++?
I would expect that any C++ programmer who knew the rules of tic tac toe
could write such a program.
Nov 17 '06 #2
No, sadly no one has yet been able to solve the so called 'tic-tac-toe'
paradox. Despite my best efforts during 12 years of research, I have
still not come up with a satisfactory solution. There is currently a
group of scientists at MIT, who claim to be close to a solution, you
may want to contact them at do*******@homework.com.

On Nov 17, 10:16 am, harbinty...@hotmail.com wrote:
I was wondering if anyone knows how to write a tic tac toe game in c++?
Nov 17 '06 #3
<ha*********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
>I was wondering if anyone knows how to write a tic tac toe game in c++?
Yes.
Nov 17 '06 #4

Jim Langston wrote:
<ha*********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
I was wondering if anyone knows how to write a tic tac toe game in c++?

Yes.
I got to do this for a final in my C++ class and to be honest i'm
completely clueless. Could you please enlighten me?

Nov 17 '06 #5
* ha*********@hotmail.com:
Jim Langston wrote:
><ha*********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googleg roups.com...
>>I was wondering if anyone knows how to write a tic tac toe game in c++?
Yes.

I got to do this for a final in my C++ class and to be honest i'm
completely clueless. Could you please enlighten me?
Start by writing a "guess a random integer number by being informed
whether each guess is too low or high or correct" program A, just to get
a feel for how it is to write an interactive program.

Then write a program B that systematically solves this problem on its
own, acting like the user; no theory needed, just common sense.

Then write a program C that let's the user solve a simple problem such
as crossing a river in a boat with limited capacity (two most popular
variants being 3 nuns and 3 cannibals, and farmer+goat+wolf+wheat).

Then write a program D that solves this problem on its own; you'll need
to look into min-max algorithm.

Then write a program E that let's the user place dots and crosses on the
tic-tac-toe board.

Then write a program F where the user plays tic-tac-toe against the
computer (since 3x3 tic-tac-toe is easily analyzed completely on paper
there's no real need to use e.g. min-max, but probably easiest to do).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 17 '06 #6
* Alf P. Steinbach:
* ha*********@hotmail.com:
>Jim Langston wrote:
>><ha*********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.google groups.com...
I was wondering if anyone knows how to write a tic tac toe game in c++?
Yes.

I got to do this for a final in my C++ class and to be honest i'm
completely clueless. Could you please enlighten me?

Start by writing a "guess a random integer number by being informed
whether each guess is too low or high or correct" program A, just to get
a feel for how it is to write an interactive program.

Then write a program B that systematically solves this problem on its
own, acting like the user; no theory needed, just common sense.

Then write a program C that let's the user solve a simple problem such
as crossing a river in a boat with limited capacity (two most popular
variants being 3 nuns and 3 cannibals, and farmer+goat+wolf+wheat).

Then write a program D that solves this problem on its own; you'll need
to look into min-max algorithm.
I meant, search algorithms. min-max is for program F.

Then write a program E that let's the user place dots and crosses on the
tic-tac-toe board.

Then write a program F where the user plays tic-tac-toe against the
computer (since 3x3 tic-tac-toe is easily analyzed completely on paper
there's no real need to use e.g. min-max, but probably easiest to do).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 17 '06 #7
On 16 Nov 2006 19:33:30 -0800 in comp.lang.c++, ha*********@hotmail.com
wrote,
>I got to do this for a final in my C++ class and to be honest i'm
completely clueless. Could you please enlighten me?
How did you manage the previous assignments? Be advised that it's
against policy in almost all online groups to do your work _for_ you.
Show what you have got done so far. Describe where you are stuck.
Ask _specific_ questions.

This issue is covered in Marshall Cline's C++ FAQ. See the topic
"# [5.2] How do I get other people to do my homework problem for me?"
It is always good to check the FAQ before posting. You can get the FAQ
at:
http://www.parashift.com/c++-faq-lite/

See the welcome message posted twice per week in comp.lang.c++ under the
subject "Welcome to comp.lang.c++! Read this first." or available at
http://www.slack.net/~shiva/welcome.txt

Nov 17 '06 #8
<ha*********@hotmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
>
Jim Langston wrote:
><ha*********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googleg roups.com...
>I was wondering if anyone knows how to write a tic tac toe game in c++?

Yes.

I got to do this for a final in my C++ class and to be honest i'm
completely clueless. Could you please enlighten me?
This is your final assignemtn and you're clueless? Didn't you do any of the
homework the instructor gave you? I find it hard to believe that you could
go through an entire class on c++ and not know how to do this.

Can you display a tic tac toe board in C++? Write code to just display a
tic tac toe board (without X's or O's).

Okay, now you're going to need to put in X's, O's or blanks depending on...
what? Hmm.. seems you're going to have to store the move for each square.
Lets look at a tic tac toe board:

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

It seems to be 3 by 3. How would you store in memory 3 elements by 3
elements? There are a few ways (vector of vector, 9 variables, a 2d array).
Decide which way you want to go (for something simple like this I might
choose a simple 2d array, I.E. char Board[3][3]; Although you might want
std::vector<std::vector<char Board; You decide. There is no "right"
answer, though some may argue that a vector should always be used instead of
a static array, I'm not one of them.

Okay, now you have storage, intialize them to spaces.

Now fill in some X's and O's in your array, and get them to print out in the
board.

Okay, so there are 3 things that programs do, Input, processing and output.
So we have the output so far. Lets look at the input. Write a
class/method/function/routine to accept a players move. You decide how the
player picks a square. Common solutions are 1 thorugh 9, or 1,1 through
3,3.

But you'll need processing. Is the players move legal? Does it fall within
bounds? Is there already a move there? Did the player win?

Alternate players.

Okay, once you're done, you have a tic tac toe game.

Now you can go farther, have the player play against the computer.

Show me code, when you get stuck ask.
Nov 17 '06 #9
VJ
Jeremy Jurksztowicz wrote:
No, sadly no one has yet been able to solve the so called 'tic-tac-toe'
paradox. Despite my best efforts during 12 years of research, I have
still not come up with a satisfactory solution. There is currently a
group of scientists at MIT, who claim to be close to a solution, you
may want to contact them at do*******@homework.com.

On Nov 17, 10:16 am, harbinty...@hotmail.com wrote:
>>I was wondering if anyone knows how to write a tic tac toe game in c++?

Invalid email address. You probably meant Do***@top.post
Nov 17 '06 #10
ha*********@hotmail.com wrote:
I was wondering if anyone knows how to write a tic tac toe game in c++?
Yes.
Nov 17 '06 #11
Alf P. Steinbach <al***@start.nowrote:
Then write a program E that let's the user place dots and crosses on the
tic-tac-toe board.

Then write a program F where the user plays tic-tac-toe against the
computer (since 3x3 tic-tac-toe is easily analyzed completely on paper
there's no real need to use e.g. min-max, but probably easiest to do).
Next write a program G: Global Thermonuclear War.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Nov 17 '06 #12
ha*********@hotmail.com wrote:
Jim Langston wrote:
<ha*********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
>I was wondering if anyone knows how to write a tic tac toe game in c++?
Yes.

I got to do this for a final in my C++ class and to be honest i'm
completely clueless. Could you please enlighten me?
Repeat after me:

Want fries with that?

Socks

Nov 17 '06 #13
I am not sure if you are still looking for a solution but I have
written for you to download at

http://www.go4expert.com/forums/showthread.php?t=353

Thanks
Shabbir

On Nov 17, 7:16 am, harbinty...@hotmail.com wrote:
I was wondering if anyone knows how to write a tic tac toe game in c++?
Nov 18 '06 #14
You should be able to find a lot of information on it on the web. Try
www.google.com e.g.

Nov 18 '06 #15

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

Similar topics

5
by: Lt | last post by:
Hello, I'm gonna write my first 3D multiplayer game using DirectPlay, VC++ ..NET 2002. I've done tutorials supplied along with DXSDK Then I wanted to use the DirectX AppWizard but it produced over...
0
by: Michael Goettsche | last post by:
Hi there, for a project in our computer science lessons at school we decided to write a client/server based battleship like game . I know this game could be written without a server, but the...
4
by: Bern | last post by:
This is the first time I'm writing a network multiplayer card game. And the model I have thought of : The host creates a new thread and this thread listens for clients. When a client is...
3
by: Oberon | last post by:
How do I deal with this? I am getting an error for each get in the Game class (see code below). In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I...
22
by: JoeC | last post by:
I am working on another game project and it is comming along. It is an improvment over a previous version I wrote. I am trying to write better programs and often wonder how to get better at...
1
by: lenest | last post by:
I need help writing a program.... You are to write a python program to accomplish the following: a.. Play a dice game of Craps using a random number generator to simulate the roll of the...
1
by: Olmar | last post by:
Hi, I am trying to write a version of the Hears card game. I can't figue out what is the best way to detect clicks on the cards. Using the cards.dll interface as described in tutorials like...
7
by: jacob navia | last post by:
There are some people here (let's call them "regulars" for short) that are always giving lessons to people about how easy is to write portable code, etc. They always point fingers at you telling...
4
by: KYAW KYAW OO | last post by:
Dear All, I am trying to write the xml file described as below XML for UnSelectedGameList.XML <UnSelectedGameList> <game id="1" name="A" picture=@E:\Games\1.png" isSelected="0"> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.