on playing further, it feels like the ai is choosing completely randomly no matter what. here is my current code: 
```c
#include 
#include 
#include "raylib.h"
#include "string.h"

#define BOARD\_SIZE 3
#define CELL\_SIZE 100
#define SCREEN\_WIDTH (CELL\_SIZE \* BOARD\_SIZE)
#define SCREEN\_HEIGHT (CELL\_SIZE \* BOARD\_SIZE)

typedef enum
{
 EMPTY,
 PLAYER1,
 PLAYER2
} Cell;

Cell board[BOARD\_SIZE][BOARD\_SIZE];

int GetWinningDirection(int player);
bool CheckDraw();
void DrawBoard(bool gameOver, int winner);
void DrawWinMessage(int player);
void ResetBoard();

Vector2 GetMouseCell();
Vector2 AIGetMove();

int main()
{
 InitWindow(SCREEN\_WIDTH, SCREEN\_HEIGHT, "Tic Tac Toe");
 SetTargetFPS(60);
 ResetBoard();

 int currentPlayer = PLAYER1;
 bool gameOver = false;
 int winner = 0;

 while (!WindowShouldClose())
 {
 if (!gameOver)
 {
 Vector2 move = {-1, -1};
 if (currentPlayer == PLAYER1 && IsMouseButtonPressed(MOUSE\_LEFT\_BUTTON))
 {
 move = GetMouseCell();
 }
 else if (currentPlayer == PLAYER2)
 {
 move = AIGetMove();
 }

 if (move.x != -1 && move.y != -1 && board[(int)move.y][(int)move.x] == EMPTY)
 {
 board[(int)move.y][(int)move.x] = currentPlayer;
 int winningDirection = GetWinningDirection(currentPlayer);
 if (winningDirection)
 {
 gameOver = true;
 winner = currentPlayer;
 }
 else if (CheckDraw())
 {
 gameOver = true;
 }
 else
 {
 currentPlayer = (currentPlayer == PLAYER1) ? PLAYER2 : PLAYER1;
 }
 }
 }

 if (gameOver && IsKeyPressed(KEY\_R))
 {
 ResetBoard();
 currentPlayer = PLAYER1;
 gameOver = false;
 winner = 0;
 }

 BeginDrawing();
 ClearBackground(RAYWHITE);
 DrawBoard(gameOver, winner);
 if (gameOver)
 {
 DrawWinMessage(winner);
 }
 EndDrawing();
 }

 CloseWindow();
 return 0;
}

Vector2 GetMouseCell() {
 int x = GetMouseX() / CELL\_SIZE;
 int y = GetMouseY() / CELL\_SIZE;
 return (Vector2){x, y};
}

Vector2 AIGetMove()
{
 Vector2 bestMove = {-1, -1};
 Cell tempBoard[BOARD\_SIZE][BOARD\_SIZE];

 // Copy the current board state
 memcpy(tempBoard, board, BOARD\_SIZE \* BOARD\_SIZE \* sizeof(Cell));

 // Check for a winning move
 for (int i = 0; i < BOARD\_SIZE; i++)
 {
 for (int j = 0; j < BOARD\_SIZE; j++)
 {
 if (tempBoard[i][j] == EMPTY)
 {
 tempBoard[i][j] = PLAYER2;
 if (GetWinningDirection(PLAYER2))
 {
 return (Vector2){j, i};
 }
 tempBoard[i][j] = EMPTY;
 }
 }
 }

 // Check for the opponent's winning move and block it
 for (int i = 0; i < BOARD\_SIZE; i++)
 {
 for (int j = 0; j < BOARD\_SIZE; j++)
 {
 if (tempBoard[i][j] == EMPTY)
 {
 tempBoard[i][j] = PLAYER1;
 if (GetWinningDirection(PLAYER1))
 {
 return (Vector2){j, i};
 }
 tempBoard[i][j] = EMPTY;
 }
 }
 }

 // If neither of the above, make a random move
 Vector2 moves[BOARD\_SIZE \* BOARD\_SIZE];
 int moveCount = 0;

 for (int i = 0; i < BOARD\_SIZE; i++)
 {
 for (int j = 0; j < BOARD\_SIZE; j++)
 {
 if (board[i][j] == EMPTY)
 {
 moves[moveCount++] = (Vector2){j, i};
 }
 }
 }

 if (moveCount > 0)
 {
 bestMove = moves[GetRandomValue(0, moveCount - 1)];
 }

 return bestMove;
}

/\*
 \* GetWinningDirection returns an integer representing the winning direction for a given player.
 \* Return values:
 \* 0 - No win
 \* 1 to BOARD\_SIZE - Horizontal win in the corresponding row
 \* BOARD\_SIZE + 1 to 2 \* BOARD\_SIZE - Vertical win in the corresponding column
 \* 2 \* BOARD\_SIZE + 1 - Diagonal win from top-left to bottom-right
 \* 2 \* BOARD\_SIZE + 2 - Diagonal win from top-right to bottom-left
 \*/
int GetWinningDirection(int player)
{
 for (int i = 0; i < BOARD\_SIZE; i++)
 {
 if ((board[i][0] == player && board[i][1] == player && board[i][2] == player))
 { // Check rows
 return i + 1;
 }
 if ((board[0][i] == player && board[1][i] == player && board[2][i] == player))
 { // Check columns
 return i + BOARD\_SIZE + 1;
 }
 }

 // Check diagonals
 if ((board[0][0] == player && board[1][1] == player && board[2][2] == player))
 {
 return 2 \* BOARD\_SIZE + 1;
 }
 if ((board[0][2] == player && board[1][1] == player && board[2][0] == player))
 {
 return 2 \* BOARD\_SIZE + 2;
 }

 return 0;
}

bool CheckDraw()
{
 for (int i = 0; i < BOARD\_SIZE; i++)
 {
 for (int j = 0; j < BOARD\_SIZE; j++)
 {
 if (board[i][j] == EMPTY)
 {
 return false;
 }
 }
 }
 return true;
}

void DrawBoard(bool gameOver, int winner)
{
 for (int i = 1; i < BOARD\_SIZE; i++)
 {
 DrawLine(i \* CELL\_SIZE, 0, i \* CELL\_SIZE, SCREEN\_HEIGHT, BLACK);
 DrawLine(0, i \* CELL\_SIZE, SCREEN\_WIDTH, i \* CELL\_SIZE, BLACK);
 }

 for (int i = 0; i < BOARD\_SIZE; i++)
 {
 for (int j = 0; j < BOARD\_SIZE; j++)
 {
 int x = j \* CELL\_SIZE;
 int y = i \* CELL\_SIZE;

 if (board[i][j] == PLAYER1)
 {
 DrawText("X", x + CELL\_SIZE / 2 - 10, y + CELL\_SIZE / 2 - 10, 20, BLACK);
 }
 else if (board[i][j] == PLAYER2)
 {
 DrawText("O", x + CELL\_SIZE / 2 - 10, y + CELL\_SIZE / 2 - 10, 20, BLACK);
 }
 }
 }

 if (gameOver && winner)
 {
 int dir = GetWinningDirection(winner);
 if (dir >= 1 && dir <= BOARD\_SIZE)
 { // Horizontal line
 int y = (dir - 1) \* CELL\_SIZE + CELL\_SIZE / 2;
 DrawLine(0, y, SCREEN\_WIDTH, y, RED);
 }
 else if (dir >= BOARD\_SIZE + 1 && dir <= 2 \* BOARD\_SIZE)
 { // Vertical line
 int x = (dir - BOARD\_SIZE - 1) \* CELL\_SIZE + CELL\_SIZE / 2;
 DrawLine(x, 0, x, SCREEN\_HEIGHT, RED);
 }
 else if (dir == 2 \* BOARD\_SIZE + 1)
 { // Diagonal from top-left to bottom-right
 DrawLine(0, 0, SCREEN\_WIDTH, SCREEN\_HEIGHT, RED);
 }
 else if (dir == 2 \* BOARD\_SIZE + 2)
 { // Diagonal from top-right to bottom-left
 DrawLine(SCREEN\_WIDTH, 0, 0, SCREEN\_HEIGHT, RED);
 }
 }
}

void DrawWinMessage(int winner)
{
 const char \*messageLine1;
 const char \*messageLine2 = "Press R to restart.";

 if (winner == PLAYER1)
 {
 messageLine1 = "Player 1 (X) wins!";
 }
 else if (winner == PLAYER2)
 {
 messageLine1 = "Player 2 (O) wins!";
 }
 else
 {
 messageLine1 = "It's a draw!";
 }

 int textWidth1 = MeasureText(messageLine1, 20);
 int textWidth2 = MeasureText(messageLine2, 20);
 int textHeight = 20;

 // Draw a semi-transparent background rectangle to improve readability
 DrawRectangle((SCREEN\_WIDTH - textWidth1) / 2 - 20, SCREEN\_HEIGHT / 2 - 50, textWidth1 + 40, textHeight \* 2 + 40, (Color){0, 0, 0, 128});

 DrawText(messageLine1, (SCREEN\_WIDTH - textWidth1) / 2, SCREEN\_HEIGHT / 2 - 30, 20, RAYWHITE);
 DrawText(messageLine2, (SCREEN\_WIDTH - textWidth2) / 2, SCREEN\_HEIGHT / 2, 20, RAYWHITE);
}

void ResetBoard()
{
 for (int i = 0; i < BOARD\_SIZE; i++)
 {
 for (int j = 0; j < BOARD\_SIZE; j++)
 {
 board[i][j] = EMPTY;
 }
 }
}
```
더 플레이하면 AI가 무슨 일이 있어도 완전히 무작위로 선택하는 것처럼 느껴집니다. 현재 코드는 다음과 같습니다: ```c#포함 #포함 #include "raylib.h"#include "string.h"#define BOARD\_SIZE 3#define CELL\_SIZE 100#define SCREEN\_WIDTH (CELL\_SIZE \* BOARD\_SIZE)#define SCREEN\_HEIGHT (CELL\_SIZE \* BOARD\_SIZE)유형 정의 열거형{ EMPTY, PLAYER1, PLAYER2} Cell;Cell board[BOARD\_SIZE][BOARD\_SIZE];int GetWinningDirection(int player);bool CheckDraw();void DrawBoard(bool gameOver, int winner);void DrawWinMessage(int player);void ResetBoard();Vector2 GetMouseCell();Vector2 AIGetMove();int main(){ InitWindow(SCREEN\_WIDTH, SCREEN\_HEIGHT, "Tic Tac Toe"); SetTargetFPS(60); ResetBoard(); int currentPlayer = PLAYER1; bool gameOver = false; int winner = 0; while (!WindowShouldClose()) { if (!gameOver) { Vector2 move = {-1, -1}; if (currentPlayer == PLAYER1 && IsMouseButtonPressed(MOUSE\_LEFT\_BUTTON)) { move = GetMouseCell(); } else if (currentPlayer == PLAYER2) { move = AIGetMove(); } if (move.x != -1 && move.y != -1 && board[(int)move.y][(int)move.x] == EMPTY) { board[(int)move.y][(int)move.x] = currentPlayer; int winningDirection = GetWinningDirection(currentPlayer); if (winningDirection) { gameOver = true; winner = currentPlayer; } else if (CheckDraw()) { gameOver = true; } else { currentPlayer = (currentPlayer == PLAYER1) ? PLAYER2 : PLAYER1; } } } if (gameOver && IsKeyPressed(KEY\_R)) { ResetBoard(); currentPlayer = PLAYER1; gameOver = false; winner = 0; } BeginDrawing(); ClearBackground(RAYWHITE); DrawBoard(gameOver, winner); if (gameOver) { DrawWinMessage(winner); } EndDrawing(); } CloseWindow(); 반환 0;}Vector2 GetMouseCell() { int x = GetMouseX() / CELL\_SIZE; int y = GetMouseY() / CELL\_SIZE; return (Vector2){x, y};}Vector2 AIGetMove(){ Vector2 bestMove = {-1, -1}; Cell tempBoard[BOARD\_SIZE][BOARD\_SIZE]; // 현재 보드 상태 복사 memcpy(tempBoard, board, BOARD\_SIZE \* BOARD\_SIZE \* sizeof(Cell)); // 이긴 수 확인 for (int i = 0; i < BOARD\_SIZE; i++) { for (int j = 0; j < BOARD\_SIZE; j++) { if (tempBoard[i][j] == EMPTY) { tempBoard[i][j] = PLAYER2; if (GetWinningDirection(PLAYER2)) { return (Vector2){j, i}; } tempBoard[i][j] = EMPTY; } } } // 상대의 승리 수를 확인하고 차단합니다. for (int i = 0; i < BOARD\_SIZE; i++) { for (int j = 0; j < BOARD\_SIZE; j++) { if (tempBoard[i][j] == EMPTY) { tempBoard[i][j] = PLAYER1; if (GetWinningDirection(PLAYER1)) { return (Vector2){j, i}; } tempBoard[i][j] = EMPTY; } } } // 위의 두 가지 중 어느 것도 없으면 무작위로 이동합니다. Vector2 moves[BOARD\_SIZE \* BOARD\_SIZE]; int moveCount = 0; for (int i = 0; i < BOARD\_SIZE; i++) { for (int j = 0; j < BOARD\_SIZE; j++) { if (board[i][j] == EMPTY) { moves[moveCount++] = (Vector2){j, i}; } } } if (moveCount > 0) { bestMove = moves[GetRandomValue(0, moveCount - 1)]; } return bestMove;}/\* \* GetWinningDirection은 주어진 플레이어의 승리 방향을 나타내는 정수를 반환합니다. \* 반환값: \* 0 - 승리 없음 \* 1 ~ BOARD\_SIZE - 해당 행에서 수평 승리 \* BOARD\_SIZE + 1 ~ 2 \* BOARD\_SIZE - 해당 열의 수직 승리 \* 2 \* BOARD\_SIZE + 1 - 왼쪽 상단에서 오른쪽 하단까지 대각선 승리 \* 2 \* BOARD\_SIZE + 2 - 오른쪽 상단에서 왼쪽 하단으로 대각선 승리 \*/int GetWinningDirection(int player){ for (int i = 0; i < BOARD\_SIZE; i++) { if ((BOARD[i][0] == player && BOARD[i][1] == player && BOARD[i][2] == player)) { // 행 확인 반환 i + 1; } if ((board[0][i] == player && board[1][i] == player && board[2][i] == player)) { // 열 확인 return i + BOARD\_SIZE + 1; } } // 대각선 확인 if ((board[0][0] == player && board[1][1] == player && board[2][2] == player)) { 반환 2 \* BOARD\_SIZE + 1; } if ((board[0][2] == player && board[1][1] == player && board[2][0] == player)) { 반환 2 \* BOARD\_SIZE + 2; } return 0;}bool CheckDraw(){ for (int i = 0; i < BOARD\_SIZE; i++) { for (int j = 0; j < BOARD\_SIZE; j++) { if (board[i][j] == EMPTY) { return false; } } } 반환 참입니다;}void DrawBoard(bool gameOver, int winner){ for (int i = 1; i < BOARD\_SIZE; i++) { DrawLine(i \* CELL\_SIZE, 0, i \* CELL\_SIZE, SCREEN\_HEIGHT, BLACK); DrawLine(0, i \* CELL\_SIZE, SCREEN\_WIDTH, i \* CELL\_SIZE, BLACK); } for (int i = 0; i < BOARD\_SIZE; i++) { for (int j = 0; j < BOARD\_SIZE; j++) { int x = j \* CELL\_SIZE; int y = i \* CELL\_SIZE; if (board[i][j] == PLAYER1) { DrawText("X", x + CELL\_SIZE / 2 - 10, y + CELL\_SIZE / 2 - 10, 20, BLACK); } else if (board[i][j] == PLAYER2) { DrawText("O", x + CELL\_SIZE / 2 - 10, y + CELL\_SIZE / 2 - 10, 20, BLACK); } } } if (게임오버 && 승자) { int dir = GetWinningDirection(winner); if (dir >= 1 && dir <= BOARD\_SIZE) { // 수평선 int y = (dir - 1) \* CELL\_SIZE + CELL\_SIZE / 2; DrawLine(0,