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
Trending in Discussions
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Code BEAM Europe 2026 – Call for Talks is Open!
We’re excited to announce that Code BEAM Europe 2026 is now open for talk submissions :t...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 11 to 20- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Eiji
Hey, I added new PR.
I rewrite Elixir code to much some guidelines.
Now we have
Agentthat 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
Vexilmodule, 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:Gridmodule which may conflict in other projects if they organise code like you.I need also write some tests.
OvermindDL1
Yeah, things like
defmodule Grid doshould be likedefmodule Vexil.Grid door so. Namespaces should always be used!Hal9000
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
No need private messages. It’s thread for your project. Feel free to ask
Hal9000
First, what is your reasoning for getting rid of modules such as Bot?
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
I still don’t understand why you did away with the modules.
Where would you store functions that manipulate those structs?
Eiji
The main module (to manage grid) is
Vexil.Battleground. It stores grid inVexil.Agentand have functions to manipulate this grid. For example to storeBotorFlagstructure. I wrote some function and split this module to some imports, so:Vexil.Battlegroundimports:Vexil.Battleground.TeamUtils. TeamUtils (like a normal team) importsVexil.Battleground.BotUtilsandVexil.Battleground.FlagUtilsand both of them importsVexil.Battleground.GridUtils.Note: in your Ruby code
FlagextendsBot, so it can move(!). I think it’s not a good to read your Ruby code, becauseFlagwill not move at all.In my code
FlagUtilsimports only functions for calculate position based on corner and spawn item. Ok, but why it’s all forBattleground? It’s simple.BotandFlagdo 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
This seems reasonable. I will look at it further tonight. Thank you.
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.” andBattlegroundshould 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).