/Tablut

Project for the MSc in Artificial Intelligence of the University of Bologna, academic year 2023/2024. Tablut Challenge from the Fundamentals of Artificial Intelligence and Knowledge Representation course

Primary LanguagePythonApache License 2.0Apache-2.0

\tLut ๐ŸŽ‰๐Ÿค–

Introduction ๐Ÿš€

Hey there, code explorers! ๐ŸŒŸ Welcome to the mind-blowing world of Tablut, brought to you by the genius minds of University of Bologna's AI course for the mind-bending academic year 2023/2024! ๐Ÿง ๐ŸŽ“

Our mission? Oh, just to create an AI wizard ๐Ÿง™ capable of dominating the epic game of Tablut using the jaw-dropping Minimax algorithm with Alpha-Beta pruning. Yeah, we're that ambitious! ๐Ÿš€

And who's behind this magical project? None other than the fantastic foursome:

Project Philosophy ๐ŸŒ

Hold on to your hats, folks! This project is pure Python 3.9 sorcery! ๐Ÿ The code? It's organized so neatly, even Marie Kondo would be proud! ๐Ÿงน Plus, it's comment city, making it a breeze to understand. Oh, and did we mention we've sprinkled some AIMA Python code magic? Yup, we went all out! ๐Ÿš€โœจ

How to Run the Code ๐Ÿš€

Ready for the magic show? ๐ŸŽฉโœจ To dive into the enchanting world of Tablut, simply run the mystical play.py file. Just toss in these enchanting arguments:

  • --team: Choose your team, either WHITE or BLACK. ๐Ÿดโ€โ˜ ๏ธ๐Ÿณ๏ธ
  • --name: Declare the name of your agent. โœจ
  • --ip: Provide the IP address of the server. Default is localhost. ๐ŸŒ

Behold the spell to run this enchanting code:

py play.py --team WHITE --name "\tLut" --ip <server_ip>

Oh, and if you're in the Windows realm, use python3 for Linux adventures. ๐Ÿงโœจ

WHITE Heuristics

In the implementation of the WHITE player's heuristics, several factors are taken into consideration to evaluate the current state of the Tablut board. These factors contribute to the overall fitness of the position for the WHITE player. The key components of the WHITE heuristics include:

  1. Vulnerability to Capture:

    • A measure of the risk of WHITE pieces being captured by BLACK pawns.
    • Utilizes the concept of clear views to assess potential threats to WHITE pieces.
  2. King's Distance and Safety:

    • Evaluates the distance of the WHITE king from the corners of the board.
    • Incorporates the number of BLACK pieces in each quadrant to assess the safety of the king.
  3. External Pawn Distribution:

    • Calculates the fitness based on the distribution of WHITE pawns relative to the king.
    • Promotes a strategic arrangement of WHITE pieces with respect to the center of the board.
  4. King's Defense:

    • Considers the ability of BLACK pieces to potentially capture the WHITE king in the next move.
    • Applies a strong negative fitness if the king is at risk of capture.
  5. King's Movement:

    • Evaluates the movement of the WHITE king, promoting a balanced position across the board.

The combination of these factors aims to provide a comprehensive assessment of the Tablut board from the perspective of the WHITE player.

BLACK Heuristics

The BLACK player's heuristics focus on evaluating the strategic aspects of the Tablut board, taking into account various factors that influence the overall fitness of the position. The primary considerations in the BLACK heuristics are:

  1. Number of BLACK and WHITE Pawns:

    • Assigns fitness based on the count of BLACK and WHITE pawns on the board.
  2. Proximity of BLACK Pawns to the King:

    • Evaluates the number of BLACK pawns within a certain distance of the WHITE king.
    • A higher count encourages a more aggressive position.
  3. Path to the King:

    • Assesses the availability of free paths for BLACK pawns to reach and potentially capture the WHITE king.
  4. Encirclement of the King:

    • Introduces a coefficient of encirclement, considering the positioning of BLACK pawns around the WHITE king.

The BLACK heuristics aim to capture the strategic advantages, focusing on pawn count, proximity to the king, and the potential to create threats against the WHITE player. These factors collectively contribute to the fitness evaluation for the BLACK player in the Tablut game.

Prepare to be amazed, mortals! ๐ŸŽฉโœจ