-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
courses.tolstenko.net |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
subdirlist(activity_dir ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
foreach(subdir ${activity_dir}) | ||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt") | ||
add_subdirectory(${subdir}) | ||
endif() | ||
endforeach() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
file(GLOB adv_intro_src CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) | ||
|
||
enable_testing() | ||
|
||
add_executable(adv-01-intro ${adv_intro_src}) | ||
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake) | ||
target_include_directories(adv-01-intro PUBLIC ${DOCTEST_INCLUDE_DIR}) | ||
target_link_libraries(adv-01-intro doctest::doctest) | ||
doctest_discover_tests(adv-01-intro) | ||
|
||
if(ENABLE_TEST_COVERAGE) | ||
target_compile_options(adv-01-intro PUBLIC -O0 -g -fprofile-arcs -ftest-coverage) | ||
target_link_options(adv-01-intro PUBLIC -fprofile-arcs -ftest-coverage) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
#include <doctest/doctest.h> | ||
using namespace std; | ||
|
||
// create a function that allocates memory on the heap and returns a raw pointer to it | ||
char* allocateMemoryAndClear(int numBytes, char value) { | ||
// implement this function | ||
} | ||
|
||
// create a function that deallocates memory on the heap | ||
void deallocateMemory(char*& ptr) { | ||
// implement this function | ||
} | ||
|
||
|
||
// DO NOT CHANGE THE CODE BELOW THIS LINE | ||
TEST_CASE("allocateMemory") { | ||
char* ptr = allocateMemoryAndClear(3, 'u'); | ||
CHECK(ptr != nullptr); | ||
CHECK(ptr[0] == 'u'); | ||
CHECK(ptr[1] == 'u'); | ||
CHECK(ptr[2] == 'u'); | ||
deallocateMemory(ptr); | ||
CHECK(ptr == nullptr); | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
subdirlist(advcpp_chapters ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
foreach(subdir ${advcpp_chapters}) | ||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt") | ||
add_subdirectory(${subdir}) | ||
endif() | ||
endforeach() |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function(add_custom_test TEST_NAME TEST_EXECUTABLE TEST_INPUT_LIST TEST_EXPECTED_OUTPUT_LIST) | ||
list(LENGTH TEST_INPUT_LIST num_tests) | ||
|
||
MATH(EXPR num_tests "${num_tests} - 1") | ||
message(STATUS "Adding ${num_tests} tests for ${TEST_NAME}.") | ||
|
||
set(TEST_COMMANDS "") | ||
foreach(index RANGE 0 ${num_tests}) | ||
list(GET TEST_INPUT_LIST ${index} TEST_INPUT) | ||
list(GET TEST_EXPECTED_OUTPUT_LIST ${index} TEST_EXPECTED_OUTPUT) | ||
|
||
list(APPEND TEST_COMMANDS | ||
COMMAND ${CMAKE_COMMAND} -E echo "Running test: ${TEST_NAME}_${index}. Using input file: ${TEST_INPUT}" | ||
COMMAND ${CMAKE_COMMAND} -E cat ${TEST_INPUT} | ||
COMMAND ${CMAKE_COMMAND} -E echo "==================================" | ||
COMMAND ${CMAKE_COMMAND} -E echo "Expected Output from ${TEST_NAME}_${index}:" | ||
COMMAND ${CMAKE_COMMAND} -E cat ${TEST_EXPECTED_OUTPUT} | ||
COMMAND ${CMAKE_COMMAND} -E echo "==================================" | ||
COMMAND ${TEST_EXECUTABLE} < ${TEST_INPUT} > test_output_${index}.txt | ||
COMMAND ${CMAKE_COMMAND} -E echo "Actual Output from ${TEST_NAME}_${index}:" | ||
COMMAND ${CMAKE_COMMAND} -E cat test_output_${index}.txt | ||
COMMAND ${CMAKE_COMMAND} -E echo "==================================" | ||
COMMAND ${CMAKE_COMMAND} -E compare_files ${TEST_EXPECTED_OUTPUT} test_output_${index}.txt | ||
COMMAND ${CMAKE_COMMAND} -E echo "Test ${TEST_NAME}_${index} passed." | ||
) | ||
endforeach() | ||
|
||
add_custom_target(${TEST_NAME} | ||
${TEST_COMMANDS} | ||
DEPENDS ${TEST_EXECUTABLE} | ||
) | ||
endfunction() | ||
|
||
add_subdirectory(assignments/flocking) | ||
add_subdirectory(assignments/maze) | ||
add_subdirectory(assignments/life) | ||
add_subdirectory(assignments/rng) | ||
add_subdirectory(assignments/catchthecat) |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
add_executable(ai-catchthecat simulator.cpp) | ||
|
||
file(GLOB TEST_INPUT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.in) | ||
file(GLOB TEST_OUTPUT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.out) | ||
|
||
add_custom_test(ai-catchthecat-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ai-catchthecat "${TEST_INPUT_FILES}" "${TEST_OUTPUT_FILES}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef CAT_h | ||
#define CAT_h | ||
#include "IAgent.h" | ||
|
||
struct Cat : public IAgent { | ||
std::pair<int,int> move(const std::vector<bool>& world, std::pair<int,int> catPos, int sideSize ) override{ | ||
return {0,0}; // todo: change this | ||
} | ||
}; | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef CATCHER_H | ||
#define CATCHER_H | ||
#include "IAgent.h" | ||
|
||
struct Catcher : public IAgent { | ||
std::pair<int,int> move(const std::vector<bool>& world, std::pair<int,int> catPos, int sideSize ) override{ | ||
return {0,0}; // todo: change this | ||
} | ||
}; | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef IAgent_h | ||
#define IAgent_h | ||
#include <vector> | ||
#include <utility> | ||
#include <string> | ||
|
||
// NO NOT CHANGE THIS FILE | ||
struct IAgent { | ||
public: | ||
/** | ||
* @brief the agent implementation. the center of the world is {0,0}, top left is {-sideSize/2, -sideSize/2} and the bottom right is {sideSize/2, sideSize/2}. | ||
* | ||
* @param world the world as a vector of booleans. true means there is a wall, false means there is no wall. The vector is the linearization of the matrix of the world. | ||
* @param catPos the position of the cat in the world {x,y} relative to the center of the world. | ||
* @param sideSize the side size of the world. it will be always a square that follows the sequence of 4*i+1: 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, ... | ||
* | ||
* @return the position to move to {x,y}. relative to the center of the world. | ||
*/ | ||
virtual std::pair<int,int> move(const std::vector<bool>& world, std::pair<int,int> catPos, int sideSize ) = 0; | ||
}; | ||
#endif |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// DO NOT SUBMIT THIS FILE | ||
// IMPROVE THIS SIMULATOR FOR YOUR OWN USE | ||
// this code is not well tested, use as entry point for your own simulator | ||
#include <iostream> | ||
#include <vector> | ||
#include "Cat.h" | ||
#include "Catcher.h" | ||
|
||
void print(const std::vector<bool>& state, int sideSize, std::pair<int,int> catPos, const std::string& turn){ | ||
std::cout << turn << " " << sideSize << " " << catPos.first << " " << catPos.second << std::endl; | ||
catPos.first += sideSize/2; | ||
catPos.second += sideSize/2; | ||
auto catPosIndex = catPos.second * sideSize + catPos.first; | ||
for(int y=0; y<sideSize; y++) { | ||
if (y % 2 == 1) std::cout << ' '; | ||
for (int x = 0; x < sideSize; x++) { | ||
if(y * sideSize + x == catPosIndex) { | ||
std::cout << 'C'; | ||
} else | ||
std::cout << (state[y * sideSize + x] ? '#' : '.'); | ||
if (x < sideSize - 1) std::cout << ' '; | ||
} | ||
std::cout << std::endl; | ||
} | ||
} | ||
|
||
std::vector<bool> readBoard(int sideSize) { | ||
std::vector<bool> board; | ||
board.reserve(sideSize*sideSize); | ||
for(int i=0; i<sideSize*sideSize; i++) { | ||
char c; | ||
std::cin >> c; | ||
switch (c) { | ||
case '#': | ||
board.push_back(true); | ||
break; | ||
case '.': | ||
case 'C': | ||
board.push_back(false); | ||
break; | ||
default: | ||
i--; | ||
break; | ||
} | ||
} | ||
return board; | ||
} | ||
|
||
int main() { | ||
std::string turn; | ||
int sideSize; | ||
int catX, catY; | ||
std::vector<bool> blocked; | ||
std::cin >> turn >> sideSize >> catX >> catY; | ||
blocked = readBoard(sideSize); | ||
// while(not win){ simulate; } // todo: create your own logic to test and simulate, check for win conditions etc. | ||
if(turn == "CAT"){ | ||
Cat cat; | ||
auto catMove = cat.move(blocked, {catX, catY}, sideSize); | ||
print(blocked, sideSize, {catMove.first, catMove.second}, "CATCHER"); | ||
} else if (turn == "CATCHER") { | ||
Catcher catcher; | ||
auto catcherMove = catcher.move(blocked, {catX, catY}, sideSize); | ||
blocked[(catcherMove.second + sideSize/2) * sideSize + catcherMove.first+sideSize/2] = true; | ||
print(blocked, sideSize, {catX, catY}, "CATCHER"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CAT 5 0 0 | ||
. . . . . | ||
. # # . . | ||
. # C . . | ||
. # # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CATCHER 5 1 0 | ||
. . . . . | ||
. # # . . | ||
. # . C . | ||
. # # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CAT 5 0 0 | ||
. . . . . | ||
. # # . . | ||
. # C # . | ||
. # . . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CATCHER 5 0 1 | ||
. . . . . | ||
. # # . . | ||
. # . # . | ||
. # C . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CAT 5 0 0 | ||
. . . . . | ||
. # # . . | ||
. # C # . | ||
. . # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CATCHER 5 -1 1 | ||
. . . . . | ||
. # # . . | ||
. # . # . | ||
. C # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CAT 5 0 0 | ||
. . . . . | ||
. # # . . | ||
. . C # . | ||
. # # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CATCHER 5 -1 0 | ||
. . . . . | ||
. # # . . | ||
. C . # . | ||
. # # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CAT 5 0 0 | ||
. . . . . | ||
. # # . . | ||
. . C # . | ||
. # # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CATCHER 5 -1 0 | ||
. . . . . | ||
. # # . . | ||
. C . # . | ||
. # # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CAT 5 0 0 | ||
. . . . . | ||
. . # . . | ||
. # C # . | ||
. # # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CATCHER 5 -1 -1 | ||
. . . . . | ||
. C # . . | ||
. # . # . | ||
. # # . . | ||
. . . . . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
add_executable(ai-flocking flocking.cpp) | ||
|
||
file(GLOB TEST_INPUT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.in) | ||
file(GLOB TEST_OUTPUT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.out) | ||
|
||
add_custom_test(ai-flocking-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/flocking "${TEST_INPUT_FILES}" "${TEST_OUTPUT_FILES}") | ||
|