Tic-Tac-Toe victory checker that scales with the table

HI, I'm having trouble making a victory checker that scales up or down with the table size automatically. It's suppose to have 4 check one on the horizontal, one on the vertical, one in the upper diagonal, and one in the lower diagonal. I can't seem tho get the checks right if anyone could help it would be much appreciated.

Edit: win requirement is 3 because you need 3 X's or O's in a row to win.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  int VictoryCheck(char checkMe[ROWS][COLS], int winRequirement) {
	int blankSeen = FALSE;
	int XPresents = FALSE;
	int OPresents = FALSE;
	int counterOOB = 0;
	int counterX = 0;
	int counterO = 0;

	// Is there a blank space on the board?
	for (int i = 0; i < ROWS; i++) {
		for (int j = 0; j < COLS; j++) {
			if (checkMe[i][j] == BLANK)
				blankSeen = TRUE;
		}
	}

	// Check to see if X or O present victory.
	for (int i = 0; i < ROWS; i++) {
		for (int j = 0; j < COLS; j++) {
			int n = 1;
			// To check and see if one of the tokens is presenting
			//  a victory, write a loop that moves along the
			//  spots indicated by the direction of the scan.  As
			//  you move to each spot, make sure it is logically
			//  legal on the board.  If you see the same symbol
			//  at each point in the scan and the symbol isn't a
			//  blank space, you can conclude that token has
			//  presented victory and the appropriate flag
			//  (XPresents, OPresents) can be set to TRUE.

			// Scan in a "horizontal" direction. 
			for (int x = 0; x <= checkMe[i][x]; x++) {
				//scans the row for either X or O
		         	if (checkMe[i][x] == MARKONE) {
					counterX += 1;
				}//resets the counter if the marker is different or a space is detected
				else if (checkMe[i][x] == BLANK || checkMe[i][x] == MARKTWO && counterX > 0) {
					counterX = 0;
			}

				//checks for O
				if (checkMe[i][x] == MARKTWO) {
					counterO += 1;
				}//resets the counter if the marker is different or a space is detected
				else if (checkMe[i][x] == BLANK || checkMe[i][x] == MARKONE && counterO > 0) {
				counterO = 0;
				}
				n += 1;
			}

			//check results
			if (counterX == winRequirement) {
				XPresents = TRUE;
			}
			else if (counterO == winRequirement) {
				OPresents = TRUE;
			}

			//prints message
			if (XPresents == TRUE) {
				printf("\nX IS PRESENTING");
			}
			else if (OPresents == TRUE) {
				printf("\nO IS PRESENTING");
			}
			// Scan in a "vertical" direction. 
			for (int y = 0; y <= checkMe[y+n][j]; y++) {
				if (checkMe[i][y + n] == MARKONE) {
					counterX += 1;
				}//resets the counter if the marker is different or a space is detected
				else if (checkMe[i][y + n] != MARKONE && counterX > 0) {
					counterX = 0;
				}

				//checks for O
				if (checkMe[i][y + n] == MARKTWO) {
					counterO += 1;
				}//resets the counter if the marker is different or a space is detected
				else if (checkMe[i][y + n] != MARKTWO && counterO > 0) {
					counterO = 0;
				}
				n += 1;
			}

				//check results
			if (counterX == winRequirement) {
				XPresents = TRUE;
			}
			else if (counterO == winRequirement) {
				OPresents = TRUE;
			}

			//prints message
			if (XPresents == TRUE) {
				printf("\nX IS PRESENTING");
			}
			else if (OPresents == TRUE) {
				printf("\nO IS PRESENTING");
			}

			// Scan in a "diagonal-up" direction.
		
			// Scan in a "diagonal-down" direction.

		}
	}
	return 0;
}
Last edited on
It seems overly complicated (what is a "win requirement?"). Here's a simple example of checking for a horizontal win.
1
2
3
4
5
6
7
8
9
10
11
12
// Check board for a (horz.) win. Returns winning char or '-'.
char check(char b[][COLS]) {
    int r, c;
    for (r = 0; r < size; r++) {
        for (c = 1; c < size; c++)
            if (b[r][c] != b[r][0])
                break;
        if (c == size)
            return b[r][0];
    }
    return '-';   // tie
}

Last edited on
Topic archived. No new replies allowed.