COMP3211 Project. Artificial Intelligence for Tron game. Group 7. Chiu Ka Wa ( ) Chun Wai Wong ( ) Ku Chun Kit ( )

Similar documents
game tree complete all possible moves

Using Artificial intelligent to solve the game of 2048

Game Playing for a Variant of Mancala Board Game (Pallanguzhi)

Programming an Othello AI Michael An (man4), Evan Liang (liange)

Documentation and Discussion

CS188 Spring 2014 Section 3: Games

CS 229 Final Project: Using Reinforcement Learning to Play Othello

CMSC 671 Project Report- Google AI Challenge: Planet Wars

ARTIFICIAL INTELLIGENCE (CS 370D)

Adversarial Search. CS 486/686: Introduction to Artificial Intelligence

Five-In-Row with Local Evaluation and Beam Search

More on games (Ch )

CS 2710 Foundations of AI. Lecture 9. Adversarial search. CS 2710 Foundations of AI. Game search

CS221 Project Final Report Gomoku Game Agent

CS 1571 Introduction to AI Lecture 12. Adversarial search. CS 1571 Intro to AI. Announcements

2048: An Autonomous Solver

More on games (Ch )

Adversarial Search. CS 486/686: Introduction to Artificial Intelligence

Adversary Search. Ref: Chapter 5

CMPUT 396 Tic-Tac-Toe Game

CS 188: Artificial Intelligence Spring Announcements

Games and Adversarial Search II

For slightly more detailed instructions on how to play, visit:

Adversarial Search and Game- Playing C H A P T E R 6 C M P T : S P R I N G H A S S A N K H O S R A V I

Artificial Intelligence. Minimax and alpha-beta pruning

CS188 Spring 2010 Section 3: Game Trees

mywbut.com Two agent games : alpha beta pruning

AI Plays Yun Nie (yunn), Wenqi Hou (wenqihou), Yicheng An (yicheng)

Unit-III Chap-II Adversarial Search. Created by: Ashish Shah 1

CS188 Spring 2010 Section 3: Game Trees

Games (adversarial search problems)

Comp th February Due: 11:59pm, 25th February 2014

CS 771 Artificial Intelligence. Adversarial Search

Set 4: Game-Playing. ICS 271 Fall 2017 Kalev Kask

Today. Types of Game. Games and Search 1/18/2010. COMP210: Artificial Intelligence. Lecture 10. Game playing

COMP219: COMP219: Artificial Intelligence Artificial Intelligence Dr. Annabel Latham Lecture 12: Game Playing Overview Games and Search

Artificial Intelligence Lecture 3

Theory and Practice of Artificial Intelligence

Computer Science and Software Engineering University of Wisconsin - Platteville. 4. Game Play. CS 3030 Lecture Notes Yan Shi UW-Platteville

Monte Carlo based battleship agent

Game-Playing & Adversarial Search

Introduction to Artificial Intelligence CS 151 Programming Assignment 2 Mancala!! Due (in dropbox) Tuesday, September 23, 9:34am

Announcements. Homework 1 solutions posted. Test in 2 weeks (27 th ) -Covers up to and including HW2 (informed search)

CSC 380 Final Presentation. Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis

CS 387/680: GAME AI BOARD GAMES

AI Agent for Ants vs. SomeBees: Final Report

Game-playing: DeepBlue and AlphaGo

Adversarial Search 1

Experiments on Alternatives to Minimax

Announcements. CS 188: Artificial Intelligence Spring Game Playing State-of-the-Art. Overview. Game Playing. GamesCrafters

Game-playing AIs: Games and Adversarial Search FINAL SET (w/ pruning study examples) AIMA

Module 3. Problem Solving using Search- (Two agent) Version 2 CSE IIT, Kharagpur

CPS331 Lecture: Search in Games last revised 2/16/10

CS 188: Artificial Intelligence Spring 2007

Last update: March 9, Game playing. CMSC 421, Chapter 6. CMSC 421, Chapter 6 1

Game Playing. Garry Kasparov and Deep Blue. 1997, GM Gabriel Schwartzman's Chess Camera, courtesy IBM.

More Adversarial Search

Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning

Programming Project 1: Pacman (Due )

CS 188: Artificial Intelligence. Overview

Artificial Intelligence Adversarial Search

Real-Time Connect 4 Game Using Artificial Intelligence

Computing Science (CMPUT) 496

CS 4700: Artificial Intelligence

HUJI AI Course 2012/2013. Bomberman. Eli Karasik, Arthur Hemed

Announcements. Homework 1. Project 1. Due tonight at 11:59pm. Due Friday 2/8 at 4:00pm. Electronic HW1 Written HW1

Comp 3211 Final Project - Poker AI

CS 380: ARTIFICIAL INTELLIGENCE MONTE CARLO SEARCH. Santiago Ontañón

UNIVERSITY of PENNSYLVANIA CIS 391/521: Fundamentals of AI Midterm 1, Spring 2010

Monte Carlo Tree Search

Algorithms for Data Structures: Search for Games. Phillip Smith 27/11/13

CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #5

Foundations of AI. 6. Adversarial Search. Search Strategies for Games, Games with Chance, State of the Art. Wolfram Burgard & Bernhard Nebel

Artificial Intelligence

Outline. Game Playing. Game Problems. Game Problems. Types of games Playing a perfect game. Playing an imperfect game

COMP219: Artificial Intelligence. Lecture 13: Game Playing

Learning to Play like an Othello Master CS 229 Project Report. Shir Aharon, Amanda Chang, Kent Koyanagi

Achieving Desirable Gameplay Objectives by Niched Evolution of Game Parameters

CS61B Lecture #22. Today: Backtracking searches, game trees (DSIJ, Section 6.5) Last modified: Mon Oct 17 20:55: CS61B: Lecture #22 1

CS 491 CAP Intro to Combinatorial Games. Jingbo Shang University of Illinois at Urbana-Champaign Nov 4, 2016

Adversarial Search (Game Playing)

CS885 Reinforcement Learning Lecture 13c: June 13, Adversarial Search [RusNor] Sec

Google DeepMind s AlphaGo vs. world Go champion Lee Sedol

Game Playing: Adversarial Search. Chapter 5

2 person perfect information

Artificial Intelligence

By David Anderson SZTAKI (Budapest, Hungary) WPI D2009

CS221 Final Project Report Learn to Play Texas hold em

CS188: Artificial Intelligence, Fall 2011 Written 2: Games and MDP s

CS 4700: Foundations of Artificial Intelligence

Monte Carlo Tree Search and AlphaGo. Suraj Nair, Peter Kundzicz, Kevin An, Vansh Kumar

Game-playing AIs: Games and Adversarial Search I AIMA

Adversarial Search: Game Playing. Reading: Chapter

CS 221 Othello Project Professor Koller 1. Perversi

Automated Suicide: An Antichess Engine

Game Playing Beyond Minimax. Game Playing Summary So Far. Game Playing Improving Efficiency. Game Playing Minimax using DFS.

Principles of Computer Game Design and Implementation. Lecture 20

CS 380: ARTIFICIAL INTELLIGENCE ADVERSARIAL SEARCH. Santiago Ontañón

Adverserial Search Chapter 5 minmax algorithm alpha-beta pruning TDDC17. Problems. Why Board Games?

Prepared by Vaishnavi Moorthy Asst Prof- Dept of Cse

Transcription:

COMP3211 Project Artificial Intelligence for Tron game Group 7 Chiu Ka Wa (20369737) Chun Wai Wong (20265022) Ku Chun Kit (20123470)

Abstract Tron is an old and popular game based on a movie of the same name. There are totally four sub games, and Light Cycles is one of the more popular ones. Various attempts have been made to create an artificial intelligence that can play the game well. There is also an online platform of Light Cycles for developers to write their own A.I. and compete against each other. In this report, we will review on the methodology we have taken to approach the game. Keywords Minimax, Flood filling, Pathfinding Introduction to Tron Battle Problem Definition Light Cycle consists of a 30 (width) by 20 (height) rectangular grid with two players starting at different random locations. The two AI players move on the grid, leaving a trail on the way. A player loses he makes a move that puts him outside the grid, or colliding with trails by himself or by others. The last surviving player is the victor. Input of the game The program reads from STDIN, with the following inputs: [1] Line 1: Two integers N and P. Where N is the total number of players and P is your player number for this game. The N following lines: One line per player. First line is for player 0, next line for player 1, etc. Each line contains four values X0, Y0, X1 and Y1. (X0, Y0) are the coordinates of the initial position of the light ribbon (tail) and (X1, Y1) are the coordinates of the current position of the light ribbon (head) of the player. Once a player loses, his/her X0 Y0 X1 Y1 coordinates are all equal to -1 (no more light ribbon on the grid for this player). Game mechanics In each turn, every player is required choose an action in {UP, DOWN, LEFT, RIGHT} within 100ms. Every move is legal, but making a move that collides with the trails left behind by any player, or moving out of the game board would causes the player to lose the game immediately, and turning trail he has left behind turns back to empty cells. After an AI has decided the next move, it may collide with a trail left behind by players or moving out of game grid, which means instant defeat of the player colliding with a trail. His own trail will be removed and the remaining players compete until there is only one player left who will in turn becomes the victor. Our project made use of an online platform Codingame [1] which let us compete with thousands other player. The board size in the platform is 30x20, and we kept

player number to 2 for simplicity. Fig.1 A typical Tron battle game (flooding.gif) Challenges Although the game only involve deciding one action from a set of 4 possible actions, it is difficult for computers to brute force the optimal solution like the game of Go. There are many different strategies to win such as wall-hugging, blocking off opponent, or simply trying to survive as long as possible and wait to the opponents to make mistake, it can be difficult to interpret the best move based on the game state, or to compare the utility of different game states. Moreover, the game a repeated game of many steps and future possibilities while the computation time given to an AI each step is capped at 100ms. The complexity of the problem also increases greatly with the number of players. For example, if we want to do a simple depth-first search, the worst case can get us O(4^n) for a depth of n. Some developers also attempted using monte-carlos search, but minimax is more discussed in the game forum among contestants. A number of heuristics analyzing the free space on the board and the relative positions of the players have yielded promising results. Due to the limited time in calculation of steps, minimax with limited depth and a heuristic to evaluate the game states on the tree leaves are widely adopted. Related Work Tron has been an old game and a lot of attempts have been made to create an artificial

intelligence that can perform well in this game. Some have tried to find a winning strategy for the game [2], but was found to be an N-P hard problem. Different techniques have been employed to find optimal solutions, including the heuristic techniques and the monte-carlo search. Tron is chosen as a game for programmers to design artificial intelligence to compete against, and a popular algorithm used is minmax [3]. In our work, we also implemented minmax algorithm in our design. In previous works [4], attempts have been made to improve heuristics to increase the performance of the agents, such as trapping the opponent and avoid getting trapped. Baseline and Oracles Our baseline emulates a very dumb AI, which does not do anything except choosing randomly between possible action set S: { Up, Down, Left, Right }. This AI is rather suicidal, so wd d also constrain it to not suicide unless necessary in the next step. So it searches forward to check for constraints, but it doesn t backtrack to fix it s own mistake because it will only decide randomly for next step among the possible action set Sp: { z z in S, z won t lead to suicide }. The oracle AI of this game plays very well, like a real human or even better. We expect an oracle AI to be able to perform tricks like not trapping itself, prefer larger space than smaller place that is more likely to get trapped later. More importantly, it should not suicide unless it is inevitable. Oracle AI could be implemented using minimax search, with alpha-beta pruning to speed up the search process, combined with an appropriate heuristics to evaluate the utility at the leaves. Additionally, this AI should consider the opponent s playing pattern, whether it is moving randomly or according to minimax, since the prediction of the opponent s action plays a significant role in minimax search. Our Approach In this project, we try to build an optimal solution that performs similarly to the oracle of the game. We decided to use minimax, and explore different heuristics based on reasonable strategies, for example, always leaving a row as an emergency escape path, to build the AI bot we have at the end. Minimax Due to the time limitation imposed by the game engine (we had only 100ms to make a decision), we had to use minimax with fewer depths. After experimenting with different heuristics, we discovered that a depth of 6 levels is the furthest we can go. The minimax search expand the nodes of the players heads and maximizes each player s option accordingly. After expanding the nodes around the AI s head, the AI would choose the cell with the highest heuristics value based on the minimax search.

Heuristics Admissible move The most basic idea to survive in the game is not to run into walls or trails until there is no options left. These actions are omitted in the searches to save run time. Surrounding empty spaces One simple calculation is to sum the surrounding empty cells as the heuristic, as empty cells are key to surviving in this game. However, this method does not take opponent's movement and strategies into consideration. It also has little meaning if the minimax has too few depths. Distance from opponents The algorithm has very limited depths, getting close to the opponent showed better results given limited number of depths because getting closing to the opponents effectively reduce the area that needs to be considered, and less depths is required. Flood filling When there are multiple admissible actions, flood filling helps deciding between which action should be taken. Generally speaking, the AI should move towards the direction with more empty spaces to minimize the chance of getting blocked or trapping itself inside. Implementations Minimax with Heuristic In this version, a few heuristics were chosen to evaluate the score of each cell. The idea of this algorithm is to get close to the opponent as quickly as possible, up to a minimum distance. After that, the player would choose the cell with the least trails and walls around. The player would also specifically avoid travelling on the edge to increase escaping options. The score is calculated by the sum of the values of the surrounding cells, a positive score for an empty cell, negative score for trails, and even larger penalty for cells out of the game board, and a reciprocal of the distance between the cell and the opponent with a huge weight. The large weight for the distance component means this will dominate the player movement. The weight than become 0 after the distance drops to 5, where the cell depends on the sum of surrounding cells. Undesirable moves are given low score, and losing moves are given very low scores that indicate negative infinity. Based on the evaluation method, a minimax with a maximum of 5 depths are used to

calculate the best move. Source code of this implementation is available at: https://github.com/tommyku/comp3211-tron/blob/master/minimax/tron.cpp You may run the code by copying the source code into the official game site https://www.codingame.com/ide/puzzle/tron-battle, and choose to run it with programming language C++. Flood Filling This implementation went through several phases, from simple local space counting to flood filling that yielded great results. Phase one was simple local space counting. First the bot evaluates all admissible actions that wouldn t lead to suiciding, and for each admissible option it checks for the surrounding 8 cells, and pick the one with highest empty cell count. This gave us some degree of success, but it is still rather suicidal, you may refer to the following game recordings. Fig.2 Local space counting avoiding trapping itself (localspace.gif) (our AI is in orange)

Fig.3 Local space counting trapping itself (suicidal2.gif) (our AI is in orange) In phase two, we tried to avoid most death by trapping ourselves and tried to increase survival rate by choosing the direction with the widest accessible space. Simply increasing the kernel size of local space counting wouldn t work because the road may be blocked off, so we need flood filling instead. We use a flood filling algorithm with limited size of 7 because we would run out of computation time otherwise. Interestingly, if we increase the size to, say, 21, the algorithm actually did worse than with 7. The result was good and it brought us from the Wood league to Bronze league (where the AIs are stronger).

Fig.4 Flood filling effectively avoids getting trapped at the bottom (avoid_hole_v2.gif) (our AI is in orange) Our flood filling algorithm successfully avoid the apparent trap at the bottom set by the opponent, and it survived long enough for the opponent to make mistake. This is powerful because we didn t even do a minimax, just simple flood filling. Fig.5 Flood filling behavior of seeking wider space (flooding.gif) (our AI is in orange) This game showcases the behavior of our flood filling algorithm in which in the middle of the game it sort of stayed in the middle but later turned to the left as

the opponents claim the space on the right, this is exactly as what we have expected, it should seek space and stay alive. An alternative to this is of course to be aggressive and seek the opponent and try to limit their available space. However we didn t do this in our project. Source code of this implementation is available at: https://github.com/tommyku/comp3211-tron/blob/master/floodfilling/ver5-floodfill.rb You may run the code by copying the source code into the official game site https://www.codingame.com/ide/puzzle/tron-battle, and choose to run it with programming language Ruby. Evaluation The minimax AI was ranked 1246/1262 on the Bronze league and the flood filling AI was ranked 245/1262. We believe this result is satisfactory as our AIs avoided many suicidal behaviors such as getting trapped and they survived by setting up traps to limit the opponents and stayed away from traps laid by ourselves and by the opponent. We identified some winning conditions of the game, and undesirable approaches. Minimax bot The approach to get close to the opponents yielded interesting results. Sometimes the player can skillfully block opponents paths, but sometimes it worked the other way around. Upon closer examination of the cases, the outcome of this approach depends heavily on their initial positions. In the future, we might look into possibilities of algorithms that makes use of, or be aware of the starting advantages.

Fig.6 Following an enemy and then trapping them (t_trap.gif) (our AI is in orange) After implementing the minimax algorithm, the performance of the player greatly reduced. It was likely due to the heuristics not correctly predicting the opponent's moves. There are many possible heuristics, running minimax using only simple heuristics would greatly reduce options originally available. The minmax algorithm also only support very few layers as the computation time is limited to 100ms. Flood filling bot This approach worked well for most of the cases, it avoid suicidal behaviors and never hit the walls unless it is inevitable. However, it is too passive that when confronting with an aggressive player, the living space of the bot sometimes are hugely confined. See the following recording for example.

Fig.7 Our AI being actively blocked by the opponent (aggressive.gif) (our AI is in orange) We believe further tweaking of the algorithm by integrating with minimax, or using opponent-seeking strategy to block off opponents before we get ourselves blocked, then switch into survival mode to avoid mistakes in the end game should give us better performance. Conclusion After testing the different approaches and heuristics, we identified some strategies that are more effective such as flood filling. We have seen that minimax isn t automatically the best approach because it faces limited resource and we needed to tune a better heuristic to evaluate the game states at the leaves. Rather, an algorithm as simple as flood filling, could avoid many mistakes despite it didn t try explicitly to predict the future. We realized several ways that we can improve. In the future we may try to analyze the opponent's behaviors and incorporate the results in the minimax algorithm, and try to analyze the game state from a different perspective. References [1] Coding Games and Programming Challenges to Code Better, CodinGame. [Online]. Available: https://www.codingame.com/ide/puzzle/tron-battle. [Accessed: 24-Nov-2017]. [2] T. Kloks, H. L. Bodlaender and T. Klokst, "Fast Algorithms for the TRON Game on Trees", 2001. [3] "Coding Games and Programming Challenges to Code Better", CodinGame,

2017. [Online]. Available: https://www.codingame.com/multiplayer/botprogramming/tron-battle. [Accessed: 20- Oct- 2017]. [4] "CS221 Project progress - Light cycle racing in Tron", AI Agent for Light Cycle Racing in Tron, 2017. [Online]. Available: https://web.stanford.edu/~jbboin/doc/ai_lightcycle.pdf. [Accessed: 20- Oct- 2017].