Skip to content

Commit d78cc50

Browse files
committed
feat(cattrap): add catch the cat assignment
1 parent a3baa88 commit d78cc50

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

  • courses/artificialintelligence/assignments/catchthecat
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Catch the Cat
2+
3+
You are in charge of creating 2 agents that will be playing the game of Catch the Cat.
4+
5+
## Game rules
6+
7+
The game is played on a NxN board where N is an odd number that follows the sequence of `1+4*x` with `x` starnig from `1`: `5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, ...`. The game starts with a cat in the center of the board, and it starts with some random blocks placed randomly.
8+
9+
The game is played in turns, where each player can move the cat or a catcher.
10+
11+
### Board
12+
13+
The board position follows `{x, y}` notation.
14+
15+
The center of the board is `{0,0}` and the board is a square with `N` cells on each side.
16+
17+
The board is a pointy top hexagon with the first line aligned to the left:
18+
19+
```
20+
/ \ / \ / \
21+
|-1-1| 0-1| 1-1|
22+
\ / \ / \ / \
23+
|-1 0| 0 0| 1 0|
24+
/ \ / \ / \ /
25+
|-1 1| 0 1| 1 1|
26+
\ / \ / \ /
27+
```
28+
29+
### Moves
30+
31+
The Cat moves in any of the 6 immediate neighbors, but it cannot move to a blocked cell.
32+
33+
The Catcher moves by blocking a cell. A cell can be blocked only once each turn.
34+
35+
### Win condition
36+
37+
1. If the cat is surrounded by blocked cells in all 6 directions, it cannot move and the catcher wins.
38+
2. If the cat reaches a border cell, it wins.
39+
3. If the cat makes invalid moves, it loses. Invalid moves are:
40+
41+
- Move to a blocked cell;
42+
- Move to a cell that is not a neighbor;
43+
- Stay in the same cell;
44+
45+
4. The catcher makes invalid moves, it loses. Invalid moves are:
46+
47+
- Block an already blocked cell;
48+
- Block a cell outside the board;
49+
- Block a cell where the cat is;
50+
51+
## Suggested coding interface
52+
53+
The move function should return a `std::pair<int, int>` with the `{x, y}` position. And receives as parameter `const std::vector<bool>&` as the blocked cells, where `true` means blocked and `false` means free, and `const std::pair<int, int>&` as the current position of the cat.
54+
55+
Suggested interface of an agent:
56+
57+
```cpp
58+
class Agent {
59+
public:
60+
Agent() = default;
61+
virtual ~Agent() = default;
62+
63+
virtual pair<int, int> move(const vector<bool>& blocked, const pair<int, int>& cat) = 0;
64+
};
65+
```
66+
67+
## Competition
68+
69+
All students enrolled in the competition will submit both agents. The agents will play against each other and the winner will be the one that wins the most games. In case of a tie, the winner will be the one that wins the fastest game.

0 commit comments

Comments
 (0)