Originally Posted by
Matticus
*TEXT*
Thanks! I see!
I have done that now. Now the program register the bots&my choise but it doesnt display. I think that it might be problem with the functions and has something to do with that I have void in the paranthesis "()" or what can the problem be? Sorry for asking tons of probably stupid questions but Im so glad that you experts can help a n00b like me! I really appretiate your help.
Code:
/* Info: */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define NUMBER_TO_WIN 3
#define PLAYER 'X'
#define BOT 'O'
// -----------------------------------------
// Functions-initiering.
// -----------------------------------------
void drawBoard();
int playerChoise();
int botChoise();
// -----------------------------------------
// Global variables
// -----------------------------------------
//char game[3][3]={{0}};
//int totalEntry =0,Row,Column;
// -----------------------------------------
// Main-functionen
// -----------------------------------------
int main()
{
char game[3][3]={{0}};
int totalEntry=0;
printf("Welcome to Tic Tac Toe!\n");
printf("What the board looks like:\n\n");
drawBoard(game);
while(totalEntry<=9)
{
playerChoise();
botChoise();
drawBoard(game);
}
printf("The game is over.");
getchar();
return 0;
}
// -----------------------------------------
// The function where the board draws.
// -----------------------------------------
void drawBoard(char game[3][3])
{
int Row,Column;
for ( Row = 0 ; Row < 3 ; Row++ )
{
for ( Column = 0 ; Column < 3 ; Column++ )
{
if(game[Row][Column] != 0)
{
printf( "|%c", game[Row][Column] );
}
else
{
printf("| ");
}
}
printf("|\n");
}
}
// -----------------------------------------
// The function where the bot makes its choise.
// -----------------------------------------
int botChoise()
{
char game[3][3];
int Row,Column,totalEntry;
// Infinite-loop
while (1)
{
Row = rand()%3;
Column = rand()%3;
// The loop breaks when the spot is empty. Then I want to write 'O' into that spot.
if (game[Row][Column] == 0 )
{
break;
}
}
//BOT is defined to the letter 'O'
game[Row][Column] = BOT;
totalEntry++;
return 0;
}
// -----------------------------------------
// Function where I choose a spot on the board.
// -----------------------------------------
int playerChoise(void)
{
char game[3][3];
int Row,Column,totalEntry;
// Infinite-loop
while (1)
{
printf("\nEnter row-number of your choise(1-3):\n");
scanf("%d", &Row);
printf("Enter column-number of your choise(1-3):\n");
scanf("%d", &Column);
Row = Row-1;
Column = Column-1;
if (game[Row][Column] == 0 )
{
break;
}
else
{
printf("That spot is taken. Try another one:\n");
}
}
game[Row][Column] = PLAYER;
totalEntry++;
return 0;
}