diff options
author | Gentoo <installgentoo@endianness.com> | 2022-07-23 00:17:50 +1000 |
---|---|---|
committer | Gentoo <installgentoo@endianness.com> | 2022-07-23 00:17:50 +1000 |
commit | c0324b80b63f5ed0be71f37bffc1b6bf74745c80 (patch) | |
tree | fb7abe24235779b2c3b99f374b124773f1f57f81 | |
parent | 922721e91ba7c67de5336fa7636f9d8c1c655fbc (diff) | |
download | tic-tac-toe-master.tar.gz tic-tac-toe-master.tar.bz2 tic-tac-toe-master.zip |
-rw-r--r-- | LICENSE (renamed from LICENCE) | 0 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | main.c | 36 |
3 files changed, 27 insertions, 11 deletions
@@ -6,5 +6,5 @@ OBJ = main.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) -out: $(OBJ) +tic-tac-toe: $(OBJ) $(CC) -o $@ $^ $(CFLAGS) @@ -1,3 +1,19 @@ +/* Terrible winnable tic-tac-toe against the computer. + Copyright (C) 2021, 2022 Gentoo-libre Install + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> @@ -7,7 +23,7 @@ #include <time.h> #define clear() printf("\033[H\033[J") -//the board as a 1D array. It's global due to the want to easily access in from any function. +/* the board as a 1D array. It's global due to the want to easily access in from any function. */ char board[] ={"|---|---|---|\n| - | - | - |\n|---|---|---|\n| - | - | - |\n|---|---|---|\n| - | - | - |\n|---|---|---|\n"}; struct termios oldt,newt;//the struct used by the terminal mode changer. Global due to want of easy access from any function. int pos[3][3] = @@ -53,11 +69,11 @@ for (x=0;x<3;++x) Ocount = 0; } -//across topleft-bottomright +/* across topleft-bottomright */ if ((board[pos[0][0]] == 'X') && (board[pos[1][1]] == 'X') && (board[pos[2][2]] == 'X') ){goto Xwin;} if ((board[pos[0][0]] == 'O') && (board[pos[1][1]] == 'O') && (board[pos[2][2]] == 'O') ){goto Owin;} -//across bottomleft-topright +/* across bottomleft-topright */ if ((board[pos[2][0]] == 'X') && (board[pos[1][1]] == 'X') && (board[pos[0][2]] == 'X') ){goto Xwin;} if ((board[pos[2][0]] == 'O') && (board[pos[1][1]] == 'O') && (board[pos[0][2]] == 'O') ){goto Owin;} @@ -67,7 +83,7 @@ if ((board[pos[2][0]] == 'O') && (board[pos[1][1]] == 'O') && (board[pos[0][2]] goto skip;//Skip over the winning exit code -//exit here due to lack of want to exit 2(?) layers deep of loops +/* exit here due to lack of want to exit 2(?) layers deep of loops */ Xwin: printf("Pathetic.\n"); tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); exit(0); //return the terminal back to it's old state and exit Owin: printf("You win! (Good job)\n"); tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); exit(0); //return the terminal back to it's old state and exit @@ -247,12 +263,12 @@ skip: clear();//clear the terminal int main(int argc, char *argv[]) { if (argc > 1) -{ -printf("Usage: %s\n\n", argv[0]); -printf("Controls:\nArrow keys to move cursor.\nPress any other key to take a move.\n\n"); -printf("I am aware that this is badly written.\n"); -exit(0); -} + { + printf("Usage: %s\n\n\ + Controls:\nArrow keys to move cursor.\nPress any other key to take a move.\n\n\ + This in intentionally badly written.\n", argv[0]); + exit(0); + } srand(time(NULL));//seed a srandom number generator very poorly with the time(should only be done once) //modified is simply a copy of the board with the cursor written on it |