Basic C++ Tic Tac Toe

Posts 1–8 of 8 · Page 1 of 1
Basic C++ Tic Tac Toe
Hey all, I'm making tic tac toe in C++ and have a little trouble. I have some code but it isn't with me right now. The problem is, I have to make it very basic. I can only use if-then statements, cases, loops, and the iostream and string libraries since that is all we have done at school. I have the player's turn but need some help on the computer so it doesn't just pick a random number and go there. It needs to be at lease semi-intelligent. Any ideas?
You could assign points.

example:
Your bot is o, and it's currently the bots turn.

x.x
...
.o.

highlighted in bold is a spot where your opponent could place his x next turn to win, so lets upgrade that amount of points
point table(most useful has highest number, 2 points are given for blocking a possible win for the opponent, and 1 point is given for opening up a win opportunity for yourself.)

030
010
101

so the bot picks the highest scored spot

xox
.x.
.o.

opponent places it in the centre...
new scoretable:
000
000
303

ah, two times 3 points he wins!

another example, where it would be a tie:
x.x
...
o..

020
000
011

xox
.x.
o..

000
000
012

xox
.x.
oxo

000
000
000

doesnt matter where it places it, coz it's a tie
could assign 3 points to blocking opponent, 2 to opening up a win situation for yourself, 1 for every possible move and 0 for not possible.
My approach would be properly restricting movements (making sure I implemented the 3x3 restriction properly) and setting flags for positions by their directional type (naming all those spaces with proper variable to have set as flags)... And work out an (probably extremely simple in this case) algorithm for the computer to move on based on the setting of those flags. But while the flag and Algorithmic approach might seem more intelligent having your bot move according to how Hell_Demon describes is probably simple enough, plus it might be faster for a situation as simple as this.
~
I would make it so that you never win, and the bot always causes a tie. cuz tic-tac-toe is too easy.
Quote Originally Posted by why06 View Post
I would make it so that you never win, and the bot always causes a tie. cuz tic-tac-toe is too easy.
+1 for opening up a move for yourself
+2 for blocking the opponent of winning

x.x
...
o..

020
000
011

xox
...
o.x

000
032
010

f*ck yeah, lost there's always a way to win as long as the center isnt taken by the time of your 2nd move.
Quote Originally Posted by Hell_Demon View Post
+1 for opening up a move for yourself

f*ck yeah, lost there's always a way to win as long as the center isnt taken by the time of your 2nd move.
Everytime I play tic tac toe I take the center first. (Instant draw)

Now what's fun is That got old so I made up multiplayer tic tac toe, where u add an extra row and column for everyone playing. Now that's fun! YOu can make up strategies and everything, plus its impossible to defend against the first player urself since the board is so huge makes for some pretty interesting gameplay, because if u just choose not to help contain player 1, but instead go for the win you usually end up losing next round.
A tie is inevitable isn't it, if they both play a perfect game.... I guess in that sense it's interesting, it would be impossible for success, his teacher must be on the dense side....
~
why for that kind of stuff just play connect four!~
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?