Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added A* agent #19

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/cse_491_fall_2023.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "macos-clang-x86",
"configurationProvider": "ms-vscode.cpptools"
}
],
"version": 4
}
64 changes: 64 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"C_Cpp.errorSquiggles": "enabled",
"files.associations": {
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__verbose_abort": "cpp",
"array": "cpp",
"atomic": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"locale": "cpp",
"map": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"queue": "cpp",
"ratio": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"variant": "cpp",
"vector": "cpp",
"algorithm": "cpp"
}
}
Empty file added docs/test.txt
Empty file.
5 changes: 5 additions & 0 deletions project_specs/team-1-specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ modules.
ii. Params and returns will be added after discussion with other groups to
see if this is wanted


#### Challenge
1. Creating an Autonomous agent that is capable of moving around an interacting
with the world
2. Working with other agent teams to implement functionality they need for their agents
51 changes: 51 additions & 0 deletions source/Agents/AgentLibary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Created by Matthew Kight on 9/24/23.
//
#pragma once

#include "../core/AgentBase.hpp"
#include "../core/WorldBase.hpp"
#include <vector>
#include <map>
#include <queue>
#include <tuple>
namespace cse491
{
namespace walle
{

/**
* @brief Node class to make A* search easier
*
*/
struct Node
{
cse491::GridPosition position; // Where node is located
int g; // Cost from start to current node
int h; // Heuristic (estimated cost from current node to goal)
std::shared_ptr<Node> parent;

Node(cse491::GridPosition position, double g, double h, std::shared_ptr<Node> parent)
: position(position), g(g), h(h), parent(parent) {}

// Calculate the total cost (f) of the node
int f() const
{
return g + h;
}
};

/**
* @brief Custom comparison function for priority queue
*
*/
struct CompareNodes
{
bool operator()(const std::shared_ptr<walle::Node> a, const std::shared_ptr<walle::Node> b) const
{
return a->f() > b->f();
}
};

}
}
32 changes: 32 additions & 0 deletions source/Agents/AgentMonika.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This file is part of the Fall 2023, CSE 491 course project - Group 1 fork - monika_k branch.
* @brief An Agent that will walk.
* @note Status: PROPOSAL
**/

#pragma once

#include "../core/AgentBase.hpp"

namespace cse491 {
class BasicAgent : public AgentBase {
protected:
std::unordered_map<std::string, double> a_star_map; // Map of the tiles on the board with their corresponding values for a* search
bool isMoving = false; // Is the agent moving?
int intelligenceLevel = 0; // Depending on the type of agent, mobility varies
// Measure of intelligence; if agent is an enemy, are they "smart enough" to be able to use a*, or would they resort to
// another search method? If the agent is the user/player's agent they would have maximum intelligence.
int healthPoints = 10;
int mobility = 20; // Number of tiles the agent can move in a given turn?
int level = 1; // Level of character; scales the rest of their attributes.

public:
BasicAgent(size_t id, const std::string & name) : AgentBase(id, name) { }
~BasicAgent() = default;

// a_star function here

// could also add getters/setters here for different attributes

};
}
83 changes: 83 additions & 0 deletions source/Agents/matt_k_first_agent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @file matt_k_first_agent.h
* @author Matt Kight
*/
#pragma once

#include <vector>
#include "../core/AgentBase.hpp"
#include "AgentLibary.h"
#include <iostream>
namespace cse491
{
namespace walle
{
/**
* Class that describes a matt_k_first_agent class
*/
class matt_k_first_agent : public cse491::AgentBase
{
private:
std::vector<GridPosition> path; // Path this agent is taking
cse491::GridPosition goal_position; // Where the agent wants to end up
int recalculate_after_x_turns = 100; // How often agent recalculates moves
int current_move_num = 0; // What move # we are currently on
WorldBase *world = nullptr;

public:
matt_k_first_agent(size_t id, const std::string &name) : AgentBase(id, name)
{
}
~matt_k_first_agent() = default;

/**
* @brief Set the word object
*
* @param world world this agent is a part of
*/
void set_word(WorldBase *world) { this->world = world; }

/// @brief This agent needs a specific set of actions to function.
/// @return Success.
bool Initialize() override
{
return HasAction("up") && HasAction("down") && HasAction("left") && HasAction("right");
}

void set_goal_position(const GridPosition gp)
{
goal_position = gp;
}
/// Choose the action to take a step in the appropriate direction.
size_t SelectAction(const WorldGrid & /*grid*/,
const type_options_t & /* type_options*/,
const item_set_t & /* item_set*/,
const agent_set_t & /* agent_set*/) override
{
// TODO REMOVE THIS
// We are taking an action so another turn has passed
++(this->current_move_num);
// If the last step failed, or we need a new path the then regenerate the path
if (action_result == 0 || this->path.empty() || this->current_move_num > this->recalculate_after_x_turns)
{
this->path = this->world->shortest_path(GetPosition(), this->goal_position);
}
// Return whatever action gets us closer to our goal
if (!this->path.empty())
{
auto pos = path.back();
path.pop_back();
if (pos.GetX() == position.GetX() && pos.GetY() == position.GetY() - 1)
return action_map["up"];
if (pos.GetX() == position.GetX() && pos.GetY() == position.GetY() + 1)
return action_map["down"];
if (pos.GetX() == position.GetX() - 1 && pos.GetY() == position.GetY())
return action_map["left"];
if (pos.GetX() == position.GetX() + 1 && pos.GetY() == position.GetY())
return action_map["right"];
}
return 0; // If no path then do not do anything
}
};
};
}
3 changes: 2 additions & 1 deletion source/Worlds/MazeWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ namespace cse491 {

// Set the agent to its new postion.
agent.SetPosition(new_position);

return true;
}

/// Can walk on all tiles except for walls
bool is_walkable (cse491::GridPosition pos) override {return main_grid.At(pos) != wall_id;}
};

} // End of namespace cse491
Loading