/*****
Name:Zackery Breeland Date Assigned:April 7, 2009
Course:CSE 1233 Date Due:April 17, 2009
File Name: zlb12Lab8.c
Program Description:
To create a tick tack toe game against a computer.
*****/
Code:
#include <stdio.h>
#include <stdlib.h>
void Board();
void Winner();
int selection(char, int);
int boxArray[3][3];
int box1, box2;
char square[3][3];
char winner;
int Player = 0;
int main()
{
int x, y;
int box1 = 0;
int box2 = 0;
int Player;
int boxValue = 0;
char square[box1][box2];
Board();
/*Choose Square*/
while(winner = ' ')
{
printf("%c", winner);
if(Player == 1)
{
printf("X");
printf("Choose a square position: ");
printf("Row: ");
scanf("%d", &box1);
printf("Column: ");
scanf("%d", &box2);
if(selection(square[3][3], Player) == 1)
Player = 1;
else
Player = 2;
}
else
{
printf("O");
printf("Choose a square position: ");
printf("Row: ");
scanf("%d", &box1);
printf("Column: ");
scanf("%d", &box2);
if(selection(square[3][3], Player) == 1)
Player = 2;
else
Player = 1;
}
}
Board();
Winner();
return 0;
}
/*Selection*/
int selection(char square[box1][box2], int player)
{
if(square[box1 - 1][box2 - 1] == '\0' && (player == 1 || player == 0))
{
square[box1 -1][box2 - 1] = 'x';
return 0;
}
else if(square[box1 - 1][box2 - 1] == '\0' && player == 2)
{
square[box1 -1][box2 -1] == 'o';
return 0;
}
else
return 1;
}
/*Board*/
void Board()
{
printf(" | | \n");
printf("%c |%c |%c \n", square[0][0], square[0][1], square[0][2]);
printf(" | | \n");
printf("___________\n");
printf(" | | \n");
printf("%c |%c |%c \n", square[1][0], square[1][1], square[1][2]);
printf(" | | \n");
printf("___________\n");
printf(" | | \n");
printf("%c |%c |%c \n", square[2][0], square[2][1], square[2][2]);
printf(" | | \n");
}
/*Who Won*/
void Winner()
{
if (square[0][0] == 'x' && square[0][1] = 'x' && square[0][2] = 'x')
winner = 'x';
else if (square[1][0] == 'x' && square[1][1] == 'x' && square[1][2] == 'x')
winner = 'x';
else if (square[2][0] == 'x' && square[2][1] == 'x' && square[2][2] == 'x')
winner = 'x';
else if (square[0][0] == 'x' && square[1][0] == 'x' && square[2][0] == 'x')
winner = 'x';
else if (square[0][1] == 'x' && square[1][1] == 'x' && square[2][1] == 'x')
winner = 'x';
else if (square[0][2] == 'x' && square[1][2] == 'x' && square[2][2] == 'x')
winner = 'x';
else if (square[0][0] == 'x' && square[1][1] == 'x' && square[2][2] == 'x')
winner = 'x';
else if (square[0][2] == 'x' && square[1][1] == 'x' && square[2][0] == 'x')
winner = 'x';
else if (square[0][0] == 'o' && square[0][1] == 'o' && square[0][2] == 'o')
winner = 'o';
else if (square[1][0] == 'o' && square[1][1] == 'o' && square[1][2] == 'o')
winner = 'o';
else if (square[2][0] == 'o' && square[2][1] == 'o' && square[2][2] == 'o')
winner = 'o';
else if (square[0][0] == 'o' && square[1][0] == 'o' && square[2][0] == 'o')
winner = 'o';
else if (square[0][1] == 'o' && square[1][1] == 'o' && square[2][1] == 'o')
winner = 'o';
else if (square[0][2] == 'o' && square[1][2] == 'o' && square[2][2] == 'o')
winner = 'o';
else if (square[0][0] == 'o' && square[1][1] == 'o' && square[2][2] == 'o')
winner = 'o';
else if (square[0][2] == 'o' && square[1][1] == 'o' && square[2][0] == 'o')
winner = 'o';
else
printf("CAT");
if(winner == 'x')
{
printf("x wins");
return;
}
if(winner == 'o')
{
printf("o wins");
return;
}
}
// After this point the program gives me a non-lvalue in assignment on line 118 in void Winner(). Does anyone know what is wrong. I just can't get this thing to work.