Skip to content

Commit

Permalink
partially functioning tar tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmeehan13 committed Sep 28, 2023
1 parent 1a8c61a commit 6575e7a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
Binary file added .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/source/simple_main.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
24 changes: 23 additions & 1 deletion source/Worlds/MazeGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
*/

#include "mazegeneration.h"
#include "Mazegeneration.h"
#include <fstream>
#include <random>
#include <stack>
Expand Down Expand Up @@ -55,6 +55,7 @@ void MazeGeneration::generate() {
}

placeSpikeTiles(0.05);
placeTarTiles(.05);
}

bool MazeGeneration::isValid(int x, int y) {
Expand Down Expand Up @@ -91,4 +92,25 @@ void MazeGeneration::placeSpikeTiles(double percentage) {
for (int i = 0; i < numSpikes; ++i) {
grid[floorPositions[i].second][floorPositions[i].first] = 'X';
}
}

void MazeGeneration::placeTarTiles(double percentage) {
std::vector<std::pair<int, int>> floorPositions;
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
if (grid[i][j] == ' ') {
floorPositions.push_back({j, i});
}
}
}

int numTars = floorPositions.size() * percentage;
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(floorPositions.begin(), floorPositions.end(), g);

// Convert some floor tiles to tar tiles
for (int i = 0; i < numTars; ++i) {
grid[floorPositions[i].second][floorPositions[i].first] = 'O';
}
}
1 change: 1 addition & 0 deletions source/Worlds/MazeGeneration.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MazeGeneration {
void saveToFile(const std::string &filename);

void placeSpikeTiles(double percentage);
void placeTarTiles(double percentage);

private:
int width;
Expand Down
6 changes: 5 additions & 1 deletion source/Worlds/MazeWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ namespace cse491 {

class MazeWorld : public WorldBase {
protected:
enum ActionType { REMAIN_STILL=0, MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT };
enum ActionType { REMAIN_STILL=0, MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT, REMOVE_TAR };

size_t floor_id; ///< Easy access to floor CellType ID.
size_t wall_id; ///< Easy access to wall CellType ID.

size_t spike_id; ///< Easy access to spike CellType ID.
size_t tar_id; ///< Easy access to tar CellTypeID


/// Provide the agent with movement actions.
Expand All @@ -28,6 +29,7 @@ namespace cse491 {
agent.AddAction("down", MOVE_DOWN);
agent.AddAction("left", MOVE_LEFT);
agent.AddAction("right", MOVE_RIGHT);
agent.AddAction("tar", REMOVE_TAR);
}

public:
Expand All @@ -36,6 +38,7 @@ namespace cse491 {
wall_id = AddCellType("wall", "Impenetrable wall that you must find a way around.", '#');

spike_id = AddCellType("spike", "Dangerous spike that resets the game.", 'X');
tar_id = AddCellType("tar", "Slow tile that makes you take two steps to get through it", 'O');

main_grid.Read("../assets/grids/default_maze.grid", type_options);
}
Expand All @@ -51,6 +54,7 @@ namespace cse491 {
case MOVE_DOWN: new_position = agent.GetPosition().Below(); break;
case MOVE_LEFT: new_position = agent.GetPosition().ToLeft(); break;
case MOVE_RIGHT: new_position = agent.GetPosition().ToRight(); break;
case REMOVE_TAR: new_position = agent.GetPosition(); break;
}

// Don't let the agent move off the world or into a wall.
Expand Down
Binary file added source/simple
Binary file not shown.

0 comments on commit 6575e7a

Please sign in to comment.