Skip to content

Instantly share code, notes, and snippets.

@Prof9
Last active September 15, 2016 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prof9/6f02214ada3db3108b0f874df0778df3 to your computer and use it in GitHub Desktop.
Save Prof9/6f02214ada3db3108b0f874df0778df3 to your computer and use it in GitHub Desktop.
Star Force encounter chance calculator
using System;
using System.Collections.Generic;
namespace EncounterChanceCalc {
class Program {
static void Main(string[] args) {
// SF1
//decimal rate = 0.10M;
// SF2 and SF3
decimal rate = 0.05M;
decimal pLeft = 1.0M;
List<decimal> firstSuccessChances = new List<decimal>();
firstSuccessChances.Add(0);
decimal p = rate;
bool last = false;
for (int i = 0; true; i++) {
if (rate >= 1.0M) {
last = true;
}
p = pLeft * rate;
firstSuccessChances.Add(p);
pLeft *= (1.0M - rate);
rate += 0.01M;
if (last) {
break;
}
}
decimal sum = 0;
List<decimal> sums = new List<decimal>();
foreach (decimal chance in firstSuccessChances) {
sum += chance;
sums.Add(sum);
}
// sum should be 1 at this point
// calc expected number of trials until first success
// i.e. expected number of encounter checks until virus battle
decimal expected = 0;
for (int i = 0; i < firstSuccessChances.Count; i++) {
expected += i * firstSuccessChances[i];
}
// calculate expected number of movement frames for a number of situations
// make sure to set proper rate above
decimal sf1nocloak = 192 + (expected - 1) * 64;
decimal sf1cloaked = 192 + (expected - 1) * 128;
decimal sf2nocloak = 250 + (expected - 1) * 10;
decimal sf3nocloak = 400 + (expected - 1) * 15;
decimal sf3cloaked1 = 400 + (expected - 1) * 45;
decimal sf3cloaked2 = 600 + (expected - 1) * 45;
// calculate expected number of movement frames for using one Cloaker and letting it expire
decimal sf1singlecloak = 0;
decimal cloakerFrames = 768 + 191;
decimal next = 0;
decimal e = expected;
for (int i = 0; e > 0; i++, e--) {
if (i == 0) {
next = 192;
} else {
if (cloakerFrames > 0 && cloakerFrames <= 768) {
next = 128;
} else {
next = 64;
}
}
sf1singlecloak += Math.Min(e, 1) * next;
cloakerFrames -= next;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment