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

Lugo 151 update readme #23

Merged
merged 3 commits into from
Mar 16, 2024
Merged
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
82 changes: 59 additions & 23 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# Lugo4Node - A Lugo Bots Client

Lugo4Node is a NodeJS implementation of a client player for [Lugo](https://lugobots.dev/) game.
Lugo4Node is a NodeJS implementation of a client player for [Lugo](https://lugobots.dev/) game.

It **is not a bot** that plays the game, it is only the client for the game lugo.
It **is not a bot** that plays the game, it is only the client to connect to the game server.

This client implements a brainless player in the game. So, this library implements many methods that does not affect the
player intelligence/behaviour/decisions. It is meant to reduce the developer concerns on communication, protocols,
attributes, etc.
This package implements many methods that does not affect the player intelligence/behaviour/decisions. It is meant to reduce the developer concerns on communication, protocols, attributes, etc.

Using this client, you just need to implement the Artificial Intelligence of your player and some other few methods to
support your strategy (see the project [exampe](./example/simple) folder).
Using this client, you just need to implement the Artificial Intelligence of your player and some other few methods to support your strategy (see the [example](./example/simple) folder and [The Dummies JS](https://github.com/lugobots/the-dummies-js)).


# Table of Contents
* [Requirements](#requirements)
* [Installation](#installation)
* [Usage](#usage)
* [First option: Implementing a Bot class (simpler and recommended)](#first-option-implementing-a-bot-class-simpler-and-recommended)
* [Second option: Implementing the turn handler (a little more work)](#second-option-implementing-the-turn-handler-a-little-more-work)
* [Third option: Using reinforcement learning :brain:](#third-option-using-reinforcement-learning-brain)
- [Helpers](#helpers)
* [Snapshot reader](#snapshot-reader)
* [Snapshot inspector](#snapshot-inspector)
* [Mapper and Region classes](#mapper-and-region-classes)
+ [The Mapper](#the-mapper)
+ [The Region](#the-region)
Expand All @@ -29,21 +27,59 @@ support your strategy (see the project [exampe](./example/simple) folder).

* NPM >= 16

### Installation

npm install @lugobots/lugo4node

### Usage

There are three ways to use **Lugo4Node** client:


### First option: Implementing a Bot class (simpler and recommended)

See [example](./example/simple/my_bot.js)

**Lugo4Node** client implements the method `playAsBot(bot)` that expects an instance [bot](./src/client.ts#L79) implementation.
**Lugo4Node** *PlayAsBot* implements a very basic logic to reduce the code boilerplate. This client will wrap most repetitive
code that handles the raw data got by the bot and will identify the player state.

The `Bot` interface requires the methods to handle each player state based on the ball possession.

All you need to do is creating your bot by extending that class and implementing your bot behaviour. See an example
at [example/simple/my_bot.ts](example/simple/my_bot.js)

```javascript
class Bot {
// OnDisputing is called when no one has the ball possession
onDisputing(inspector: GameSnapshotInspector): Order[] | { orders: Order[], debug_message: string } | null {
// the magic code comes here
return ...
}

// OnDefending is called when an opponent player has the ball possession
onDefending(inspector: GameSnapshotInspector): Order[] | { orders: Order[], debug_message: string } | null {
// the magic code comes here
return ...
}

// OnHolding is called when this bot has the ball possession
onHolding(inspector: GameSnapshotInspector): Order[] | { orders: Order[], debug_message: string } | null {
// the magic code comes here
return ...
}

// OnSupporting is called when a teammate player has the ball possession
onSupporting(inspector: GameSnapshotInspector): Order[] | { orders: Order[], debug_message: string } | null {
// the magic code comes here
return ...
}

// AsGoalkeeper is only called when this bot is the goalkeeper (number 1). This method is called on every turn,
// and the player state is passed at the last parameter.
asGoalkeeper(inspector: GameSnapshotInspector, state: PLAYER_STATE): Order[] | { orders: Order[], debug_message: string } | null {
// the magic code comes here
return ...
}
}

```

### Second option: Implementing the turn handler (a little more work)

Expand Down Expand Up @@ -75,11 +111,11 @@ move/kick/catch order, finding your teammates positions, etc.

**Lugo4Node** brings some libraries to help you with that:

### Snapshot reader
### Snapshot inspector

_Auto generated doc coming soon_

The Snapshot reader is quite useful. Firs to it helps you to extract data from
The Snapshot inspector is quite useful. Firs to it helps you to extract data from
the [Game Snapshot](https://github.com/lugobots/protos/blob/master/doc/docs.md#lugo.GameSnapshot) each game turn.

```javascript
Expand Down Expand Up @@ -121,17 +157,17 @@ inspector.makeOrderKickMaxSpeed(target: Lugo.Point): Lugo.Order
inspector.makeOrderCatch(): Lugo.Order
```

<!-- And, last but not least, the Reader also helps our bot to see the game map based on directions instead of coordinates:
<!-- And, last but not least, the inspector also helps our bot to see the game map based on directions instead of coordinates:

```javascript
reader.goForward()
reader.goForwardLeft()
reader.goForwardRight()
reader.goBackward()
reader.goBackwardLeft()
reader.goBackwardRight()
reader.goLeft()
reader.goRight()
inspector.goForward()
inspector.goForwardLeft()
inspector.goForwardRight()
inspector.goBackward()
inspector.goBackwardLeft()
inspector.goBackwardRight()
inspector.goLeft()
inspector.goRight()
``` -->

### Mapper and Region classes
Expand Down