Skip to content

This repository contains a C implementation of the classic Connect 4 board game played on an 8x8 grid. The game features a single-player mode where you compete against an AI opponent. The AI uses a minimax algorithm with alpha-beta pruning to optimize its moves, providing a challenging experience.

License

Notifications You must be signed in to change notification settings

Tutusaus/4_en_Ratlla

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📊 AI-Powered Board Game in C

main

Table of Contents

Introduction

Welcome to the AI-Powered Board Game in C! This project is a terminal-based strategy game where you compete against a computer opponent on an 8x8 grid. The AI uses a sophisticated minimax algorithm with alpha-beta pruning to simulate challenging gameplay, ensuring a competitive experience every time you play.

Features

  • Single-player mode: Battle against an AI opponent with smart decision-making capabilities.
  • 8x8 Board: Classic grid-based gameplay using ASCII characters:
    • O for Player moves
    • X for Computer moves
    • (Space) for empty cells
  • AI Strategy:
    • Minimax algorithm with a configurable depth limit for move predictions.
    • Alpha-beta pruning to optimize decision-making speed.
  • Modular code: Organized with structs and functions for readability and maintainability.

Installation

Follow these steps to set up the game on your local machine:

Prerequisites

  • GCC compiler (or any C compiler of your choice)
  • Terminal/Command Line Interface

Clone the Repository

git clone https://github.com/Tutusaus/4_en_Ratlla.git
cd .\4_en_Ratlla\

Compile the Code

gcc main.c -o main

Usage

Once compiled, you can run the game by executing:

main.exe

Gameplay Instructions

  • The game starts with an empty 8x8 board.
  • Players take turns placing their marks (O for Player, X for Computer) on the board.
  • The objective is to outsmart your opponent by strategically placing your marks.
  • The AI uses an advanced algorithm to make decisions, providing a challenging opponent.

How It Works

The game leverages a tree data structure to simulate possible game states:

  • Each game state is represented by a node struct containing:
    • A 2D array for the board (tauler[N][N])
    • A list of possible moves (children nodes)
    • A heuristic value for evaluating the game state
  • The AI uses a minimax algorithm with alpha-beta pruning:
    • Minimax evaluates all possible moves to determine the optimal one.
    • Alpha-beta pruning reduces the number of nodes evaluated by the algorithm, making the AI faster and more efficient.
  • You can adjust the AI difficulty by modifying the depth constant (PROFUNDITAT).

Future Improvements

Here are some enhancements planned for future versions:

  • Graphical User Interface (GUI): Develop a visual version using libraries like SDL or OpenGL.
  • Difficulty Levels: Add adjustable difficulty settings for the AI.
  • Multiplayer Support: Enable two-player mode.
  • Save/Load Game: Implement functionality to save and resume games.

Contributing

Contributions are welcome! If you would like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -m 'Add new feature').
  4. Push to the branch (git push origin feature-branch).
  5. Open a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

This repository contains a C implementation of the classic Connect 4 board game played on an 8x8 grid. The game features a single-player mode where you compete against an AI opponent. The AI uses a minimax algorithm with alpha-beta pruning to optimize its moves, providing a challenging experience.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages