Skip to content

Commit

Permalink
Merge pull request #96 from permaweb/chore/update-bot-tutorial-v2
Browse files Browse the repository at this point in the history
chore: update bots tut
  • Loading branch information
ropats16 authored Feb 27, 2024
2 parents 9d0b2f7 + ae5dff2 commit 1a16d48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/tutorials/bots-and-games/announcements.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Handlers.add(
)
```

In this case, the name of the handler is `"PrintAnnouncements"`. It uses a special utility (`hasMatchingTags`) to check if the incoming message has been tagged as an announcement. If true, the handler prints the Event and Data, which represent the title and description of the announcement.
In this case, the name of the handler is `"PrintAnnouncements"`. It uses a special in-built utility (`hasMatchingTags`) to check if the incoming message has been tagged as an announcement. If true, the handler prints the Event and Data, which represent the title and description of the announcement.

> Note: Once a message is "handled", it will be discarded from your `Inbox`.
Expand Down
14 changes: 9 additions & 5 deletions src/tutorials/bots-and-games/arena-mechanics.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ For those who prefer to watch the action unfold, the "Listen" mode offers an opp

To maintain the flow and fairness of arena games, an automated system oversees game state transitions. These transitions encompass waiting, playing, and ending phases. Time durations for each state, such as `WaitTime` and `GameTime`, ensure that rounds adhere to defined timeframes, preventing games from lasting indefinitely.

## Arena Game Blueprint

For those interested in using this arena framework, here is the blueprint for the arena game in Lua:
You can refer to the code for the arena in the dropdown below:

<details>
<summary><strong>Arena Game Blueprint</strong></summary>

```lua
-- ARENA GAME BLUEPRINT.

-- REQUIREMENTS: cron must be added and activated for game operation.

-- This blueprint provides the framework to operate an 'arena' style game
-- inside an ao process. Games are played in rounds, where players aim to
-- eliminate one another until only one remains, or until the game time
Expand Down Expand Up @@ -409,6 +405,14 @@ Handlers.add(

</details>

## Arena Game Blueprint

For those interested in using this arena framework, we've made this code easily accesible through a blueprint. Simply run the following code in your terminal:

```lua
.load-blueprint arena
```

## Summary

Understanding the mechanics of the arena can not only help you improve your autonomous agent created in the previous section but also empowers you to harness core functionalities for crafting your unique games.
Expand Down
4 changes: 2 additions & 2 deletions src/tutorials/bots-and-games/build-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ AverageMaxStrengthHitsToKill = 3 -- Average number of hits to eliminate a player
-- @return Table representing player's initial state
function playerInitState()
return {
x = math.random(0, Width/8),
y = math.random(0, Height/8),
x = math.random(0, Width),
y = math.random(0, Height),
health = 100,
energy = 0
}
Expand Down
4 changes: 2 additions & 2 deletions src/tutorials/bots-and-games/game-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Let's define a new variable that stores the latest state as follows:
LatestGameState = LatestGameState or nil
```

The syntax preserves exisitng values of the variable when you load successive iterations of the `bot.lua` file instead of overwriting it. If there is no pre-existing value then a `nil` value is assigned to the variable.
The syntax preserves exisitng values of the variable when you load successive iterations of the `bot.lua` file in your terminal, instead of overwriting it. If there is no pre-existing value then a `nil` value is assigned to the variable.

Then implement another handler as follows:

Expand All @@ -73,7 +73,7 @@ Handlers.add(
)
```

The response from the game process from the previous handler has an action tag with the value `GameState` that helps us trigger this second handler. Once triggered, the handle function loads the `json` package that parses the data into json and stores it in the `LatestGameState` variable.
The response from the game process from the previous handler has an action tag with the value `GameState` that helps us trigger this second handler. Once triggered, the handle function loads the in-built `json` package that parses the data into json and stores it in the `LatestGameState` variable.

This handler additionally sends a message to your process indicating when the state has been updated. The significance of this feature will be explained in the following section.

Expand Down

0 comments on commit 1a16d48

Please sign in to comment.