Skip to content

Implemented an AI (ai.py) that can automatically navigate to the exit tile of a HaverQuest tile-based game under a certain set of constraints

Notifications You must be signed in to change notification settings

iogolla/HaverQuest-Tile-based-AI-Game

Repository files navigation

HaverQuest AI Adventure

HaverQuest Gameplay

"HaverQuest is a tile-based game, meaning that the game board is represented as a grid composed of tiles. An individual tile can be something like a piece of grass, a piece of a wall, etc... A map is a big matrix of tiles with various properties: grass, walls, and so on. HaverQuest allows maps to be loaded in a format specified by its game engine. For example, the above map is represented as a file like this:

# HaverQuest Map Level 1
# G -- Grass
# B -- Grey brick
# R -- Red brick
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGRRRRRRRGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
BBBBBGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGG
GGGRGGGGGGGGGGGGGGGG
GGGRGGGGGGGGGGGGGGGG
GGGRGGGGGGGGGGGGGGGG
GGGRGGGGGGGGGGGGGGGG
GGGRGGGGGGGGGGGGGGGG

The lines that start with # are comments, and are ignored by HaverQuest's engine as it loads the map. The map is comprised of an n-by-k matrix of characters, where each character stands in for the name of an image. This configuration is also possible to change in a file named config.json, which specifies the properties of various tiles.

On top of the map sits various other tiles. For example, there's a squirrel (the game's main character that you can move with the up, down, left, and right keys) along with a nut. The goal of the game is to get to the nut before running out of "fuel." You lose one fuel each time you make a move (either up, down, left, or right).

Setting up HaverQuest

To run HaverQuest, you'll need to have the pygame module installed. To do this, please run the following command on your computer (reach out to me if this doesn't work):

pip3 install pygame

HaverQuest uses pygame to perform the work of rendering graphics to the screen.

You should then be able to run HaverQuest by using the following command:

python3 game.py

You should then see the empty game board set up, allowing you to play the game." - Professor Kris Micinski

In this project I'll be designing an AI implementation that solves a tile-based squirrel game. To present a clear process of my implementation, I will divide my explanation into two parts.

Part 1: Getting to the Health Pack

This part will make the squirrel move to the health pack for the purpose of building up more fuel. To make the squirrel move to the health pack, I will use the Path Finder class to develop a pathfinder solution. I will integrate its findPath method in my solution to make the squirrel move from the starting cordinate all the way to the health pack.

The methods I need to implement for this part are:

  • (1) getFuel(self), which reports the level of the fuel left
  • (2) move(self,x,y), which accepts x and y in the range [-1,1] and moves to that tile using |x| + |y| fuel
  • (3) getHealthPacks(self), which gets the position of the healthpacks on the board

In addition to these methods, I will add a field called self.healthPack to MyAISquirrel and set it to None then I will assign getHealthPacks(self) method to it so as to avoid losing 20 fuel each clocktick. Before the first clocktick is called, I will make the squirrel move to the healthpack along the path generated by the findPath method from PathFinder class

Part 2: Getting to the Exit Position

In this part, I will construct an AI that moves the squirrel from its current position all the way to the exit position while firing stones at the ferrets. This part will make the squirrel wait until the fuel builds up to 60 before it makes any movement. The intention is to make it gather enough fuel so that it can be able to self-sustain itself through the exit without losing fuel whenever it gets hit by a stone fired by the ferrets. Initially, the squirrel will move horizontally toward the left without firing a single stone but once it starts moving vertically, it will start firing stones up and diagonally toward the northwest direction in attempt to kill the ferrets.

The methods I need to implement for this part are:

  • (1) getExit(self), which reports the position of the exit tile
  • (2) `move(self,x,y), which accepts x and y in the range [-1,1] and moves to that tile using |x| + |y| fuel
  • (3) fireStone(self,x,y, which fires a stone with a set speed along the vector (x * speed, y * speed). You don't have any control over speed, but x and y must be in the range [-1,1]

In addition to these methods, I will add a field called self.exitPosition to MyAISquirrel and set it to None then I will assign getExit(self) method to it so as to avoid losing 30 fuel each clocktick

Community

I welcome anyone with any additional information/suggestions to contact me.

Questions?🤔 Comments?🤨 Suggestions!😊

Contact me at ianelvis6@gmail.com

About

Implemented an AI (ai.py) that can automatically navigate to the exit tile of a HaverQuest tile-based game under a certain set of constraints

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages