National University of Computer and Emerging Sciences, Lahore Campus
Course: Artificial Intelligence Course Code: AI-2002
Program: BS(Computer Science) Semester: Spring 2024
Duration: Total Marks: 10
Paper Date: 1st-April-23 Weight 3.33 %
Section: D/E/F Page(s): 2
Exam: Assignment 2 Roll No.
Instruction/Notes:
• Provide your solution in a Jupyter Notebook file.
Assignment: Chomp AI - Outsmarting the Opponent
Objective: Design and implement an AI opponent for the classic game of Chomp using the minimax
algorithm.
Game Description:
Chomp is a two-player strategy game played on a rectangular grid
of chocolate squares. One square, typically the bottom-left corner,
contains a poisoned bar. Players take turns eating chocolate, but with
a twist: whenever a player takes a square, they must also eat all the
squares directly above and to the right of their chosen square. The
goal is to avoid eating the poisoned bar and force your opponent to
do so.
1. Implement the Chomp Game:
o Design a data structure to represent the Chomp game state, including the grid size, poisoned square
location, and remaining squares.
o Implement functions to simulate a player's move, updating the game state accordingly.
o Develop a function to check if the game is over (win or loss for either player).
2. Minimax AI Implementation:
o Implement the Minimax algorithm to create an AI opponent. The AI should analyze potential moves,
considering all possible future game states for both players.
o Define an evaluation function that assigns a score to each potential game state. This score should reflect
how favorable the state is for the AI (maximizing its chances of winning while minimizing the
opponent's).
o Using Minimax, the AI will choose the move that leads to the highest score (best outcome) based on the
evaluation function.
3. Play against the AI:
o Allow the user to play against your AI opponent on a chosen grid size.
o Display the game state after each move.
o Implement user input functionality to select a square.
o The AI should then analyze the board and make its move according to the Minimax algorithm.
o Determine the winner and display an appropriate message.
FAST School of Computing Page1