Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Informatics College Pokhara

Artificial Intelligence
CU6051NA
Coursework 2

Submitted By: Submitted To:


Student Name: Nikit Gurung Sukrit Shakya
London Met ID: 17031975 Module Leader
Group: L3C2 Artificial Intelligence
Date: 10-Feb-2019 Module Name
Table of Contents

1 Introduction................................................................................................ 1
1.1 Explanation of the topic/AI concepts used .......................................... 1
1.2 Explanation of the chosen problem domain ........................................ 2
1.3 Reason for selection ........................................................................... 2
2 Mind Map................................................................................................... 3
2.1 Description and design of mind map ................................................... 3
2.1.1 Mind Map 1 .................................................................................. 3
2.1.2 Mind Map 2 .................................................................................. 4
2.1.3 Mind Map 3 .................................................................................. 5
2.1.4 Mind Map 4 .................................................................................. 6
2.1.5 Mind Map 5 .................................................................................. 7
3 Background ............................................................................................... 8
3.1 Research work done on the chosen topic ........................................... 8
3.1.1 Books ........................................................................................... 8
3.1.2 Journals........................................................................................ 8
3.2 Review and analysis of existing work in the problem domain ............. 9
3.2.1 Table Tennis 3D Ping Pong ......................................................... 9
3.2.2 Pong 10 ........................................................................................ 9
3.2.3 Pong RT ..................................................................................... 10
4 Solution ................................................................................................... 11
4.1 Explanation of the solution ................................................................ 11
4.2 AI Algorithm used ............................................................................. 11
4.2.1 Minimax Algorithm ...................................................................... 11
4.3 Pseudocode of the solution............................................................... 12
4.4 Flowchart diagram of the solution ..................................................... 14
4.5 Explanation of the development process .......................................... 14
4.6 Achieved results ............................................................................... 16
5 Conclusion............................................................................................... 19
6 References .............................................................................................. 20
Table of Figures

Figure 1: Mind Map 1 ....................................................................................... 3


Figure 2: Mind Map 2 ....................................................................................... 4
Figure 3: Mind Map 3 ....................................................................................... 5
Figure 4: Mind Map 4 ....................................................................................... 6
Figure 5: Mind Map 5 ....................................................................................... 7
Figure 6: Table Tennis 3D Ping Pong .............................................................. 9
Figure 7: Pong 10 ............................................................................................ 9
Figure 8: Pong RT.......................................................................................... 10
Figure 9: Flowchart for Unlimited Ping Pong .................................................. 14
Figure 10: Game GUI ..................................................................................... 16
Figure 11: Player wins ................................................................................... 17
Figure 12: CPU wins ...................................................................................... 18
CU6051NA Artificial Intelligence

1 Introduction
1.1 Explanation of the topic/AI concepts used
Artificial Intelligence(AI) is a branch of a computer science that deals with
listening, reasoning, analysing, processing and understanding natural language
as human being. In today’s world, the presence of AI has contributed to several
sectors such as educational sector, household sector, organizational sector,
scientific sector, gaming sector and many more. Talking more specific about
the gaming sector, AI has made great contribution such as making games
realistic, smarter and enhancing the overall gaming experience, etc.

As gaming is becoming popular all over the world among all age groups and
people spend many of their times playing games, I have chosen Adversarial
search and games as the AI concept for the gaming project named Unlimited
Ping Pong. This concept is also known as Minimax search which is popularly
recognized for its helpfulness in calculating the best move in two player games
such as Pong where all the needed information is accessible. It possesses of
navigating through a tree which captures all the possible moves in the game.
Both of the players each move is stated in terms of gain or loss for one of the
players. In zero-sum games, it is used to make decisions which defines one
player’s gain is the other player’s loss. According to von Neumann’s minimax
theorem, “Zero-sum games consists of a set of strategies which leads to both
players gaining the same value and that seeing as this is the best possible value
one can expect to gain, one should employ this set of strategies (Kulenovic,
2008).”

This individual report for the coursework of the Artificial


Intelligence will cover the introduction phase, background phase, solution
phase and the conclusion phase of the project. The main reason behind making
this gaming project in this individual coursework for artificial intelligence is that
gaming simply doesn’t have any age bar and is becoming a sensation among
both the youths and the adults.

Nikit Gurung 1
CU6051NA Artificial Intelligence

1.2 Explanation of the chosen problem domain


As mentioned above, for this gaming project named Unlimited Ping
Pong, we have chosen Adversarial search and games as its AI concept. Well,
Unlimited Ping Pong is a two dimensional arcade game which consists of two
players where both of them control an in-game paddle by moving it vertically up
or down side of the screen with the help of up and down button. Just like table
tennis, in this game the user must hit a ball back and forth with the help of the
paddle. A player wins the game when he/she scores more than the CPU’s
score. Each point is earned when the player or the CPU is unable to return the
ball to the other.

In order to play this game, a user must just click the Unlimited Ping Pong
Icon and can simply play the game and compete against the CPU until the user
closes the program.

1.3 Reason for selection


The reasons for selecting this project are enlisted below:

 Gaming has a huge scope in AI.


 Gaming is suitable for all age groups.
 Lack of game developers in Nepal.
 Gain more knowledge about this specific AI concept i.e. Adversarial
search and games.

Nikit Gurung 2
CU6051NA Artificial Intelligence

2 Mind Map
2.1 Description and design of mind map
2.1.1 Mind Map 1

Figure 1: Mind Map 1

This is the first or the initial map mind for the gaming application name
Unlimited Ping Pong. As this is a gaming project, Adversarial search and
games is chosen as the AI concept. Moreover, in this mind map 1, we have
introduced the general features such as its game type, guideline, final
outcomes, display, etc.

Nikit Gurung 3
CU6051NA Artificial Intelligence

2.1.2 Mind Map 2

Figure 2: Mind Map 2

In the mind map 2, we have given details of some of the general features such
as the game type will be an arcade game in 2D and will have multiplayer
feature. Similarly, guideline for user manual is provided in many points such as
run the program, use paddle to hit the ball, earn points when the CPU misses
the ball and exit the program whenever you want.

Nikit Gurung 4
CU6051NA Artificial Intelligence

2.1.3 Mind Map 3

Figure 3: Mind Map 3

In the mind map 3, the final outcomes of the Unlimited Ping Pong is
discussed. i.e. If a user has more points than the CPU, it is declared as a
win. Likewise, if both the user and CPU have same points then, it is a draw
and in the end if the CPU has more points than the user, it is declared as a
loss.

Nikit Gurung 5
CU6051NA Artificial Intelligence

2.1.4 Mind Map 4

Figure 4: Mind Map 4

In the mind map 4, the detail introduction of the Unlimited Ping Pong game
is given. This game is an arcade multiplayer game which was released in
1972, consists of two paddles and a ball and points are earned when one
of the user misses to hit the ball with their paddle.

Nikit Gurung 6
CU6051NA Artificial Intelligence

2.1.5 Mind Map 5

Figure 5: Mind Map 5

The mind map 5 is the complete description of this gaming project. Here,
the rules are discussed about this game. i.e. A user must use a paddle to
hit the ball, points are earned when a player misses to hit the ball with the
help of the paddle.

Nikit Gurung 7
CU6051NA Artificial Intelligence

3 Background
3.1 Research work done on the chosen topic
For this gaming AI project, I researched many books, websites, watched
different Youtube tutorials to learn how to do coding in the place where I
was facing complications and learned the importance of AI in gaming.

3.1.1 Books
Pac-man was the first game which introduced the use of AI in the gaming
sector. In this game, the Pac-Man definitely has enemy characters that
seems to plot against you, moved around the level just as the user and
made life harder. This game was totally based on a simple AI technique.
Until the mid-1990s, game AI didn’t have a drastic change. AI games
started to sell successfully from the mid-1990s. Although Virtual Theatre AI
system was mostly anticipated system, it only allowed characters to walk
forward and backward in the game which was barely a success (Millington
& Funge, 2009).

This book helps to provide the proper guidance to invent a proper computer
game with the help of python programming language. It provides
knowledge about the interactive shell, writing programs in Python’s file
editor, a program to guess the number. i.e. Whether the selected number
of the user is too high or too low (Sweigart, 2017).

3.1.2 Journals
This journal helps to introduce the variety of initial concepts to be used in
artificial intelligence for games in order to identify what tools or items are
present for facing our AI problems, gives an idea about how they work
jointly and their implementation style and the programming language of
their choice (Sizer, 2018).

Strategy plays a vital part in the field of gaming. Before starting a game,
each player or a team makes a strategy in order to win. So to develop the
feature of strategy in the game, the python uses different algorithms such
as Minimax Algorithm, Negamax Algorithm, etc. Talking in more detail
about the minimax algorithm, this strategy is deployed in those games
which consists of two players. In such algorithm, each player makes an

Nikit Gurung 8
CU6051NA Artificial Intelligence

effort to predict the next move of the opponent and tries to minimize that
function (Bartel, 2017).

3.2 Review and analysis of existing work in the problem domain


3.2.1 Table Tennis 3D Ping Pong
This game is similar to my gaming project. It is also a multiplayer game.
Talking about the game features, it has a very good graphical user
interface, user can select a country to represent and play and possesses a
very active system player or CPU. Moreover, it also has sound effects,
pause, play and cancel options. Unlike my project, it is a 3D game.

Figure 6: Table Tennis 3D Ping Pong

3.2.2 Pong 10

Figure 7: Pong 10

Pong 10 is originated from the mythical game of 70’s which is a free multiplayer
game. This is a 2D game. The players should move the paddle to hit the ball
and secure points. In order to move the paddle, the player should use E button
for up and C button for down. The player who secures 9 points first wins the
game.

Nikit Gurung 9
CU6051NA Artificial Intelligence

3.2.3 Pong RT

Figure 8: Pong RT

This application is similar to my gaming application. The similarities between it


and my application is that both are arcade, 2D game and multiplayer game.
Like my gaming application, it should also use the paddle to hit the ball and
secure points when one of the player misses the ball. The main difference
between this application and my gaming application is that it finishes when one
of the player reaches to five points but in my case a user can play this game
unlimited until he/she exists the game.

Nikit Gurung 10
CU6051NA Artificial Intelligence

4 Solution
4.1 Explanation of the solution
This gaming application named “Unlimited Ping Pong” is a two dimensional
arcade game which consists of two players where both of them control an
in-game paddle by moving it vertically up or down side of the screen with
the help of up and down button. In this game, the user must hit the ball back
and forth with the help of the paddle. A player wins the game when he/she
scores more than the CPU’s score. Each point is earned when the player
or the CPU is unable to return the ball to the other.

This gaming application is simply developed for the gamers, the people
who want to spend their leisure time and people who are standing in a
queue. This game will help the people to reduce their boredom, exercise
their brain and play against a competitive system player or the CPU. As this
game is competitive, the user might find it entertaining as well as
challenging.

4.2 AI Algorithm used


4.2.1 Minimax Algorithm
For this gaming application, minimax algorithm is used. It is simply a
decision rule algorithm which is represented as a game-tree. This algorithm
is used in decision theory, game theory, philosophy and statistics. This
algorithm is mainly used in multiplayer games. One player is referred as
min and the other is referred as max player. By agreement the root of the
game-tree represents the max player. In this algorithm, it is supposed that
each player makes their best move for him/herself and hence the worst
move for his/her opponent in order to win the game (Al-dehedhawy & Al-
Tufaili, 2015).

Nikit Gurung 11
CU6051NA Artificial Intelligence

4.3 Pseudocode of the solution


pong pseudo

class paddle

def update()

if key == up

direction = -1

elif key == down

direction = 1

class Ball

def update()

if ball hits right

player_score +1

elif ball hits left

computer_score +1

def detect_collision()

if ball hits paddle

reflect ball

def reset()

set (x,y)

set speed

class computer

def update()
Nikit Gurung 12
CU6051NA Artificial Intelligence

if ball.y < paddle.y

move down

elif ball.y > paddle.y

move up

def run()

player_score (x,y)

computer_score (x,y)

player_paddle (x,y)

computer_score (x,y)

ball.reset (x,y)

until exit

paddle.update()

ball.detect_collision()

computer.update()

if ball hits screen

ball.update()

ball.reset()

run()

Nikit Gurung 13
CU6051NA Artificial Intelligence

4.4 Flowchart diagram of the solution

Figure 9: Flowchart for Unlimited Ping Pong

4.5 Explanation of the development process


For the development process of this gaming project, following tools and
technologies were used to achieve it:

Python as the programming language

Python programming language is such a programming language that


assists us to work swiftly and coordinate systems more effectively. This
programming language is readable language, easy to learn and
understand because it is expressive and high level programming
language (Python Software Foundation, 2019).

Nikit Gurung 14
CU6051NA Artificial Intelligence

Pycharm as the Integrated Development Environment (IDE)

In this gaming project, Pycharm has been used as the platform to run my
codes written in python language. The reason behind choosing Pycharm
is that it provides code analysis, excellent code hinting, code navigation,
refactoring, an integrated unit tester, supports popular web technologies
and is cross-platform (Horn, 2019).

Pygame as the library

Pygame is an open source python programming language library which is


used for developing multimedia applications such as games made on top
of the excellent SDL library. Pygame is flexible because it is portable and
can be executed in almost every platform and operating system (pygame,
2019).

Nikit Gurung 15
CU6051NA Artificial Intelligence

4.6 Achieved results

Figure 10: Game GUI

This is the Graphical User Interface (GUI) or the main interface of this game
named Unlimited Ping Pong. As shown in the figure above, in the middle there
is the score board of both the player and the CPU. The left paddle is owned by
the player and the right paddle is owned by the CPU. The white ball in this game
moves from left side to right side and vice versa.

Nikit Gurung 16
CU6051NA Artificial Intelligence

Figure 11: Player wins

In this figure, the change in the scoreboard is shown when the player earns the
point. A point is earned by the player when CPU misses to hit the ball with the
paddle.

Nikit Gurung 17
CU6051NA Artificial Intelligence

Figure 12: CPU wins

In this figure, the change in the scoreboard is shown when the CPU earns the
point. A point is earned by the CPU when the player misses to hit the ball with
the paddle.

Nikit Gurung 18
CU6051NA Artificial Intelligence

5 Conclusion
With the completion of this gaming project, I learned many new things such
as the AI concept of Adversarial search and games, importance of artificial
intelligence in the gaming world and creation of mind maps before
executing the project. Apart from these, I also read books, journals related
to AI and python programming language for the research work. Not only
this, I also made review and analysis of similar existing work. Regarding
the solution section, I explained the solution, gave brief description about
minimax algorithm, wrote pseudocode of the solution, made flowchart
diagram of the solution, gave detail explanation of the development process
and displayed the successful running of the “Unlimited Ping Pong” game
with the help of screenshots.

It solves real world problems by promoting this game to the gamers,


provides a platform for people to spend their leisure time, reduce their
boredom and exercise their brain. Moreover, it also has the provision of
playing against a competitive system player or CPU which makes the game
entertaining as well as challenging.

With the help of this coursework, I am optimistic with the fact that this will
surely help me to develop my coding skills related to python programming
language even more and gives motivation to gain more knowledge about
different AI concepts. Hence, this coursework will surely help me in my
future IT career.

Nikit Gurung 19
CU6051NA Artificial Intelligence

6 References

Al-dehedhawy, I. & Al-Tufaili, F., 2015. Artificial Intelligence - Adversarial


search. [Online]
Available at: https://www.slideshare.net/foofiM/adversarial-search-45837796
[Accessed 26th January 2019].

Bartel, G., 2017. Playing Strategy Games With The Minimax Algorithm.
[Online]
Available at: https://medium.freecodecamp.org/playing-strategy-games-with-
minimax-4ecb83b39b4b
[Accessed 25th January 2019].

Horn, B. V., 2019. What is PyCharm?. [Online]


Available at: https://www.linkedin.com/learning/learning-python-with-
pycharm/what-is-pycharm
[Accessed 28th January 2019].

Kulenovic, M. R., 2008. Game Theory. [Online]


Available at:
http://hypatia.math.uri.edu/~kulenm/mth381pr/GAMETH/gametheory.html
[Accessed 24th January 2019].

MicroPyramid, 2017. UNDERSTANDING SELF AND __INIT__ METHOD IN


PYTHON CLASS.. [Online]
Available at: https://micropyramid.com/blog/understand-self-and-__init__-
method-in-python-class/?fbclid=IwAR2pvI3NwiWUGsllFOicUwGkrvoBVR-
hAbLqnZMuMVWv37Rdv2o4ARjuDsw
[Accessed 28th January 2019].

Millington, I. & Funge, J., 2009. In: ARTIFICIAL INTELLIGENCE FOR


GAMES. New York: Taylor & Francis Group, pp. 5-15.

pygame, 2019. About — wiki. [Online]


Available at: https://www.pygame.org/wiki/about
[Accessed 27th January 2019].

Nikit Gurung 20
CU6051NA Artificial Intelligence

Python Software Foundation, 2019. What is Python? Executive Summary.


[Online]
Available at: https://www.python.org/doc/essays/blurb/
[Accessed 27th January 2019].

Sizer, B., 2018. The Total Beginner's Guide to Game AI. [Online]
Available at: https://www.gamedev.net/articles/programming/artificial-
intelligence/the-total-beginners-guide-to-game-ai-r4942/
[Accessed 24th January 2019].

Sweigart, A., 2017. In: L. Chun, ed. INVENT YOUR OWN COMPUTER
GAMES WITH PYTHON. San Francisco: William Pollock, pp. 1-21.

Nikit Gurung 21

You might also like