Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/economy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

// Base price and price multiplier for CPU
const CPU_BASE_PRICE: f64 = 1.0;
const CPU_PRICE_MULTIPLIER: f64 = 1.5;
const CPU_PRICE_MULTIPLIER: f64 = 1.020;

// Base price and price multiplier for RAM
const RAM_BASE_PRICE: f64 = 1.0;
const RAM_PRICE_MULTIPLIER: f64 = 1.75;
const RAM_PRICE_MULTIPLIER: f64 = 1.030;

// Base price and price multiplier for Disk
const DISK_BASE_PRICE: f64 = 1.0;
const DISK_PRICE_MULTIPLIER: f64 = 1.625;
const DISK_PRICE_MULTIPLIER: f64 = 1.025;

// Perks price
pub const CI_CD_PRICE: f64 = 10.0;
pub const AUTO_SCALING_PRICE: f64 = 50.0;
pub const CI_CD_PRICE: f64 = 5.0;
pub const AUTO_SCALING_PRICE: f64 = 25.0;

// Helper to round values to the nearest 0.05
fn round_value(value: f64) -> f64 {
Expand Down
26 changes: 13 additions & 13 deletions src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@
use crate::statefile::GameState;

// Base and minimum compile time (in seconds)
const BASE_COMPILE_TIME: f64 = 600.0;
const MIN_COMPILE_TIME: f64 = 10.0;
const BASE_COMPILE_TIME: f64 = 300.0;
const MIN_COMPILE_TIME: f64 = 5.0;

// Base and minimum credit reward for a successful compilation
const BASE_CREDIT_REWARD: f64 = 1.0;
const MIN_CREDIT_REWARD: f64 = 1.0;
const MIN_CREDIT_REWARD: f64 = 0.5;

// Base and minimum / maximum probability of compilation failure
const BASE_COMPILATION_FAILURE_PROB: f64 = 0.20;
const MIN_COMPILATION_FAILURE_PROB: f64 = 0.10;
const BASE_COMPILATION_FAILURE_PROB: f64 = 0.30;
const MIN_COMPILATION_FAILURE_PROB: f64 = 0.05;
const MAX_COMPILATION_FAILURE_PROB: f64 = 0.90;

// Calculate compile time based on CPU and RAM
// - Each additional CPU core reduces the compile time by 5 seconds
// - Each additional GB of RAM increases the compile time by 2.5 seconds
// - Each additional GB of RAM increases the compile time by 1 second
// - Minimum possible compile time is capped at `MIN_COMPILE_TIME`
pub fn compile_time(cpu: u64, ram: u64) -> f64 {
let time = BASE_COMPILE_TIME - 5.0 * (cpu.saturating_sub(1) as f64)
+ 2.5 * (ram.saturating_sub(1) as f64);
+ 1.0 * (ram.saturating_sub(1) as f64);

time.max(MIN_COMPILE_TIME)
}

// Calculate the credit reward after a successful compilation based on RAM and Disk
// - Each additional GB of RAM increases the number of credits earned by 0.5
// - Each additional GB of Disk reduces the number of credits earned by 0.25
// - Each additional GB of Disk reduces the number of credits earned by 0.1
// - Minimum possible credit reward is capped at `MIN_CREDIT_REWARD`
pub fn credit_reward(ram: u64, disk: u64) -> f64 {
let reward = BASE_CREDIT_REWARD + 0.5 * (ram.saturating_sub(1) as f64)
- 0.25 * (disk.saturating_sub(1) as f64);
- 0.1 * (disk.saturating_sub(1) as f64);

reward.max(MIN_CREDIT_REWARD)
}

// Calculate compilation failure probability based on CPU and Disk
// - Each additional CPU core increases the probability of compilation failure by 0.025
// - Each additional GB of Disk reduces the probability of compilation failure by 0.05
// - Each additional GB of Disk reduces the probability of compilation failure by 1.5%
// - Each additional CPU core increases the probability of compilation failure by 1%
// - Minimum probability is capped at `MIN_COMPILATION_FAILURE_PROB`
// - Maximum probability is capped at `MAX_COMPILATION_FAILURE_PROB`
pub fn failure_probability(cpu: u64, disk: u64) -> f64 {
let probability = BASE_COMPILATION_FAILURE_PROB + 0.025 * (cpu.saturating_sub(1) as f64)
- 0.05 * (disk.saturating_sub(1) as f64);
let probability = BASE_COMPILATION_FAILURE_PROB - 0.015 * (disk.saturating_sub(1) as f64)
+ 0.010 * (cpu.saturating_sub(1) as f64);

probability.clamp(MIN_COMPILATION_FAILURE_PROB, MAX_COMPILATION_FAILURE_PROB)
}
Expand Down