summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGentoo <installgentoo@endianness.com>2022-07-23 00:17:50 +1000
committerGentoo <installgentoo@endianness.com>2022-07-23 00:17:50 +1000
commitc0324b80b63f5ed0be71f37bffc1b6bf74745c80 (patch)
treefb7abe24235779b2c3b99f374b124773f1f57f81
parent922721e91ba7c67de5336fa7636f9d8c1c655fbc (diff)
downloadtic-tac-toe-master.tar.gz
tic-tac-toe-master.tar.bz2
tic-tac-toe-master.zip
trivial changes and properly licensedHEADmaster
-rw-r--r--LICENSE (renamed from LICENCE)0
-rw-r--r--Makefile2
-rw-r--r--main.c36
3 files changed, 27 insertions, 11 deletions
diff --git a/LICENCE b/LICENSE
index f288702..f288702 100644
--- a/LICENCE
+++ b/LICENSE
diff --git a/Makefile b/Makefile
index 154d954..94d4475 100644
--- a/Makefile
+++ b/Makefile
@@ -6,5 +6,5 @@ OBJ = main.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
-out: $(OBJ)
+tic-tac-toe: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS)
diff --git a/main.c b/main.c
index 93a71c2..6731ed7 100644
--- a/main.c
+++ b/main.c
@@ -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