Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char a[3][3];
- int b[3][3];
- int cur = 0;
- int sn;
- void step() { // функция хода крестиком дял пользователя
- sn = 0;
- printf("Place X in (Enter number 1 to 9): ");
- do {
- scanf("%d",&sn);
- switch (sn) {
- case 1: if (b[0][0] != 0) sn = 0; break;
- case 2: if (b[0][1] != 0) sn = 0; break;
- case 3: if (b[0][2] != 0) sn = 0; break;
- case 4: if (b[1][0] != 0) sn = 0; break;
- case 5: if (b[1][1] != 0) sn = 0; break;
- case 6: if (b[1][2] != 0) sn = 0; break;
- case 7: if (b[2][0] != 0) sn = 0; break;
- case 8: if (b[2][1] != 0) sn = 0; break;
- case 9: if (b[2][2] != 0) sn = 0; break;
- default: break;
- }
- if (sn > 9 || sn < 1) {
- printf("\nYour number is not fit.\nTry to enter again: ");
- }
- } while (sn > 9 || sn < 1);
- printf("\n");
- printf("\n");
- switch (sn) {
- case 1: a[0][0] = 'X'; b[0][0] = 1; break;
- case 2: a[0][1] = 'X'; b[0][1] = 1; break;
- case 3: a[0][2] = 'X'; b[0][2] = 1; break;
- case 4: a[1][0] = 'X'; b[1][0] = 1; break;
- case 5: a[1][1] = 'X'; b[1][1] = 1; break;
- case 6: a[1][2] = 'X'; b[1][2] = 1; break;
- case 7: a[2][0] = 'X'; b[2][0] = 1; break;
- case 8: a[2][1] = 'X'; b[2][1] = 1; break;
- case 9: a[2][2] = 'X'; b[2][2] = 1; break;
- default: break;
- }
- }
- void botstep() {
- int CBS = 0;
- for (int h = 0; h != 3; h++) {
- for (int g = 0; g != 3; g++) {
- if (b[h][g] == 0 && CBS == 0) {
- b[h][g] = 2;
- a[h][g] = 'O';
- CBS = 1;
- }
- }
- }
- }
- void output() {
- for (int i = 0; i != 3; i++) {
- for (int j = 0; j != 3; j++) {
- printf("%c ",a[i][j]);
- }
- printf("\n");
- }
- printf("\n");
- }
- void checker() {
- if (b[0][0] == b[0][1] && b[0][1] == b[0][2])
- if (b[1][0] == b[1][1] && b[1][1] == b[1][2])
- if (b[2][0] == b[2][1] && b[2][1] == b[2][2])
- if (b[0][0] == b[1][0] && b[1][0] == b[2][0])
- if (b[0][1] == b[1][1] && b[1][1] == b[2][1])
- if (b[0][2] == b[1][2] && b[1][2] == b[2][2])
- if (b[0][0] == b[1][1] && b[1][1] == b[2][2])
- if (b[0][2] == b[1][1] && b[1][1] == b[2][0])
- }
- void win () {
- }
- int main() // основная функция
- {
- for (int i = 0; i != 3; i++) {
- for (int j = 0; j != 3; j++) {
- b[i][j] = 0;
- cur = cur + 1;
- a[i][j] = cur + '0';
- printf("%c ",a[i][j]);
- }
- printf("\n");
- }
- for (int i = 1; i != 10; i++) {
- if (i % 2 == 1) {
- if (i != 9) step();
- else {
- step();
- output();
- }
- }
- else {
- botstep();
- output();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement