• Advertisement
Sign in to follow this  

Tic-Tac-Toe Winning proof?

This topic is 4772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, I've spent a few minutes googling without turning anything really useful up, so... While I have my own idea of how to prove that someone has won the game, what are your ideas on proving a win?

Share this post


Link to post
Share on other sites
Advertisement
I ment as far as storing and proving mathmatically/logicaly in programming. This IS a programming forum, so I sort of figured I wouldn't have to state that part of the question.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"Tic Tac Toe Board (Gray is the actual board shown in the game)

Numbers: 0 1 2

0 4 9 2
1 3 5 7
2 8 1 6

By looking at the table above, you will initialize all of the numbers above in the multi-dimensional array. If you add the three numbers in vertical or horizontal or diagonal, the results will be 15. So, have a function to the do the calculation for that. Whichever player put the X or O in one of the slots in the table, you will then assign that number appropriately to that user and show the X or O in the table instead of number."

Maybe this will work for you :D

Share this post


Link to post
Share on other sites
Tic-tac-toe isn't a particularly big game. You could just search all possible moves from the current board position and verify that they all lead to a win for the same person.

Share this post


Link to post
Share on other sites
The board is 3x3, there are 8 winning positions for each side. Testing each individually isn't overwhelming.

Share this post


Link to post
Share on other sites
I wrote this:


#include <iostream>
#define C(v) cout<<(v?v==X?'X':'O':'.')
using namespace std;enum P{N,X,O};P p=O,b[9],c;int d
[]={0,3,1,3,2,3,0,1,3,1,6,1,0,4,2,2},t,*u;int main()
{for(;;){y:for(t=0;t<9;++t)t=N;for(;;){z:for(t=0;
t<9;++t)C(t)<<((t+1)%3?' ':'\n');p=p==X?O:X;for(;
;){C(p)<<", enter your move (1-9): ";cout.flush();cin
.sync();t=cin.get()-'1';t=t%3+3*(2-t/3);if(t>-1&&t<9
&&!t)break;}t=p;for(u=d;u<d+16;u+=2)if((c=b[*u
]))for(t=1;t<3;)if(c!=b[*u+t*u[1]])break;else if(++t
>2){C(c)<<" Wins!\n";goto y;}for(t=0;t<9;++t)if(!t[b
])goto z;cout<<"Draw!\n";goto y;}}}



It's a little known fact that by using as little white space as possible and using one character variable names your programs will run faster.*

*This is a lie, it in fact just makes it harder to read.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement