Giter Site home page Giter Site logo

chengluyu / turnip-price Goto Github PK

View Code? Open in Web Editor NEW
33.0 3.0 2.0 960 KB

《动物森友会》大头菜价格算法 Rust & WebAssembly 版 / The Rust & WebAssembly implementation of the algorithm of the turnip price in Animal Crossing: New Horizon.

Rust 62.54% HTML 25.72% JavaScript 11.74%
animal-crossing animal-crossing-new-horizons turnip turnip-price

turnip-price's Introduction

Turnip Price

中文版

A Rust (and WebAssembly) implementation of the calculator turnip price of Animal Crossing: New Horizon. This project can't be done without @_Ninji's C++ code and his disassembly work. You can try the demo online.

🚀 Getting Started

You can install this package via npm or Yarn.

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.

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.

🕸️🦀️ 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

turnip-price's People

Contributors

chengluyu avatar dependabot-preview[bot] avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sclin

turnip-price's Issues

Error: Cannot find module 'turnip-price'

Hello! First of all, really great work here; I'm excited to make use of your npm module!

I'm having trouble getting it up and running though. I've installed the package using npm install --save tunip-price, and the installation seems to be fine, but when I try to require the package with const tp = require('turnip-price');, I get the following error Error: Cannot find module 'turnip-price', but the turnip-price folder is in my node_modules folder, just as it should be.

I'm using several other packages in my project, and using "require" is working fine for all of them, so I know it isn't an issue with the file locations.

Am I importing the package correctly in my script, or is there a step that I'm missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.