Application that simulates a large grid of Pokémon types fighting each other.

Last update: May 10, 2022

poke-fighting-rust

Rust project that simulates a grid of Pokémon fighting with each other.

Each Pokémon type is a pixel on the grid and is represented by a color.

Every frame an attack is done by a Pokémon that will pick a random neighbour, if that neighbour faints they will turn into a pokemon of the same type as the attacker.

Some Pokémon types do more or less damage to other types, which is what this is trying to simulate.

Twitter thread with more info and GIFs

Build

cargo run

Depends on nannou for the Window

Example Frame

Here the purple Pokémon (Ghost type) have a few large clusters and are slowly taking over the lower region. But a small brown section (Dark type) has started to invade one of them

preview

GitHub

https://github.com/olafurw/poke-fighting-rust
Comments
  • 1. Use the standard GitHub cache action

    Call me paranoid but I don’t like depending on third-party stuff for the build infrastructure. So I looked into whether there is a more canonical caching solution for Github actions. Turns out there is: https://github.com/actions/cache/blob/main/examples.md#rust---cargo. It works well for my repo.

    One has to commit the Cargo.lock file however. That’s probably recommendable either way.

    Reviewed by palant at 2022-05-08 20:44
  • 2. Less CPU-heavy pausing approach

    Currently, when paused the application continues to loop. As a result, CPU load is still high. Worse yet, for me it tends to hang up then (most likely a graphics deadlock again). Setting loop mode has none of these issues.

    Reviewed by palant at 2022-05-09 11:41
  • 3. Generalize Battle to work on abstract fighters, not pokemons

    This fixes #14, all mostly straightforward. The only complication is that Battle::fight needs two fighter references, one mutable, and the previous work-around no longer works with the types being opaque. The solution to split the vector into multiple independent slices might help with multithreading as well.

    Reviewed by palant at 2022-05-09 08:18
  • 4. Cleaned up imports

    See https://rust-lang.github.io/rust-clippy/master/#wildcard_imports for recommendations on imports. This rule isn’t enforced by default but running cargo clippy -- -W clippy::wildcard_imports will make the warnings show up. In general, importing stuff in main.rs that isn’t used there but is transitively imported elsewhere is very confusing. Also, use super::* in tests usually takes care of all import needs.

    Reviewed by palant at 2022-05-08 19:59
  • 5. Used a 2D grid

    This commit implements a 2D grid API using a single Vec.

    The API of this new Grid API uses Option. By manipulating and propagating Option, we can also get rid of code like Location::is_outside.

    Location in general has also been removed and replaced by a pair of usize.

    Reviewed by SfietKonstantin at 2022-05-17 13:10
  • 6. Reworked fighter generation

    Made use of std::iter::repeat_with to construct the table of fighters. Also migrated to the GenerateRandomly trait, that generates one fighter at a time (to be used with repeat_with)

    Reviewed by SfietKonstantin at 2022-05-10 19:40
  • 7. Moved all pokemon-related types into pokemon.rs

    Got rid of pointless POKEMON_COUNT and RPS_COUNT constants while at it. The point was not requiring any consumers to import strum::EnumCount, but that size is used only internally now.

    Reviewed by palant at 2022-05-09 13:37
  • 8. Made handling of in-fighting consistent, only allowed with -o command line flag

    With this change, the --fightown command line flag determines whether own kind is attacked or not. If it’s the latter, no attack happens at all (previously it would still attack if no other pokemon were around).

    The challenge here was implementing this without hurting performance too much. That’s why I have weakest_neighbour and weakest_neighbour_filtered as separate functions – any kind of decision making inside the function would degrade performance. And I choose the callback up front now so this choice doesn’t have to happen within the loop (I strongly suspect though that Rust already optimized that choice out of the loop before).

    Reviewed by palant at 2022-05-09 10:34
  • 9. Abstract Pokemon away from Battle.

    Make battle work with any kind of 'fighter'. To be generic towards what kind of 'fighter' is battling.

    Where Pokemon is just one kind of fighting. Could create another one as an example where you do Rock/Paper/Scissors. Perhaps even turn Pokemon into a library. @palant

    Reviewed by olafurw at 2022-05-08 20:43
  • 10. Optimize dev builds to make them usable

    Presumably, you are suggesting to run release builds because dev build performance is just too bad. With this change dev build is optimized and usable. It still has all the debug foo in it and should be better suited for development.

    Reviewed by palant at 2022-05-08 20:21
  • 11. Added command line option to measure frame rate

    I couldn’t find a way to make nannou or mesa measure the frame rate, so here is a simple manual solution. It calculates the frame rate after every 100 frames. I would have preferred constant time intervals but I also wanted this code to have as little own impact on the performance as possible.

    Reviewed by palant at 2022-05-08 17:20
  • 12. Ability to mouse over pixels to see info about each fighter.

    Only usable I think if you're able to pause the simulation (see #23)

    You'd have to tell each fighter to implement either Display or something similar. I wonder what's the best way to show this kind of info, a modal window that appears in the corner or something?

    Reviewed by olafurw at 2022-05-09 11:11
  • 13. Think of other Fighter/Battle types that can be implemented.

    Seems generic enough since you only need to decide what happens when a matchup occurs. Chess pieces? Something from other games? Simulations (does it work for game of life?)

    Reviewed by olafurw at 2022-05-09 09:13
Solutions of Advent of Code 2021 in Rust, and some other languages.

advent-of-rust Solutions of Advent of Code 2021 in Rust, and some other languages. Puzzles Puzzle Stars Languages Day 1: Sonar Sweep ⭐ ⭐ Rust Python D

Jan 29, 2022
Insert a new named workspace between two other named workspaces

Insert a new named workspace between two other named workspaces

Mar 13, 2022
TinyUF2 flash unlocker for STM32F411 (easily adaptable to other STM32F4xx)

TinyUF2 flash unlocker for STM32F411 (easily adaptable to other STM32F4xx) This small program is meant to unlock the first 2 (=32kb) flash sectors tha

Feb 1, 2022
Traits for inspecting memory usage of Rust types

memuse This crate contains traits for measuring the dynamic memory usage of Rust types. About Memory-tracking is a common activity in large applicatio

Nov 26, 2021
A list of known SS58 account types as an enum.

A list of known SS58 account types as an enum.

Apr 27, 2022
🪣 Types for a `Vec`'s raw parts

raw-parts A wrapper around the decomposed parts of a Vec<T>. This struct contains the Vec's internal pointer, length, and allocated capacity. RawParts

Apr 18, 2022
Annoyed that Rust has many string types? Well it doesn't have to

generic-str The one true string type in Rust! This project intends to be a proof-of-concept for an idea I had a few months back. There is lots of unsa

Apr 9, 2022
Use explicit container types with Scrypto! Leverage the Rust compiler's type checking to increase security and productivity when developing Radix blueprints.

Scrypto Static Types Use explicit container types with Scrypto! Leverage the Rust compiler's type checking to increase security and productivity when

Apr 23, 2022
An unsafe botched job that doesn't rely on types being 'static lifetime.

An unsafe botched job that doesn't rely on types being 'static lifetime. Will panic if provided a 0 field struct. I will fix this when I figure out how.

Feb 4, 2022
Rust types for the OASIS Common Alerting Protocol (CAP)

Rust types for the OASIS Common Alerting Protocol (CAP)

Feb 24, 2022
A rust program to try and detect some types of Hardware Keyloggers.
A rust program to try and detect some types of Hardware Keyloggers.

Hardware Keylogger Detection Warning: Certain Types of Hardware keyloggers can not be detected by this program, Passive Hardware Keyloggers are imposs

Apr 12, 2022
A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns.

Discord API Types A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns. Also did

Apr 28, 2022
Option and Either types with variants known at compile time.

Const Either Some types to allow deciding at compile time if an option contains a value or which variant from the either type is active. This might be

May 5, 2022
Federated blogging application, thanks to ActivityPub (now on https://git.joinplu.me/ — this is just a mirror)

Plume Website — Documentation — Contribute — Instances list Plume is a federated blogging engine, based on ActivityPub. It is written in Rust, with th

May 26, 2022
QueingSimulator is an application that can be used to build intuitions about behavior of synchronous request/reply systems

Queueing Simulator QueingSimulator is an application that can be used to build intuitions about behavior of synchronous request/reply systems (such as

Feb 12, 2022
Simple tray application which shows battery level for HyperX Cloud Flight Wireless Headset.
Simple tray application which shows battery level for HyperX Cloud Flight Wireless Headset.

HyperX Cloud Flight Battery Monitoring Introduction Simple tray application which shows battery level for HyperX Cloud Flight Wireless Headset. Screen

May 16, 2022
An application for reading comics together.

Shared comic reader Creates a web server that serves image sets to one or more clients. When one of those clients turns a page, all other clients who

Dec 17, 2021
A clean and simple network looking glass application
A clean and simple network looking glass application

lg lg is my custom Looking Glass server software for use in ZZANet. The whole application is lightweight, self-contained, and easy to use even outside

Nov 25, 2021
01 Solana program application interface.

01 abi The abi is a repository for interfacing with the 01 program either through a rust client or through CPIs from another Solana program. Program A

May 11, 2022