Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chengluyu/turnip-price
《动物森友会》大头菜价格算法 Rust & WebAssembly 版 / The Rust & WebAssembly implementation of the algorithm of the turnip price in Animal Crossing: New Horizon.
https://github.com/chengluyu/turnip-price
animal-crossing animal-crossing-new-horizons turnip turnip-price
Last synced: 2 months ago
JSON representation
《动物森友会》大头菜价格算法 Rust & WebAssembly 版 / The Rust & WebAssembly implementation of the algorithm of the turnip price in Animal Crossing: New Horizon.
- Host: GitHub
- URL: https://github.com/chengluyu/turnip-price
- Owner: chengluyu
- Created: 2020-04-04T09:11:48.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:47:02.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T15:09:51.154Z (9 months ago)
- Topics: animal-crossing, animal-crossing-new-horizons, turnip, turnip-price
- Language: Rust
- Homepage:
- Size: 938 KB
- Stars: 32
- Watchers: 3
- Forks: 2
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Turnip Price
[中文版](docs/README_zh-CN.md)
A Rust (and WebAssembly) implementation of the calculator turnip price of Animal Crossing: New Horizon. This project can't be done without [@_Ninji](https://twitter.com/_Ninji)'s [C++ code](https://gist.github.com/Treeki/85be14d297c80c8b3c0a76375743325b) and his disassembly work. You can try the [demo](https://turnip-price.now.sh) online.
## 🚀 Getting Started
You can install this package via npm or Yarn.
```bash
npm i turnip-price
# or
yarn add turnip-price
```Also, make sure that the target environment has access to WebAssembly. Then you can write a calculation function like this.
```js
import * as wasm from "turnip-price";
import { memory } from 'turnip-price/turnip_price_bg';function calculate(whatPattern, seed) {
const turnip = wasm.calculate(whatPattern, seed);
return {
buyingPrice: trunip.buying_price,
sellingPrices: new Int32Array(memory.buffer, turnip.selling_prices(), 12),
};
}
```Explanation of the `sellingPrices` array:
* The 0th, 2nd, 4th, 6th, 8th, 10th elements indicate the morning price from Tuesday to Saturday respectively;
* The 1st, 3rd, 5th, 7th, 9th, 11th elements indicate the afternoon price from Tuesday to Saturday respectively.## 🤔 FAQ
### 📈 Can I Predict the Price on My Island by This?
No, yet. *Because you don't have the random seed, which is not exposed to regular players.* By the way, if you have the seed, *the calculator won't work the first time you buy the turnips*, according to [@_Ninji's reply](https://twitter.com/_Ninji/status/1245097287136706561?s=20).
### 🕸️🦀️ Why do you use WebAssembly?
Because the code involves the practice of reinterpreting unsigned 32-bit integer as 32-bit IEEE 754 floating number.
Though I can do that in JavaScript, using WebAssembly maybe more stable.## 🔍 Discovery
### 📚 Can I Enumerate All Combinations?
There are total `4 × 2 ^ 32 = 17,179,869,184` combinations.
On my machine, it tooks 4 minutes to enumerate all combinations (in 4 threads).However, it's cost to save all combinations to your disk.
For each combination, the algorithm will product 13 prices.
Each price is a positive integer from 0 to around 660, which can be represented by an unsigned 10-bit integer.
Therefore, the uncompressed data size is 2,233,382,993,920 bits, i.e. 260 GBs.### 💰 How Much Is The Highest Price?
I tried all combinations of patterns (0, 1, 2, 3) and seeds (from 0 to `UINT32_MAX`). Here is the results.
* In pattern 0 (i.e. `what_pattern` is set to 0), the highest price is 660 when seed = 326.
* In pattern 1 (i.e. `what_pattern` is set to 1), the highest price is 660 when seed = 326.
* In pattern 2 (i.e. `what_pattern` is set to 2), the highest price is 660 when seed = 326.
* In pattern 3 (i.e. `what_pattern` is set to 3), the highest price is 660 when seed = 9772.In conclusion, **the highest price of turnips is 660**.
### 📈 Weekly Highest Price Distribution
You may want to acknowledge the distribtion. I also did this.
![The Histogram of Weekly Highest Price of Turnips](docs/weekly-highest-distribution.svg)