A TypeScript, Express, and Node.js project that allows developers to configure and run Codyfighters via the Codyfight API.
- Features
- Requirements
- Project Structure
- Setup & Configuration
- Scripts
- Development
- Production
- Extending the Database Layer
- Extending Strategies
- Contributing
- License
- Configuration UI: A user interface to add or remove bots from the database.
- Bot Runner: Runs configured bots that connect to the Codyfight API and perform actions in the game.
- Bot Strategies: Easily extend the move and cast strategies to customize bot behavior.
- Multiple Database Support: Uses SQLite by default; can switch to Postgres or any other DB by implementing an interface.
- TypeScript:
>= 5.0.0
- Express:
^4.18.2
- Node.js:
>= 23.3.0
- NPM:
10.9.1
or later
.
├── src/
│ ├── bots/
│ ├── client/
│ ├── game/
│ ├── server/
│ ├── utils/
│ └── ...
├── package.json
├── tsconfig.json
├── yarn.lock
└── ...
src/bots
: Contains core bot logic, including strategies and bot runner.src/server
: Houses the Express server and database setup (SQLite or Postgres).src/client
: Front-end/public assets for the configuration page.src/game
: Game-specific logic and data structures (e.g., map, state, pathfinding).src/utils
: Shared utility functions.
Create a .env
file at the root of your project and add the necessary variables. Use the template .env
file for reference.
# Environment
NODE_ENV=development
# SQLite (default)
DB_PATH=./src/server/db/bots.db
DB_DIALECT=sqlite
-
Create the Database:
Run the following scripts to initialize and seed an SQLite database:# Create tables node --loader ts-node/esm src/server/db/scripts/sqllite/create-db.ts # Seed database with some dummy records node --loader ts-node/esm src/server/db/scripts/sqllite/seed-db.ts
-
Confirm
.env
:
Make sure.env
contains:DB_DIALECT=sqlite DB_PATH=./src/server/db/bots.db
- Set Up Postgres:
Create a Postgres database (e.g.,codyfight_bots
) and a user (e.g.,admin
). - Configure
.env
:DB_DIALECT=postgres DATABASE_URL=postgresql://admin@localhost:1234/codyfight_bots
Below are the relevant commands:
npm run dev:config
: Starts the configuration server in dev mode.npm run dev:run-bots
: Starts the bot runner in dev mode.npm run start:config
: Runs the configuration server from the compileddist
folder.npm run start:run-bots
: Runs the bot runner from the compileddist
folder.npm run build
: Builds the project for production, including server and client assets.
-
Install Dependencies
npm install
-
Database
- For SQLite: Initialize the database (see Database Setup).
- For Postgres: Configure
.env
and set up the database with necessary scripts.
-
Start in Development Mode
- Configuration Page:
npm run dev:config
- Bot Runner:
npm run dev:run-bots
- Configuration Page:
-
Build the Project
npm build
-
Start the Compiled Server
- Configuration Page:
npm run start:config
- Bot Runner:
npm run start:run-bots
- Configuration Page:
To add support for a new database type (e.g., MongoDB):
- See
src/server/db/repository/custom-c-bot-repository.ts
for an example implementation of a custom database repository.
You can extend or override the bot’s move and cast strategies by implementing custom logic:
- Cast Strategy: See
src/bots/strategies/cast/custom-cast-strategy.ts
for an example. - Move Strategy: See
src/bots/strategies/move/custom-move-strategy.ts
for an example.
- Fork this repository and clone your fork.
- Create a new branch for your feature or fix.
- Commit and push your changes.
- Open a Pull Request against the main repository. Please include clear descriptions and, if necessary, add or update tests.
This project is open-sourced under the MIT License. Contributions are welcome!