-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Well, it's a good time I don't push, so I don't remember what I chang…
…ed :P Tic Tac Toe: - AI action order changed from Oponent-2 -> AI-2 -> rest to AI-2 -> Oponent-2 -> rest, so AI see if itself wins before seeing if the oponente will win -Some corrections (nothing especific) Lig 4: -Some corrections (nothing especific) -There's a Run-time check error #2 when Ai looks for ties, somewhere, happens some times, some not Hang Man: -Made Rest: -Nothing
- Loading branch information
1 parent
e1e338a
commit 3db4e47
Showing
11 changed files
with
729 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#ifdef _WIN32 | ||
#define _CRT_SECURE_NO_WARNINGS 1 | ||
#include <windows.h> | ||
#else | ||
#include <termios.h> | ||
#include <unistd.h> | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#ifdef _WIN32 | ||
// Some old MinGW/CYGWIN distributions don't define this: | ||
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 | ||
#endif | ||
|
||
static HANDLE stdoutHandle, stdinHandle; | ||
static DWORD outModeInit, inModeInit; | ||
|
||
void setupConsole(void) { | ||
DWORD outMode = 0, inMode = 0; | ||
stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE); | ||
stdinHandle = GetStdHandle(STD_INPUT_HANDLE); | ||
|
||
if (stdoutHandle == INVALID_HANDLE_VALUE || stdinHandle == INVALID_HANDLE_VALUE) { | ||
exit(GetLastError()); | ||
} | ||
|
||
if (!GetConsoleMode(stdoutHandle, &outMode) || !GetConsoleMode(stdinHandle, &inMode)) { | ||
exit(GetLastError()); | ||
} | ||
|
||
outModeInit = outMode; | ||
inModeInit = inMode; | ||
|
||
// Enable ANSI escape codes | ||
outMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | ||
|
||
// Set stdin as no echo and unbuffered | ||
inMode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT); | ||
|
||
if (!SetConsoleMode(stdoutHandle, outMode) || !SetConsoleMode(stdinHandle, inMode)) { | ||
exit(GetLastError()); | ||
} | ||
} | ||
|
||
void restoreConsoleMode(void) { | ||
if (!SetConsoleMode(stdoutHandle, outModeInit) || !SetConsoleMode(stdinHandle, inModeInit)) { | ||
exit(GetLastError()); | ||
} | ||
} | ||
|
||
void restoreConsole(void) { | ||
// Reset colors | ||
printf("\x1b[0m"); | ||
|
||
// Reset console mode | ||
if (!SetConsoleMode(stdoutHandle, outModeInit) || !SetConsoleMode(stdinHandle, inModeInit)) { | ||
exit(GetLastError()); | ||
} | ||
} | ||
#else | ||
|
||
static struct termios orig_term; | ||
static struct termios new_term; | ||
|
||
void setupConsole(void) { | ||
tcgetattr(STDIN_FILENO, &orig_term); | ||
new_term = orig_term; | ||
|
||
new_term.c_lflag &= ~(ICANON | ECHO); | ||
|
||
tcsetattr(STDIN_FILENO, TCSANOW, &new_term); | ||
} | ||
|
||
void restoreConsole(void) { | ||
// Reset colors | ||
printf("\x1b[0m"); | ||
|
||
// Reset console mode | ||
tcsetattr(STDIN_FILENO, TCSANOW, &orig_term); | ||
} | ||
#endif | ||
|
||
void getCursorPosition(int* row, int* col) { | ||
printf("\x1b[6n"); | ||
char buff[128]; | ||
int indx = 0; | ||
for (;;) { | ||
int cc = getchar(); | ||
buff[indx] = (char)cc; | ||
indx++; | ||
if (cc == 'R') { | ||
buff[indx + 1] = '\0'; | ||
break; | ||
} | ||
} | ||
sscanf(buff, "\x1b[%d;%dR", row, col); | ||
fseek(stdin, 0, SEEK_END); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#pragma once | ||
|
||
#include <stdio.h> | ||
|
||
enum Colors { | ||
RESET_COLOR, | ||
BLACK_TXT = 30, | ||
RED_TXT, | ||
GREEN_TXT, | ||
YELLOW_TXT, | ||
BLUE_TXT, | ||
MAGENTA_TXT, | ||
CYAN_TXT, | ||
WHITE_TXT, | ||
|
||
BLACK_BKG = 40, | ||
RED_BKG, | ||
GREEN_BKG, | ||
YELLOW_BKG, | ||
BLUE_BKG, | ||
MAGENTA_BKG, | ||
CYAN_BKG, | ||
WHITE_BKG | ||
}; | ||
|
||
enum ClearCodes { | ||
CLEAR_FROM_CURSOR_TO_END, | ||
CLEAR_FROM_CURSOR_TO_BEGIN, | ||
CLEAR_ALL | ||
}; | ||
|
||
void setupConsole(void); | ||
void restoreConsoleMode(void); | ||
void restoreConsole(void); | ||
void getCursorPosition(int* row, int* col); | ||
|
||
static inline void setTextColorRGB(int r, int g, int b) { | ||
printf("\x1b[38;2;%d;%d;%dm", r, g, b); | ||
} | ||
|
||
static inline void setTextColor(int code) { | ||
printf("\x1b[%dm", code); | ||
} | ||
|
||
static inline void setTextColorBright(int code) { | ||
printf("\x1b[%d;1m", code); | ||
} | ||
|
||
static inline void setBackgroundColorRGB(int r, int g, int b) { | ||
printf("\x1b[48;2;%d;%d;%dm", r, g, b); | ||
} | ||
|
||
static inline void setBackgroundColor(int code) { | ||
printf("\x1b[%dm", code); | ||
} | ||
|
||
static inline void setBackgroundColorBright(int code) { | ||
printf("\x1b[%d;1m", code); | ||
} | ||
|
||
static inline void resetColor(void) { | ||
printf("\x1b[%dm", RESET_COLOR); | ||
} | ||
|
||
static inline void clearScreen(void) { | ||
printf("\x1b[%dJ", CLEAR_ALL); | ||
} | ||
|
||
static inline void clearScreenToBottom(void) { | ||
printf("\x1b[%dJ", CLEAR_FROM_CURSOR_TO_END); | ||
} | ||
|
||
static inline void clearScreenToTop(void) { | ||
printf("\x1b[%dJ", CLEAR_FROM_CURSOR_TO_BEGIN); | ||
} | ||
|
||
static inline void clearLine(void) { | ||
printf("\x1b[%dK", CLEAR_ALL); | ||
} | ||
|
||
static inline void clearLineToRight(void) { | ||
printf("\x1b[%dK", CLEAR_FROM_CURSOR_TO_END); | ||
} | ||
|
||
static inline void clearLineToLeft(void) { | ||
printf("\x1b[%dK", CLEAR_FROM_CURSOR_TO_BEGIN); | ||
} | ||
|
||
static inline void moveUp(int positions) { | ||
printf("\x1b[%dA", positions); | ||
} | ||
|
||
static inline void moveDown(int positions) { | ||
printf("\x1b[%dB", positions); | ||
} | ||
|
||
static inline void moveRight(int positions) { | ||
printf("\x1b[%dC", positions); | ||
} | ||
|
||
static inline void moveLeft(int positions) { | ||
printf("\x1b[%dD", positions); | ||
} | ||
|
||
static inline void moveTo(int row, int col) { | ||
printf("\x1b[%d;%df", row, col); | ||
} | ||
|
||
static inline void saveCursorPosition(void) { | ||
printf("\x1b%d", 7); | ||
} | ||
|
||
static inline void restoreCursorPosition(void) { | ||
printf("\x1b%d", 8); | ||
} |
Oops, something went wrong.