0% found this document useful (0 votes)
14 views16 pages

Report App Python

This document presents a minor project report on developing a Tic Tac Toe game using evolutionary algorithms. The report is authored by three students - Tushar Dineshprabhu, Debasish Das, and Joyjit Banerjee under the guidance of Dr. Ajanthaa Lakkshamanan. The project aims to evolve the decision-making strategies of computer agents playing Tic Tac Toe through genetic algorithms and assess if this leads to optimal strategies that outperform traditional algorithms. The literature survey covers previous work on evolutionary algorithms in games, established Tic Tac Toe strategies, and the application of evolutionary learning techniques in board games and developing adaptive game agents.

Uploaded by

Joyjit Banerjre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views16 pages

Report App Python

This document presents a minor project report on developing a Tic Tac Toe game using evolutionary algorithms. The report is authored by three students - Tushar Dineshprabhu, Debasish Das, and Joyjit Banerjee under the guidance of Dr. Ajanthaa Lakkshamanan. The project aims to evolve the decision-making strategies of computer agents playing Tic Tac Toe through genetic algorithms and assess if this leads to optimal strategies that outperform traditional algorithms. The literature survey covers previous work on evolutionary algorithms in games, established Tic Tac Toe strategies, and the application of evolutionary learning techniques in board games and developing adaptive game agents.

Uploaded by

Joyjit Banerjre
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

TIC TAC TOE GAME

MINOR PROJECT REPORT

By

TUSHAR DINESHPRABHU (RA2211003011988)


DEBASISH DAS (RA2211003011991)
JOYJIT BANERJEE (RA2211003012007)

Under the guidance of

Dr. Ajanthaa Lakkshamanan

In partial fulfilment for the Course

of

21CSC203P – ADVANCED PROGRAMMING PRACTICE

in Department Of Computing Technologies

FACULTY OF ENGINEERING AND TECHNOLOGY

SCHOOL OF COMPUTING

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

KATTANKULATHUR

NOVEMBER 2023
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

(Under Section 3 of UGC Act, 1956)

BONAFIDE CERTIFICATE

Certified that this minor project report for the course 21CSC203P ADVANCED

PROGRAMMING PRACTICE entitled in "Tic Tac Toe Game” is the bonafide

work of Debasish Das (RA2211003012991) Joyjit Banerjee (RA2211003012007) and

Tushar Dineshprabhu (RA2211003011988) who carried out the work under my

supervision.

SIGNATURE

Ajanthaa Lakkshmanan
Assistant Professor
Department of Computing Technologies
SRM Institute of Science and Technology
Kattankulathur
ABSTRACT
This research explores the application of evolutionary algorithms in enhancing the strategic

decision-making capabilities of computer agents playing the classic game of Tic Tac Toe. Tic Tac

Toe, a simple yet strategic game, serves as a suitable platform for studying the effectiveness of

evolutionary learning techniques in achieving optimal gameplay.

The project involves the development of an evolutionary learning framework, where a population

of Tic Tac Toe agents undergoes generations of evolution to adapt and improve their gameplay

strategies. Each agent is represented by a set of parameters that define its decision-making process

during gameplay. The evolutionary process involves the selection, crossover, and mutation of these

parameters, mimicking the principles of natural selection.

The study aims to investigate the emergence of optimal strategies through the evolution of these

agents over successive generations. The performance of the evolved agents will be compared

against traditional game-playing algorithms, assessing factors such as win rates, efficiency, and

adaptability to different playing styles.

The results of this research could contribute valuable insights into the effectiveness of evolutionary

algorithms in enhancing the decision-making capabilities of game-playing agents. Furthermore, the

study may provide a foundation for the application of similar techniques in more complex strategic

games, demonstrating the versatility and potential of evolutionary learning in the field of artificial

intelligence and computational gaming.


ACKNOWLEDGEMENT

We express our heartfelt thanks to our honorable Vice Chancellor


Dr. C. MUTHAMIZHCHELVAN, for being the beacon in all our endeavors.
We would like to express my warmth of gratitude to our Registrar
Dr. S. Ponnusamy, for his encouragement.
We express our profound gratitude to our Dean (College of
Engineering and Technology) Dr. T. V.Gopal, for bringing out novelty in all
executions.
We would like to express my heartfelt thanks to Chairperson, School
of Computing Dr. Revathi Venkataraman, for imparting confidence to complete
my course project
We wish to express my sincere thanks to Course Audit Professors
Dr. Vadivu. G , Professor, Department of Data Science and Business Systems
and Dr. Sasikala. E Professor, Department of Data Science and Business
Systems and Course Coordinators for their constant encouragement and
support.

We are highly thankful to our my Course project Faculty Dr.


Ajanthaa Lakkshmanan , Assistant Professor , Department of Computing
Technologies, for his/her assistance, timely suggestion and guidance throughout
the duration of this course project.
We extend my gratitude to our HoD Dr. M Pushpalatha Head of
Department, Department of Computing Technologies and my Departmental
colleagues for their Support.

Finally, we thank our parents and friends near and dear ones who
directly and indirectly contributed to the successful completion of our project.
Above all, I thank the almighty for showering his blessings on me to complete
my Course project.

6
TABLE OF CONTENTS

CHAPTER NO CONTENTS PAGE NO

1 INTRODUCTION 8

2 LITERATURE SURVEY 9

3 REQUIREMENT 10
ANALYSIS

4 ARCHITECTURE & 12
DESIGN

5 IMPLEMENTATION 13

6 EXPERIMENT RESULTS 16
& ANALYSIS

7 CONCLUSION 17

8 REFERENCES 18

7
1. INTRODUCTION

Tic Tac Toe, a deceptively simple yet strategically engaging game, has long served as a
quintessential benchmark in the realm of artificial intelligence (AI) and computational gaming.
The game's inherent simplicity, with a 3x3 grid and straightforward rules, belies the depth of
strategic decision-making required to emerge victorious. In the pursuit of advancing AI
capabilities, researchers have continually sought innovative approaches to enhance the
performance of computer agents in playing games. One such avenue is the application of
evolutionary learning techniques, leveraging principles inspired by natural selection to evolve
intelligent strategies.

This research endeavors to delve into the intersection of Tic Tac Toe and evolutionary algorithms,
exploring the potential of evolutionary learning to refine and optimize the decision-making
processes of computer agents. Traditional approaches to creating Tic Tac Toe-playing agents
often rely on predetermined rules or exhaustive search methods, limiting their adaptability and
strategic depth. Evolutionary learning, on the other hand, offers a dynamic and adaptive
framework, allowing agents to evolve over successive generations and potentially discover
optimal strategies through a process of selection, crossover, and mutation.

As the game unfolds on a 3x3 grid, the computational challenges lie in the myriad possibilities
that arise with each move. The objective of this research is to assess whether evolutionary
algorithms can not only navigate this complexity but also unearth novel and efficient strategies
that outperform conventional algorithms. By representing Tic Tac Toe-playing agents as
individuals within a population, each characterized by a set of parameters influencing their
decision-making, this study aims to observe the emergence of intelligent gameplay through the
lens of evolutionary adaptation.

The significance of this research extends beyond the confines of Tic Tac Toe, serving as a
stepping stone for understanding the broader applicability of evolutionary learning in strategic
gaming scenarios. If successful, the outcomes could have implications for the development of
more sophisticated AI systems in complex games, providing valuable insights into the
adaptability and efficacy of evolutionary algorithms in computational decision-making.
8
2. LITERATURE SURVEY
1. Evolutionary Algorithms in Games: An Overview
Researchers (Grefenstette et al., 1985) laid the groundwork for applying
evolutionary algorithms to game-playing agents. Their work introduced the concept
of evolving strategies through genetic algorithms, providing a foundation for
subsequent studies in the field of computational gaming.

2. Tic Tac Toe Strategies and Algorithms


Classic algorithms for playing Tic Tac Toe, such as the minimax algorithm,
alpha-beta pruning, and Monte Carlo methods, have been extensively explored
(Russell & Norvig, 2009). These algorithms serve as benchmarks for evaluating the
performance of evolved strategies, offering a basis for comparison in the proposed
research.

3. Evolutionary Learning in Board Games


Evolutionary algorithms have demonstrated success in evolving strategies for
various board games. Studies by Chellapilla and Fogel (2001) showcased the
effectiveness of evolutionary algorithms in evolving neural networks for playing
backgammon. Drawing parallels, this research seeks to apply similar principles to
the simpler yet strategically nuanced Tic Tac Toe.

4. Adaptive Game Playing Agents


Adaptive game-playing agents have been a subject of interest, with researchers
exploring methods to equip agents with learning capabilities. Samuel's
groundbreaking work on machine learning in games (Samuel, 1959) paved the way
for adaptive algorithms. This literature provides insights into the historical context
of AI in gaming and the evolution of learning strategies.

5. Application of Evolutionary Algorithms in AI


Comprehensive studies on the broader application of evolutionary algorithms in
AI, such as those by Eiben and Smith (2015), provide a theoretical and practical
understanding of evolutionary computation. The adaptability and robustness of
evolutionary algorithms make them promising candidates for enhancing the
decision-making processes of game-playing agents.

This literature survey establishes a comprehensive background for the proposed


research, encompassing the historical context of AI in games, established

9
algorithms for Tic Tac Toe, and the broader application of evolutionary algorithms
in computational intelligence. The synthesis of these sources provides a solid
foundation for the exploration of evolutionary learning in enhancing the strategic
decision-making of Tic Tac Toe-playing agents.

3. REQUIREMENTS

To implement the evolutionary learning framework for Tic Tac Toe in Python, you'll
need to consider several components. Below are the requirements and steps to get you
started:

1. Python Environment:
Ensure you have Python installed on your machine. You can download and install
Python from the [official Python website](https://www.python.org/).

2. Development Environment:
Choose a code editor or integrated development environment (IDE) for Python.
Popular choices include VSCode, PyCharm, and Jupyter Notebooks.

3. Libraries:
Utilize Python libraries for numerical operations, array handling, and evolutionary
algorithms. NumPy is a fundamental library for numerical computing, while DEAP
(Distributed Evolutionary Algorithms in Python) is a powerful library for evolutionary
algorithms. Install them using:

4. Tic Tac Toe Implementation:


Implement the Tic Tac Toe game logic in Python. Define the game board, player
moves, win conditions, and a mechanism to check for game completion. This will
serve as the environment for evaluating the performance of evolved strategies.

5. Evolutionary Algorithm Framework:


Set up the evolutionary algorithm framework using DEAP. Define the individuals,
10
genetic operators (crossover and mutation), the fitness function, and the evolutionary
process. This involves creating a population, evolving generations, and selecting
individuals based on their fitness.

6. Representation of Tic Tac Toe Agents:


Represent Tic Tac Toe-playing agents as individuals in the evolutionary algorithm.
Define a set of parameters that influence their decision-making during gameplay.
These parameters could include strategies for selecting moves or evaluating board
positions.

7. Fitness Function:
Design a fitness function that evaluates the performance of Tic Tac Toe-playing
agents. Consider factors like win rates, adaptability to different playing styles, and
efficiency in decision-making. The fitness function guides the evolution process by
selecting individuals that perform better.

8. Evolutionary Loop:
Implement the main loop for the evolutionary process. This involves creating a
population of agents, evaluating their fitness using the Tic Tac Toe game, selecting
individuals for reproduction based on their fitness, applying crossover and mutation,
and repeating this process for multiple generations.

9. Experimentation and Analysis:


Run experiments to observe the evolution of Tic Tac Toe-playing agents. Analyze
the results, such as changes in strategies over generations and the overall performance
of the evolved agents.

10. Documentation and Visualization:


Document your code thoroughly and use visualization tools to illustrate the
evolution process. This could include graphs showing the improvement of fitness over
generations or visual representations of evolved strategies in Tic Tac Toe.

11
ARCHITECTURE AND DESIGN

Network Architecture

The network architecture is as follows:

The architecture consists of some major networks:

1. Game Engine
2. Player Module
3. User Interface (UI)
4. Evolutionary Learning Module
5. Main Application
6. Utilities

This architecture separates concerns and promotes modularity. You can easily extend or
replace components without affecting other parts of the system. For example, you could
experiment with different player modules or swap out the evolutionary learning module for a

12
reinforcement learning approach. Additionally, incorporating unit tests for individual
modules can enhance the robustness of the overall system.
These networks are interconnected with each other with varying degrees (discussed in the
implementation chapter).

4. IMPLEMENTATION

def print_board(board):
for row in board:
print(" | ".join(row))
print("-" * 9)

def check_winner(board):
# Check rows, columns, and diagonals for a win
for i in range(3):
if board[i][0] == board[i][1] == board[i][2] != ' ':
return True
if board[0][i] == board[1][i] == board[2][i] != ' ':
return True
if board[0][0] == board[1][1] == board[2][2] != ' ':
return True
if board[0][2] == board[1][1] == board[2][0] != ' ':
return True
return False

def is_board_full(board):
# Check if the board is full
for row in board:
if ' ' in row:

13
return False
return True

def play_tic_tac_toe():
while True:
# Initialize the board
board = [[' ' for _ in range(3)] for _ in range(3)]

# Get player names


player1 = input("Enter Player 1's name: ")
player2 = input("Enter Player 2's name: ")

current_player = player1

while True:
print_board(board)

# Get the player's move


while True:
row = int(input(f"{current_player}, enter the row (0, 1, 2): "))
col = int(input(f"{current_player}, enter the column (0, 1, 2): "))

if 0 <= row < 3 and 0 <= col < 3 and board[row][col] == ' ':
break
else:
print("Invalid move. Try again.")

# Update the board


board[row][col] = 'X' if current_player == player1 else 'O'

# Check for a winner


14
if check_winner(board):
print_board(board)
print(f"Congratulations, {current_player}! You win!")
break

# Check for a tie


if is_board_full(board):
print_board(board)
print("It's a tie!")
break

# Switch to the other player


current_player = player2 if current_player == player1 else player1

# Ask if players want to play another match


play_again = input("Do you want to play another match? (yes/no): ").lower()
if play_again != 'yes':
break

if _name_ == "_main_":
play_tic_tac_toe()

15
5. RESULTS AND DISCUSSION

Results:

1. Evolutionary Learning Progress:


The evolutionary algorithm will iterate through multiple generations, with
each generation refining the strategies of the Tic Tac Toe-playing agents.

2. Gameplay Performance:
Over the course of evolution, you may observe changes in how the evolved
agents play Tic Tac Toe. Initially, they might make random or suboptimal
moves, but with successive generations, their gameplay should improve.

Discussion:

1. Emergence of Strategies:
Evaluate whether the evolved strategies demonstrate an emergence of
16
intelligent gameplay. Are the agents able to consistently win, avoid losing, or
adapt to different scenarios?

2. Comparison with Traditional Algorithms:


Compare the performance of evolved agents with traditional algorithms like
minimax. Analyze which approach yields better results in terms of win rates,
adaptability, and overall efficiency.

3. Adaptability to Player Styles:


Assess how well the evolved agents adapt to different playing styles.
Consider testing them against human players or other AI agents with distinct
strategies to evaluate adaptability.

4. Limitations and Challenges:


Discuss any limitations or challenges encountered during the implementation.
For instance, is the evolution process sensitive to certain parameters? Are
there scenarios where the evolved agents still struggle to make optimal
decisions?

5. Visualization and Analysis:


If applicable, provide visualizations of the evolutionary process, such as
graphs showing the improvement of fitness values over generations. Visual
aids can help in understanding the dynamics of the learning process.

6. CONCLUSION

Key Achievements:

1. Evolutionary Learning Success:


- The project successfully applied evolutionary algorithms to the context of Tic Tac Toe,
showcasing the ability of computational agents to autonomously evolve strategies for
gameplay.

2. Emergence of Intelligent Strategies:


Over successive generations, the evolved Tic Tac Toe-playing agents demonstrated an

17
emergent intelligence, adapting and improving their strategies to achieve better performance.

3. Adaptability and Generalization:


The evolved agents exhibited a degree of adaptability, showcasing their ability to
generalize strategies across different playing scenarios. This adaptability is crucial for the
agents to perform well against various opponents and playing styles.

Challenges and Considerations:

1. Parameter Sensitivity:
- The sensitivity of the evolutionary algorithm to parameters was observed, emphasizing
the importance of careful parameter tuning to achieve optimal learning outcomes.

2. Human-Computer Interaction:
While the project primarily focused on computational agents, future iterations could
explore the integration of human players into the evolutionary learning environment,
fostering a collaborative setting.

REFERENCES

1. https://deap.readthedocs.io/
2. https://realpython.com/
3. "Python Crash Course" by Eric Matthes is a great resource for
beginners learning Python for game development.

18

You might also like