Hal9000

Hal9000

As you may know, I am slowly/painfully writing an Elixir book.

There is a code example that I’ve written in Ruby – a simple
robot-type “capture the flag” game. (Not a real game, just a
coding exercise.)

I’m about to port the Ruby code to Elixir. If anyone wants to
look/comment/help, please feel free. (Those who contribute
will be mentioned in the acknowledgements fwiw.)

This repo will be public for at least two days:

https://github.com/Hal9000/vexil

Thanks,
Hal

Showing Posts 11 to 20

Eiji

Eiji

Hey, I added new PR.
I rewrite Elixir code to much some guidelines.
Now we have Agent that stores our game data, each bot have AI Erlang process (TODO: turn).
Your project is now really configurable. For example you can setup 2 to 4 teams with their colours and names dynamically.
I added some two dependencies bunt to easy format grid and credo to keep code readability.
Review my code and say if you don’t understand something. The code is not 10 lines, so bigger explanation may be really long. Let me know what you think about my version. If you accept it I will implement simple AI.
I wrote that I add this PR in current week, so it’s not complete yet (AI and credo checks).
Run code several times to see different results.

Tip: I created new modules inside Vexil module, because it’s not a “Hello World” tutorial and you are going to show good code example. In your old code you have for example: Grid module which may conflict in other projects if they organise code like you.

I need also write some tests.

OvermindDL1

OvermindDL1

Yeah, things like defmodule Grid do should be like defmodule Vexil.Grid do or so. Namespaces should always be used! :slight_smile:

Hal9000

Hal9000 OP

There are several things I don’t understand yet about this.
Let’s talk more via email?

Namespacing is a good idea, yes.

Hal

Eiji

Eiji

No need private messages. It’s thread for your project. Feel free to ask :smile:

Hal9000

Hal9000 OP

First, what is your reasoning for getting rid of modules such as Bot?

Eiji

Eiji

These modules are for defining structs by defstruct.
Here you have details about structs.
I think it’s best way to store data like that. Of course I can forgot about other things. Feel free to add propositions to my version of code.

Hal9000

Hal9000 OP

I still don’t understand why you did away with the modules.
Where would you store functions that manipulate those structs?

Eiji

Eiji

The main module (to manage grid) is Vexil.Battleground. It stores grid in Vexil.Agent and have functions to manipulate this grid. For example to store Bot or Flag structure. I wrote some function and split this module to some imports, so:
Vexil.Battleground imports: Vexil.Battleground.TeamUtils. TeamUtils (like a normal team) imports Vexil.Battleground.BotUtils and Vexil.Battleground.FlagUtils and both of them imports Vexil.Battleground.GridUtils.
Note: in your Ruby code Flag extends Bot, so it can move(!). I think it’s not a good to read your Ruby code, because Flag will not move at all.
In my code FlagUtils imports only functions for calculate position based on corner and spawn item. Ok, but why it’s all for Battleground? It’s simple. Bot and Flag do not need to calculate position from corner. I think my version is easiest to understand (if you know how import works).
More, flag do not think and bot do not see full grid, so they should not calculate coords. I know it’s not a bug, but it’s not easy to read - am I wrong?

Hal9000

Hal9000 OP

This seems reasonable. I will look at it further tonight. Thank you.

Eiji

Eiji

Next example:
In next version AI needs to calculate where to move. To do this AI give question to Battleground: “Can I move 3 times left and 1 time bottom?”. If true it responds: “Move bot from x,y 3 times left and 1 time bottom.” and Battleground should calculate new position (x and y). Fetch item from grid, remove it (replace with nil) and “move” (replace nil with item - struct - in new coords).

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews