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

Overview

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

Comments
  • Use the standard GitHub cache action

    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.

    opened by palant 3
  • Less CPU-heavy pausing approach

    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.

    opened by palant 2
  • Generalize Battle to work on abstract fighters, not pokemons

    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.

    opened by palant 2
  • Display fighter info in a floating window on click

    Display fighter info in a floating window on click

    I used egui to display a floating window on mouse click. It displays the current position of the mouse pointer and the fighter type along with its color.

    Using Debug trait to stringify fighter types is somewhat awkward but should do for now.

    The only issue I noticed: when the app is paused, the figher info window will stop updating as well, even if the mouse is moved. I guess that pausing has to be done by skipping the battling after all. But we won’t get around redrawing even in the paused state.

    opened by palant 1
  • Ability to mouse over pixels to see info about each fighter.

    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?

    opened by olafurw 1
  • Cleaned up imports

    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.

    opened by palant 1
  • Fixed regression from #36: Wrong position calculation if width and height aren't identical

    Fixed regression from #36: Wrong position calculation if width and height aren't identical

    I noticed lines in the display if I specify an image size that’s not square. Turns out, this is a regression from #36: wrong calculation in Battle::action().

    While looking for the bug, I added a test making sure that Grid2D::get_pair_mut() operates on the same data as is returned by Grid2D::get() later. It’s probably a good idea to keep this one.

    opened by palant 0
  • Used a 2D grid

    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.

    opened by SfietKonstantin 0
  • Reworked fighter generation

    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)

    opened by SfietKonstantin 0
  • Moved all pokemon-related types into pokemon.rs

    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.

    opened by palant 0
  • Made handling of in-fighting consistent, only allowed with -o command line flag

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

    opened by palant 0
  • Think of other Fighter/Battle types that can be implemented.

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

    opened by olafurw 2
Owner
Ólafur Waage
Ólafur Waage
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

rene-d 6 Jan 7, 2023
Insert a new named workspace between two other named workspaces

Insert a new named workspace between two other named workspaces

null 2 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

Stefan Kerkmann 1 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

null 13 Dec 23, 2022
A list of known SS58 account types as an enum.

A list of known SS58 account types as an enum.

Parity Technologies 39 Dec 14, 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

Artichoke Ruby 3 Sep 1, 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

Conrad Ludgate 40 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

null 7 Aug 5, 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.

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

Rust types for the OASIS Common Alerting Protocol (CAP)

Will Glynn 2 Jun 6, 2022
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

null 4 Dec 5, 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

Unofficial Discord Documentation 1 Sep 16, 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

null 1 May 5, 2022
The most primitive and the fastest implementation of a fixed-size last-in-first-out stack on stack in Rust, for Copy-implementing types

This is the simplest and the fastest (faster than Vec!) implementation of a last-in-first-out stack data structure, on stack, when stack elements are

Yegor Bugayenko 10 Jun 18, 2023
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

Plume 1.9k Jan 8, 2023
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

Joe Magerramov 7 Sep 11, 2022
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

Stefan Kondinski 18 Dec 27, 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

null 0 Dec 17, 2021
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

Evan Pratten 2 Dec 16, 2022