1. Overview:

Rats vs. Cats is a two-dimensional real-time strategy (RTS) game built using XNA Game Studio 4.0 and C#. Our focus is mostly on the Game AI (movement AI, decision making, and path-finding).

We made this game as the main assignment of Game Programming III course. In this work, our classmate, Ali Kouhzadi, sketched some characters which you can see his work at the end of this page.

There is this small farm in a beautiful village which has a small barn full of cereal and grain. A big gang of rats are attacking this farm and the farmer's cats are to protect the barn from this invasion.

In each level, the player has a limited number of cat units which can be placed in strategic locations and they have to prevent rats from progressing into the farm and finally into the barn; on the left side there is a gang of rats moving towards the barn.

2. Game Design Specifications:

Rat units (Worker rats)
This is the NPC character.

  • Finds the shortest path
  • Runs from cats; does not attack
  • Weakness: Immediately killed

Cat units
There is only one type of cat (player) unit.

  • This unit has a limited range of sight.
  • Finds the shortest path to nearby enemy units.
  • Attacks enemy units after reaching them.
  • Randomly patrols the game level if no enemy is found.

NOTE: All the visuals and graphics of the game are completely designed and created by our team, except the cat character design. The used music here, are from Never Hood (Game) and Benny Hill (TV show).


We made three levels. It starts with easy difficulty and then level by level the difficulty is increased:

  • Number of rats coming into the scene is increased
  • Number of obstacles is decreased so the rats can move easily throughout the scene (it will be harder for cats to catch them)

(Level 1)

(Level 2)

(Level 3)

Layout Design:

These are four stages of the game menu:

(Start Page)

(Main Menu)


3. Technical Design Specifications:

Artificial Intelligence Techniques:

Tactical path-finding: Decision making involves a character working out what to do next. Typically, each character has a range of different behaviors that they could choose to perform: attacking, standing still, exploring and patrolling, and so on.

We have implemented our own customized and modified version of A* algorithm that meets our needs.

For rat units (NPC) our A* algorithm is dynamic and it is run for every single rat unit on the stage every time a cat unit moves; we do this so that the rats (NPCs) can take into account the new position of the cat units.

For cat units we run A* algorithm every time they need to move; this includes the situation in which a cat unit is idle for more than 5 seconds; we explain this in more detail in Decision Making and also Movement AI parts of this section.

Decision making: both cat units and rat units use tactical path-finding to find the best path possible in any given time.

The decision making system needs to work out which of these behaviors is the most appropriate at each moment of the game. The chosen behavior can then be executed using movement AI and/or animation.

Decision making for player units (cat units):

The decision making system for the cat is as follows:

  • CHECK if the cat unit is IDLE for more than 3,000 milliseconds


    • CHECK the CHOSEN NODE and see if it is BLOCKED

      • If NOT BLOCKED, PASS the chosen node to PATH-FINDING CLASS

      • ELSE set TIMER TO 0 (zero) (this unit should wait again)

  • CHECK within the RADIUS OF TWO (2) NODES (80 pixels) for NPC UNIT(s)

    If FOUND,

    • If the NPC unit is not being PURSUED by another cat unit,

      • PURSUE the NPC unit(s) (Pursue: predict the NPC's next location)

      • PASS the predicted location (node) to the PATH-FINDING CLASS

    • ELSE remain IDLE

Cat's field of view (radius of 80 pixels)

Decision making for NPCs (rat units):

The decision making system for the rat unit (NPC) is as follows:

  • Check the neighboring nodes in radius of 1 node (40 pixels),

    • If any cat unit(s) found, run A* again and find another path
    • Else continue to (b)

  • If the next node in the chosen path is blocked by another NPC,

    • Stay in the current position for 3,000 milliseconds,

      • After 3,000 milliseconds if the node is still blocked, run A* algorithm

      • again to find another path. (Read the deadlock section bellow)

    • ELSE if it is not blocked, reserve the node (BLOCKED) and move to the reserved node

Decision making for NPCs (rat units)

Deadlock: there is a possibility that a deadlock occurs for NPCs. It happens in a situation where unit A is waiting for unit B to move on and free the location it is holding, and B is waiting for A to do the same thing. As a result, none of them will move and they will stay in their positions for ever (or until a cat unit kill at least one of them).

To avoid this, we have set a time limit of 3,000 milliseconds for an NPC to wait for its target node to become unblocked again; after this time limit, every unit that is trapped in a deadlock situation will run the A* algorithm again and finds a completely new path to follow.

So both characters' next move will be different nodes, and therefore the deadlock situation is handled.

Movement AI: A combination of results from Decision making AI and Path-finding AI will be used to handle the movement AI.

For example, when a rat is seen by a cat, the cat decides to SEEK the rat, and the rat decides to FLEE.

Also we have a form of SEPARATION, and ALIGNMENT (similar to what you see in flocking behavior) for the NPCs. We didn't exactly implement the flocking behavior, but we used the separation and alignment concepts for the NPCs.

Separation for NPCs works in this way: every NPC sets the node that it is currently residing in as BLOCKED, so other NPCs cannot move on to this BLOCKED node; if an NPC is waiting for a BLOCKED node for more than 3,000 milliseconds, we run A* algorithm one more time for this particular NPC so it can continue its way from a completely new path.

For the player (cat) units we have the WANDERING behavior; if a player unit is idle for more than 3,000 milliseconds, it will randomly choose a neighboring node and move over there, and again after another 3,000 milliseconds it will move to a randomly chosen node and so on.

4. Game Development Assessment and Issues:

What we are most proud of about your game:

The first thing that we would like to point out is that thanks to this subject, lectures and tutorials and self-study we have learned C#, XNA and Artificial Intelligence concepts (and their implementations to some extend) in such a short time and from the scratch; so overall, we are satisfied with everything that we accomplished until now.
The things that we like to point out as "most satisfying" are:

  • Implementing, customizing and modifying A* algorithm to meet our specific needs

  • Visuals and appearance: when we started this project, we thought that we will surely have problems with the visuals and appearance of this game because we have nearly zero experience in graphics design (we are not FCM students!). But right now we are very satisfied with the graphics and appearance of our game.

What changes we have made to our original game design plan:

  • Soldier Rats: Removed the second type of NPCs (soldier rats) for technical reasons and lack of time; the graphics and animations (especially for attack) were not ready and we didn't have enough time to finish the graphics part. The AI part could be easily done by slightly modifying the currently used methods.

  • Graphics settings: in the proposal we mentioned that we want to include a graphics settings section in the main menu, so users can choose the quality of the textures. But because of the nature of the 2D games, we came to conclusion that the texture quality does not have any effects on the appearance since the viewer's distance from objects will not change.

What we would do next if you had more time:

If we had more time and if we could focus on developing this game only (without having to worry about other subjects, assignments, etc.), we would love to at least try to do the followings:

  • Add several different player and non-player (enemy) characters with different attributes and abilities.

  • Formulate the level-design and have a solid specification for it.

  • Add different layers of levels (for example, 5 layers each 10 levels); each layer telling a part of the story and having a different environment and atmosphere compared to other layers.

  • Work on full-screen mode and different resolutions.

  • Add Xbox 360 controller support.

What you would do differently next time:

Based on what we have learned during this trimester, we really like to try and right the code from the scratch, because right now we have a good and solid understanding about how the things work and how the pipeline of XNA works. So the next time our code and the implementations of artificial intelligence algorithms will be more will be more efficient.

5. Game Manual:

At the start of each level you have a limited number of cat units available; you choose them from the bar at the bottom of the screen. Then you can place them in a place you desire.

After that, you can move your player characters once in every 10 seconds. For moving them, first you have to select the character and then click on the destination.

In order to win a level, you have to catch the rats that come into the screen and you will lose if more than 9 rats reach the barn's door.

5. Video:

This is the captured video of the Rats vs Cats game below:

6. Sketches:

© 2013 Davood rasti & Alireza Rasti. All Rights Reserved.