Skip to content

Commit

Permalink
Changed all "normal" gameplay plays to account for dynamic role alloc…
Browse files Browse the repository at this point in the history
…ation, simplified RLinterface and accounted for static behaviour when no RL input is given
  • Loading branch information
flimdejong committed Feb 10, 2025
1 parent ff175ce commit 4c1f2bb
Show file tree
Hide file tree
Showing 18 changed files with 559 additions and 397 deletions.
8 changes: 8 additions & 0 deletions docker/runner/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ services:
- GRADLE_USER_HOME=/home/roboteamtwente/.cache # Cache gradle dependencies
volumes:
- ../../roboteam_autoref/:/home/roboteamtwente/
deploy:
resources:
limits:
memory: 500mb
profiles: ["simulator","diff","game","autoref", "RL"]

erforce_autoref_sim:
Expand All @@ -177,6 +181,10 @@ services:
- 10010:10010 # Tracker port
volumes:
- ../../:/home/roboteamtwente/
deploy:
resources:
limits:
memory: 500mb
profiles: ["simulator","diff", "RL"]

erforce_autoref_game:
Expand Down
2 changes: 1 addition & 1 deletion docker/runner/ray-cluster-combined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ spec:
- name: roboteam-secondary-ai
image: roboteamtwente/roboteam:kubernetes
command: ["/bin/sh"]
args: ["-c", "/home/roboteam/build/release/bin/roboteam_ai --secondary-ai"]
args: ["-c", "/home/roboteam_old/build/release/bin/roboteam_ai --secondary-ai"]
workingDir: /home/roboteam
env:
- name: LD_LIBRARY_PATH
Expand Down
48 changes: 2 additions & 46 deletions roboteam_ai/include/roboteam_ai/rl/RLInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@
#include <array>
#include <string>
#include <thread>
#include "utilities/Constants.h"

namespace rtt::ai::stp::rl {

/**
* @brief Interface class for Reinforcement Learning communication
* @details Handles ZMQ socket communication and manages game state information.
* This class is used to receive RL decisions from the RL model and update the role allocation.
* The role allocation for defenders and walls is determined based on the number of attackers.
*/

class RLInterface {
private:
// Thread members
Expand All @@ -23,24 +15,12 @@ class RLInterface {

// Game state members
int numAttackers;
int numDefenders;
int numWallers;
std::array<bool, 9> gridPositions; // Array of 9 positions, boolean

const int MANDATORY_ROLES = 3; // keeper, passer, receiver
const int MAX_ROBOTS = static_cast<int>(rtt::ai::constants::MAX_ROBOT_COUNT);

// ZMQ members
zmqpp::context_t context;
zmqpp::socket_t socket;

/**
* @brief Processes received string messages and updates the game state
* @param input_string Format: "N P1 P2 ... P_N" where:
* - N is the number of attackers
* - P1 through PN are positions (1-9) where attackers are located
*/
void process_string(const std::string& input_string);
bool isActive;

/**
* @brief Processes string containing only number of attackers
Expand All @@ -52,45 +32,21 @@ class RLInterface {
*/
void start();

/**
* @brief Allocates roles based on current game state
* @param requestedAttackers Number of attackers requested
*/
void allocateRoles(int requestedAttackers);

public:
RLInterface();
~RLInterface();

// Getters
int getNumAttackers() const;
int getNumDefenders() const;
int getNumWallers() const;
std::array<bool, 9> getBinaryOccupancyGrid() const;
bool getIsActive() const { return isActive; }

// Setters
void setNumAttackers(int attackers);
void clearNumAttackers();
void setNumWallers(int wallers);
void clearNumWallers();
void setNumDefenders(int defenders);
void clearNumDefenders();
void setBinaryOccupancyGrid(std::array<bool, 9> grid);

/**
* @brief Receives and processes full RL decision including grid positions
*/
void receiveRLDecision();

/**
* @brief Receives and processes attacker count only
*/
void receiveAttackersOnly();

/**
* @brief Prints the binary occupancy grid (debug only)
*/
void printBinaryOccupancyGrid() const;
};

} // namespace rtt::ai::stp::rl
12 changes: 12 additions & 0 deletions roboteam_ai/include/roboteam_ai/stp/plays/defensive/Defend.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ class Defend : public Play {
*/
const char* getName() const override;

/**
* Updates role configuration based on current game state
*/
void updateRoleConfiguration();

InterceptionInfo harasserInfo;

private:
static const int MANDATORY_ROLES = 2; // keeper, harasser

mutable int numDefenders = 4;
mutable int numWallers = 4;
mutable int numAttackers = 1;
};
} // namespace rtt::ai::stp::play

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,24 @@ class KeeperKickBall : public Play {
*/
bool shouldEndPlay() noexcept override;

/**
* Updates role configuration based on current game state
*/
void updateRoleConfiguration();

private:
/**
* @brief Check if the ball has been kicked. True if the kick tactic has ended, false if it is still going.
* @return Boolean that tells whether the ball has been kicked
*/
bool ballKicked();

PassInfo passInfo; /**< Struct containing info about the pass. Calculated once for each time this play is run */
PassInfo passInfo; /**< Struct containing info about the pass. Calculated once for each time this play is run */\

static const int MANDATORY_ROLES = 2;

mutable int numDefenders = 4;
mutable int numAttackers = 5;
};
} // namespace rtt::ai::stp::play

Expand Down
8 changes: 8 additions & 0 deletions roboteam_ai/include/roboteam_ai/stp/plays/offensive/Attack.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class Attack : public Play {
* @return The name of the play as string
*/
const char* getName() const override;

void updateRoleConfiguration();

private:
static const int MANDATORY_ROLES = 2;
mutable int numDefenders = 5;
mutable int numWallers = 2;
mutable int numAttackers = 2;
};

} // namespace rtt::ai::stp::play
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ class AttackingPass : public Play {
void updateRoleConfiguration();

private:
/**
* @brief Check if the ball has been kicked. True if passer is done with kicking, False if it is still ongoing
* @return Boolean that tells whether the ball has been kicked
*/
bool ballKicked();
/**
* @brief Check if the ball has been kicked. True if passer is done with kicking, False if it is still ongoing
* @return Boolean that tells whether the ball has been kicked
*/
bool ballKicked();

static const int MANDATORY_ROLES = 3; // keeper, passer, receiver

mutable int numDefenders = 4;
mutable int numWallers = 2;
mutable int numAttackers = 2;
mutable int numDefenders = 4;
mutable int numWallers = 2;
mutable int numAttackers = 2;

PassInfo passInfo; /**< Struct containing info about the pass. Calculated once for each time this play is run */
PassInfo passInfo; /**< Struct containing info about the pass. Calculated once for each time this play is run */
};
} // namespace rtt::ai::stp::play

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class BallPlacementThem : public Play {
* @return The name of the play as string
*/
const char* getName() const override;

void updateRoleConfiguration();

static const int MANDATORY_ROLES = 2;

mutable int numDefenders = 4;
mutable int numWallers = 4;
mutable int numAttackers = 1;
};
} // namespace rtt::ai::stp::play

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class BallPlacementUsForceStart : public Play {
* @return The name of the play as a string
*/
const char* getName() const override;

void updateRoleConfiguration();

static const int MANDATORY_ROLES = 2;

mutable int numDefenders = 6;
mutable int numWallers = 2;
mutable int numAttackers = 1;
};
} // namespace rtt::ai::stp::play

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ class BallPlacementUsFreeKick : public Play {
* @return The name of the play as a string
*/
const char* getName() const override;

void updateRoleConfiguration();

static const int MANDATORY_ROLES = 2;

mutable int numDefenders = 3;
mutable int numWallers = 2;
mutable int numAttackers = 4;
};
} // namespace rtt::ai::stp::play

Expand Down
Loading

0 comments on commit 4c1f2bb

Please sign in to comment.