Skip to content

Commit 383ba04

Browse files
committed
fix(ai): add tests to catchthecat assignment
1 parent 7bedc11 commit 383ba04

22 files changed

Lines changed: 144 additions & 20 deletions

File tree

courses/artificialintelligence/assignments/catchthecat/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_executable(ai-catchthecat simulator.cpp Catcher.h Cat.h)
1+
add_executable(ai-catchthecat simulator.cpp)
22

33
file(GLOB TEST_INPUT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.in)
44
file(GLOB TEST_OUTPUT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.out)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#pragma once
1+
#ifndef CAT_h
2+
#define CAT_h
23
#include "IAgent.h"
34

45
struct Cat : public IAgent {
56
std::pair<int,int> move(const std::vector<bool>& world, std::pair<int,int> catPos, int sideSize ) override{
67
return {0,0}; // todo: change this
78
}
8-
};
9+
};
10+
#endif
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#pragma once
1+
#ifndef CATCHER_H
2+
#define CATCHER_H
23
#include "IAgent.h"
34

45
struct Catcher : public IAgent {
56
std::pair<int,int> move(const std::vector<bool>& world, std::pair<int,int> catPos, int sideSize ) override{
67
return {0,0}; // todo: change this
78
}
8-
};
9+
};
10+
#endif

courses/artificialintelligence/assignments/catchthecat/IAgent.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#pragma once
1+
#ifndef IAgent_h
2+
#define IAgent_h
23
#include <vector>
34
#include <utility>
45
#include <string>
@@ -16,4 +17,5 @@ struct IAgent {
1617
* @return the position to move to {x,y}. relative to the center of the world.
1718
*/
1819
virtual std::pair<int,int> move(const std::vector<bool>& world, std::pair<int,int> catPos, int sideSize ) = 0;
19-
};
20+
};
21+
#endif

courses/artificialintelligence/assignments/catchthecat/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ The points will be counted as how many moves each one does;
6060

6161
If Cat Wins:
6262

63-
- CatPoints: SideSize * SideSize - CatMoves - K * CPU time;
64-
- CatcherPoints: CatcherMoves - K * CPU time;
63+
- CatPoints: SideSize * SideSize/2 - CatMoves - K*CpuCatTime;
64+
- CatcherPoints: CatcherMoves - K*CpuCatcherTime;
6565

6666
If Catcher Wins:
6767

68-
- CatPoints: CatMoves - K * CPU time;
69-
- CatcherPoints: SideSize * SideSize - CatcherMoves - K * CPU time;
68+
- CatPoints: CatMoves - K*CpuCatTime;
69+
- CatcherPoints: SideSize * SideSize/2 - CatcherMoves - K*CpuCatherTime;
7070

7171
## How to participate:
7272

@@ -136,4 +136,4 @@ public:
136136
*/
137137
virtual std::pair<int,int> move(const std::vector<bool>& world, std::pair<int,int> catPos, int sideSize ) = 0;
138138
};
139-
```
139+
```

courses/artificialintelligence/assignments/catchthecat/simulator.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "Cat.h"
77
#include "Catcher.h"
88

9-
void print(const std::vector<bool>& state, int sideSize, std::pair<int,int> catPos, char turn) {
9+
void print(const std::vector<bool>& state, int sideSize, std::pair<int,int> catPos, const std::string& turn){
1010
std::cout << turn << " " << sideSize << " " << catPos.first << " " << catPos.second << std::endl;
1111
catPos.first += sideSize/2;
1212
catPos.second += sideSize/2;
@@ -47,20 +47,21 @@ std::vector<bool> readBoard(int sideSize) {
4747
}
4848

4949
int main() {
50-
char turn;
50+
std::string turn;
5151
int sideSize;
5252
int catX, catY;
5353
std::vector<bool> blocked;
5454
std::cin >> turn >> sideSize >> catX >> catY;
5555
blocked = readBoard(sideSize);
56-
if(turn == 'C'){
56+
// while(not win){ simulate; } // todo: create your own logic to test and simulate, check for win conditions etc.
57+
if(turn == "CAT"){
5758
Cat cat;
5859
auto catMove = cat.move(blocked, {catX, catY}, sideSize);
59-
print(blocked, sideSize, {catMove.first, catMove.second}, 'T');
60-
} else {
60+
print(blocked, sideSize, {catMove.first, catMove.second}, "CATCHER");
61+
} else if (turn == "CATCHER") {
6162
Catcher catcher;
6263
auto catcherMove = catcher.move(blocked, {catX, catY}, sideSize);
6364
blocked[(catcherMove.second + sideSize/2) * sideSize + catcherMove.first+sideSize/2] = true;
64-
print(blocked, sideSize, {catX, catY}, 'C');
65+
print(blocked, sideSize, {catX, catY}, "CATCHER");
6566
}
6667
}

courses/artificialintelligence/assignments/catchthecat/tests/test-a.in

Whitespace-only changes.

courses/artificialintelligence/assignments/catchthecat/tests/test-a.out

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CAT 5 0 0
2+
. . . . .
3+
. # # . .
4+
. # C . .
5+
. # # . .
6+
. . . . .
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CATCHER 5 1 0
2+
. . . . .
3+
. # # . .
4+
. # . C .
5+
. # # . .
6+
. . . . .

0 commit comments

Comments
 (0)