Skip to content
Open
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
3 changes: 0 additions & 3 deletions .github/workflows/maze-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ jobs:
- name: Build project (debug)
run: make

- name: Run maze solver
run: ./build/mazealgo

- name: Build project (release / -O2)
run: |
make clean
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
build/
testmazes/
89 changes: 72 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,80 @@
SRCS = astar.c floodfill.c main.c
OBJS = $(patsubst %.c,build/%.o,$(SRCS))
DEPS = $(OBJS:.o=.d)
TARGET = build/mazealgo
CC ?= gcc
CC ?= gcc

CFLAGS = -Wall -Wextra -Werror -std=c11 -Og -g -pedantic
# Build configuration
BUILD_TYPE ?= debug # options: debug, release
SANITIZE ?= 1 # 1 to enable sanitizers, 0 to disable
SIM ?= 1 # 1 to define SIM, 0 to omit

# Base compiler flags (common to all builds)
CFLAGS = -Wall -Wextra -Werror -std=c11 -pedantic
CFLAGS += -Wconversion -Wshadow -Wformat=2 -fstack-protector-strong

# Configuration-specific flags
ifeq ($(BUILD_TYPE),debug)
# make BUILD_TYPE=debug
CFLAGS += -Og -g
else ifeq ($(BUILD_TYPE),release)
CFLAGS += -O2
endif

ifeq ($(SANITIZE), 1)
CFLAGS += -fsanitize=address,undefined
endif

ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG
endif

ifeq ($(SIM), 1)
CFLAGS += -DSIM
endif
LDFLAGS =

BUILD = build
TARGET_ALGO = $(BUILD)/mazealgo
TARGET_READER = $(BUILD)/socket_reader

ALGO_SRCS = api.c floodfill.c main.c queue.c
READER_SRCS = socket_reader.c

ALGO_OBJS = $(patsubst %.c, $(BUILD)/%.o, $(ALGO_SRCS))
READER_OBJS = $(patsubst %.c, $(BUILD)/%.o, $(READER_SRCS))
ALL_OBJS = $(ALGO_OBJS) $(READER_OBJS)
DEPS = $(ALL_OBJS:.o=.d)

# ── Targets ────────────────────────────────────────────────────────────────────

.PHONY: all clean run help

all: $(TARGET_ALGO) $(TARGET_READER)

$(TARGET_ALGO): $(ALGO_OBJS) | $(BUILD)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

$(TARGET_READER): $(READER_OBJS) | $(BUILD)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

$(BUILD)/%.o: %.c | $(BUILD)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@

$(BUILD):
mkdir -p $(BUILD)

# ── Dependency includes ────────────────────────────────────────────────────────

-include $(DEPS)

build/mazealgo: $(OBJS)
$(CC) -o $@ $^ $(CFLAGS)
build/%.o: %.c
mkdir -p build
$(CC) -MMD -MP -c $< -o $@ $(CFLAGS)
.PHONY: clean help
# ── Utility ───────────────────────────────────────────────────────────────────

run: all
$(TARGET_READER) & $(TARGET_ALGO)
Comment thread
AFE123xr marked this conversation as resolved.

clean:
rm -rf build
$(RM) -r $(BUILD)

help:
@echo "This project is built using 'make' (see Makefile)."
@echo "If the README still refers to CMake-based builds, those instructions are legacy."
@echo "To build the binary used by CI, run: make"
@echo "To clean build artifacts, run: make clean"
@echo "Targets:"
@echo " all - Build mazealgo and socket_reader (default)"
@echo " run - Build then run both binaries"
@echo " clean - Remove build artifacts"
@echo " help - Show this message"
77 changes: 58 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,74 @@
# Maze Algorithm Repository
# Micromouse Maze Algorithm Repository

This repository will contain the maze algorithm. Right now, it uses a left wall following algorithm.
This repository provides the template and core interface for developing Micromouse maze-solving algorithms. It includes an adapter for the Micromouse Simulator (MMS) and a skeleton for implementing search algorithms.

## how to build
## File Structure

This uses a build tool known as cmake. This will make compilation much easier. There's a `CMakeLists.txt` file which describes what the final executable should look like.
| File | Description |
| :--- | :--- |
| `floodfill.c` | **Primary Logic:** Implement your floodfill or search algorithm here. |
| `api.c` | The low-level interface used to communicate with the simulator. |
| `socket_reader.c` | An adapter that connects the MMS to your algorithm, enabling step-by-step debugging. |
| `queue.c` | A standard queue data structure implementation for use in BFS/Floodfill. |

```sh
mkdir build # if you didn't create a folder named build yet
cd build # go into build folder
cmake .. # generate make file and other components
make # compile your code. You can add j<num-threads> to speed up compilation
## Build Instructions

Use the `make` command with the following optional flags to compile the project:

```bash
make SIM=1 DEBUG=1 SANITIZE=1
```

### Build Flags

* **`SIM=1`**: Compiles the code specifically for use with the Micromouse Simulator.
* **`DEBUG=1`**: Enables symbols and configurations for step-by-step debugging.
* **`SANITIZE=1`**: Enables AddressSanitizer to detect memory leaks and buffer overflows.

To remove compiled binaries and object files, run:

- This is expected to be used in conjunction with the micromouse maze simulator
```bash
make clean
```

-----

## Execution & Simulation

## Documentation
### 1\. Configure the Simulator

- https://github.com/mackorone/mms-cpp: the micromouse cpp api
- https://github.com/mackorone/mms: The micromouse maze simulation program
Before running your code, open the **Micromouse Simulator (MMS)** and point the configuration to your build directory.

## branching conventions
![](./images/image.png)

You'll create a new branch for each problem you're trying to fix. We'll be doing the following convention
### 2\. Run the Algorithm

```sh
user/<username>/problem
Once the simulator is configured and the "Run" button is pressed, execute the binary from your terminal:

user/afe123x/left-corner-crash #An example branch name, clearly describing what we're working on.
```bash
./build/mazealgo
```

When you're done with your work, and ensure it compiles, you can make a pull request.
-----

## Development Workflow

### Branching Convention

To maintain a clean repository, please use the following naming convention for all new features or bug fixes:

`user/<username>/<brief-description>`

**Example:**
`user/afe123x/left-corner-crash`

### Pull Requests

1. Ensure your code compiles without errors or warnings.
2. Verify that `SANITIZE=1` does not report memory issues.
3. Push your branch and open a Pull Request for review.

## Resources

* [MMS Simulation Program](https://github.com/mackorone/mms): The core simulator application.
* [MMS C++ API](https://github.com/mackorone/mms-cpp): Documentation for the simulator's API and protocol.
Loading
Loading