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.
C Programming
Other urls found in this thread:
asciitable.com
youtu.be
twitter.com
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
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.
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...
Go back to your corner
Learn matrix math.
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
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?