https://github.com/eric7237cire/rgb_delivery
A Solver for RGB Express. Uses Rust, WebAssembly, WebWorkers, TypeScript, and Angular
https://github.com/eric7237cire/rgb_delivery
angular7 rust typescript typings webassembly webpack
Last synced: 2 months ago
JSON representation
A Solver for RGB Express. Uses Rust, WebAssembly, WebWorkers, TypeScript, and Angular
- Host: GitHub
- URL: https://github.com/eric7237cire/rgb_delivery
- Owner: eric7237cire
- Created: 2019-04-12T18:10:10.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-14T00:35:52.000Z (over 3 years ago)
- Last Synced: 2025-04-22T10:46:16.024Z (about 1 year ago)
- Topics: angular7, rust, typescript, typings, webassembly, webpack
- Language: Rust
- Homepage:
- Size: 5.04 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 38
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
[](https://travis-ci.org/eric7237cire/poker)
#  π¦ πΈοΈ A grid solver for [RGB Express](http://rgbexpress.com/) 
[RGB Express](http://rgbexpress.com/) is an excellent strategy Android game. It helps to download & play before looking at the solver.
Basically you have to get each van (V) pick up a block (B) and return it to the target warehouse (T). The van and warehouse must be the same color.
Each van can hold 3 blocks, the 'poppers', if active, will pop the top block off the Van. Poppers are activated before starting the level.
Component/tech flow:
WASM => Web Worker <=> Angular 7
Thus Angular has no knowledge of the WebAssembly, using only WebWorker messages, but it does use the typings generated. Thus if a new attribute/etc. is
added to the public classes/interfaces (exposed by Serde), the typescript transpilation will show errors.
## The Algorithm
Just a brute force search with some pruning done with connected components calculated
with the Union Find / Disjoint Set datastructure.
## Components
### grid-editor
Angular 7 front end, grid editor & runs the search.

Language: TypeScript
### web_worker
Code based on a [public repo](https://github.com/rustwasm/rust-wasm-worker-template).
Packages the WASM using a stand alone webpack as a Web worker. Too much of a PITA to get angular cli
to play nicely.
Build as a local only npm module, exposing a browser asset and the typings.
Language: TypeScript
To setup, see the [Travis Configuration](.travis.yml)
### rgb-solver
WASM Source. Unit tests run in x86 (or linux on travis)
Language: Rust
To setup, see the [The Watch Bat File](/devops/build-wasm.bat)
### wasm-typescript-definition
Code based on a [public repo](https://github.com/tcr/wasm-typescript-definition) of same name.
Modified to produce better *.d.ts types for typescript. Most useful is generating union types which match nicely with Rusts variant enums.
TypeScript has nice support for [discriminated unions](https://basarat.gitbooks.io/typescript/docs/types/discriminated-unions.html) which let you do a checked switch on the attribute type.
Built automatically when rgb-solver is built.
Example:
Typing generated:
```typescript
export type Road = {
...
};
export type Bridge = {
...
};
//derive struct
export type Warehouse = {
...
};
export type TileEnum = TileRoad | TileWarehouse | TileBridge | Empty
export type TileEnum = TileRoad | TileWarehouse | TileBridge | Empty
export type TileRoad = {type: "TileRoad"} & Road
export type TileWarehouse = {type: "TileWarehouse"} & Warehouse
export type TileBridge = {type: "TileBridge"} & Bridge
export type Empty = {type: "Empty" }
export type TileEnum_type = "TileRoad" | "TileWarehouse" | "TileBridge" | "Empty"
```
Rust:
```rust
#[derive(Clone, Serialize, Deserialize, Debug, TypescriptDefinition, Hash, Eq, PartialEq)]
#[serde(tag = "type")]
pub enum TileEnum {
TileRoad(Road),
TileWarehouse (Warehouse),
TileBridge(Bridge),
Empty
}
```
# Deploying to [git hub pages](https://eric7237cire.github.io/rgb_delivery/)
Done by travis, see the [Travis Configuration](.travis.yml)