C Programming

Hey Anons. I need major help! I need to write a program that checks win conditions for tic tac toe using a string from the user. Please help me or point me in the right direction. Thanks Anons.

Attached: Screen Shot 2017-07-29 at 9.42.24 PM.png (863x551, 84K)

Other urls found in this thread:

asciitable.com/.
youtu.be/tas0O586t80
twitter.com/SFWRedditGifs

google it.

add all chars together, if they sum to a specific value: win condition set, etc...

install c++

What is the content of the strings? What do they represent?

This. Give a few examples of strings to work with.

something like xoxoxox

If using ascii, do something like Each letter is a value asciitable.com/. If the user enters capital letters, just force them to lowercase values when calculating the math to make it easier.

alright thank you

3 spaces indent
why
it should be 8

pft i use 16

op here. So what if i wanted to do a win code for something like
[x,o,x]
[o,x,o]
[x,o,o]
and then say some like player x has won. Would it be a shit ton of if and else statements?

just make a pseudo multi dimensional array
check edge cases so you know not to seg fault
and then for each cell check one in each direction (with a for loop), if the next cell is the same recurse to that cell.

Set flags in separate array so as to not double check.

This isn't hard user.

sorry man. just my second semester programming.

/*
* all the things that pretain to testing if `player' has won
* these functions are ment to operate
* on a `grid' object of arburtrary size
*/
#include
#include "grid.h"

bool testCol(int col,int player ){ //on 'player' not having a win in col returns 1
int i;
int count = 0;
for(i = 0; i < NUMROW; i++){
if(grid[i][col] == player){
count++;
}
}
if(count == 3){
return 1;
} else {
return 0;
}
}
bool testRow(int row,int player ){ //on 'player' not having a win in row returns 1
int i;
int count = 0;
for(i = 0; i < NUMCOL; i++){
if(grid[row][i] == player){
count++;
}
}
if( count == 3){
return 1;
} else {
return 0;
}
}
/*
*best way to make this not edge alligned
*would be accessing the grid as a
*1 dimentional array and using an offset
*with a multiple reliant of the size of the grid
*/
bool testDiagUp(int player){
int i, j;
int count = 0;
for(i = 0,j = 0; i < NUMROW; i++,j++){
if(grid[i][j] == player){
count++;
}
}
if( count == 3) {
return 1;
} else {
return 0;
}
}
bool testDiagDown(int player){
int i, j;
int count;
for(i = NUMROW - 1, j = 0; i > 0; i--,j++){
if(grid[i][j] == player){
count++;
}
}
if( count == 3 ) {
return 1;
} else {
return 0;
}
return 1;
}

bool winnerTest(int player){ //return true on 'player' win
int i;
for(i = 0; i < NUMCOL; i++){
if(testCol(i,player)) {
return 1;
}
}
for(i = 0; i < NUMROW; i++){
if(testRow(i,player)) {
return 1;
}
}
if(testDiagUp(player)) {
return 1;
}
if(testDiagDown(player)) {
return 1;
}
return 0;
}


arbitrary size testing in c++ if its any help.

Thanks user! I can understand a good amount. C is my first programming language.

I bet that's a oneliner on Haskell.

Attached: 1549076973387.gif (225x213, 701K)

sadly I know no functional languages.
I've got C, C++, and shitty python for data analysis, that's it.

That being said I'm pretty sure I could write better... I just felt like doing anons homework instead of doing anything productive...

don't use gets(), that's a massive security vulnerability.

You just have 8 win conditions total.
That's 8 for loops checking for 3 consecutive symbols. If they are consecutive, return the last symbol to know who won.

Hmm...

Attached: smug wojak rust.png (767x639, 109K)

Go back to your corner

Learn matrix math.

youtu.be/tas0O586t80

Attached: segfaulting cnile.png (627x722, 114K)

We did fractals and recursion on like second month of first semester in sepples what kind of uni is teaching tic tac toe on 2nd semester

Attached: 1445972464054.jpg (482x427, 36K)

Let a 9-element char array represent the current board.
Then simply make a hash table of all winning states and check against the current board.

see

>what kind of uni is teaching tic tac toe on 2nd semester
this is the same shit I had to put up with at the university of Texas of the permian basin in a class full of brainlets
the cirriculum has to be easy enough in order to prevent classes from getting canceled from retards changing majors

This is why I feel confident in my STEM job security.

How long will Jow Forums continue doing kids homework for them?