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 27 to 18

Eiji

Eiji

It’s not a problem for me, but If it’s possible wrote about when you will have a time for this project, so I do not need wait and I can better manage my time.

My English is not good, but I will try answer your questions:

escript - read this tutorial
rest is generated by mix new vexil command

It’s predefined color name. See bunt dependency github project.

No, when I wrote this code I had Grid struct (so I found another name for this module), but after some changes this struct was not needed. But now I think it’s much more cleaner, because Battleground generate grid and have methods for read and write to it. Of course I can send PR with changed module name if you wwant.

AI as a separated Erlang process will decide what to do.
It will ask Battleground module if it can do something and depends on results it will call Battleground to apply AI decision (for example because AI - here bot - see only cells in specific range, think about Battleground as game engine).

Note: color should be unique for all teams.
Database naming convention for example in simple blog we have:

  1. Post with title, body and id
  2. Comment with user_name, body and post_id.

So Team has color (like id) and Bot has team_color (like team_id).

I use Agent to store game data. In previous (not pushed) version I don’t have Agent and I was need to pass more arguments. For example see where I read map_last_index. In previous version I need to pass it in lots of functions. I think it’s much more easier to read when we read game data from Agent.

What do you exactly mean?
I added code to make it configurable, so you can easily setup game rules, for example Bot types and their count.
I think it’s much more easier to modify this code without completely rewrite “game engine”.
Do you know M.U.G.E.N? It was really configurable. Anybody could add new characters, backgrounds, music and lots more. Lots of fans from lots of communities used this to create own games with for example: characters from other game.
I think project like it (but much more simpler - your vexil) should be configurable too. You can add some exercises to implement new features without need to write new game.
Also I read your code in Ruby and my configuration and it’s implementation is based on setup method in Referee class.This method have statically selected data and I split it to configuration (config.exs) and implementation (Battleground and it’s utils). See how I place bots based on their number.
Do you agree with me?

start_edge from config.exs is based on your setup method.

# I translated it like:
# Defender count is: 3
# if the rest of the division bot count (from configuration) by 2 is 1
# place bot exactly at `start_edge` corner
place(team, Defender, 5, 5)
place(team, Defender, 5, rand(1..4)) # `start_edge` for `defender` is 5
place(team, Defender, rand(1..4), 5) # same here

corner is from Team struct and it’s randomly selected - see &Vexil.Battleground.TeamUtils.random_corner/1 method.

Note: in configuration I use “human” numbers (people count from 1) and translate it to List index (computers count from 0). So when start_edge is 5 I place bots on 4th index random cell (half on X edge and half on Y edge).

Do you have any more questions?

Hal9000

Hal9000 OP

Sorry, very busy week here.

So far:

  1. In mix.exs - why escript, build_embedded, start_permanent ?

  2. In config.exs - why “coral” etc.?

  3. Any reason Battleground shouldn’t be just Grid?

  4. Uncertain how ai will work.

  5. Are you distinguishing between color and team_color? Why?

  6. Does Agent really buy us much here?

  7. I don’t understand what you’ve done in battleground.ex – is the complexity really needed?

  8. I don’t understand all the “edge/corner” stuff in bot_utils and elsewhere.

Hal9000

Hal9000 OP

I don’t understand it all yet. I will look at it tonight after I leave work
and will ask questions.

Eiji

Eiji

Heh, finally my PR is accepted. :smile:
Before I begin work on AI I want to be sure:
Do you understand all from my code?
Whether the code is clear and intuitive for you?
I’m not sure how much implement AI could take for me, but I think I finish it by the end of next week.

Eiji

Eiji

I added PR with merge commit and now there are no conflicts with your master branch.
Any questions for my code? Something is hard to interpreting?

Eiji

Eiji

You can delete file that have conflict. In my commit this file is deleted.
Try:

git rm vexil/lib/referee.ex

and push changes in your shell and then try submit PR.

Hal9000

Hal9000 OP

I had trouble merging somehow. Couldn’t figure out how to resolve conflict manually.

Not sure what state this is in now.

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).

Hal9000

Hal9000 OP

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

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?

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 92995 915
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
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
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews