Code Monkey home page Code Monkey logo

oppaisharp's Introduction

NuGet

OppaiSharp

OppaiSharp is a C# port of oppai-ng by Francesco149, based on its Java port Koohii. It allows you to calculate star ratings and PP values for any osu!standard map, just like oppai(-ng) does.

It is "licensed" under the Unlicense, so you're free to do whatever you want with it. But giving me or Francesco149 a bit of credit doesn't hurt, and I would appreciate it if you didn't claim it as your own :)

Warning

This repo is not up-to-date with the latest changes to the PP and SR algorithm, and has been superseded by the official implementation at ppy/osu. Please switch to using it.

Example usage

v2:

//create a StreamReader for your beatmap
byte[] data = new WebClient().DownloadData("https://osu.ppy.sh/osu/774965");
var stream = new MemoryStream(data, false);
var reader = new StreamReader(stream);

//read a beatmap
var beatmap = Beatmap.Read(reader);

//calculate star ratings for HDDT
Mods mods = Mods.Hidden | Mods.DoubleTime;
var diff = new DiffCalc().Calc(beatmap, mods);
Console.WriteLine(string.Format("Star rating: {0:F2} (aim stars: {1:F2}, speed stars: {2:F2})", 
    diff.Total, diff.Aim, diff.Speed));

//calculate the PP for a play on this map
//the play has no misses or 50's, so we don't specify them
var pp = new PPv2(new PPv2Parameters(beatmap, diff, c100: 8, mods: mods));

Console.WriteLine(string.Format("Play is worth {0:F2}pp ({1:F2} aim pp, {2:F2} acc pp, {3:F2} speed pp) " +
                                "and has an accuracy of {4:F2}%", 
    pp.Total, pp.Aim, pp.Acc, pp.Speed, pp.ComputedAccuracy.Value() * 100));

v1 (old):

//create a StreamReader for your beatmap
byte[] data = new WebClient().DownloadData("https://osu.ppy.sh/osu/774965");
var stream = new MemoryStream(data, false);
var reader = new StreamReader(stream);

//parse the beatmap
var beatmap = new Parser().Map(reader);

//calculate star ratings for HDDT
Mods mods = Mods.Hidden | Mods.DoubleTime;
var stars = new DiffCalc().Calc(beatmap, mods);
Console.WriteLine(string.Format("Star rating: {0:F2} (aim stars: {1:F2}, speed stars: {2:F2})", 
    stars.Total, stars.Aim, stars.Speed));

//calculate the PP value for a play
var pp = new PPv2(new PPv2Parameters {
    Beatmap = beatmap,
    AimStars = stars.Aim,
    SpeedStars = stars.Speed,
    Mods = mods,
    Count100 = 8,
    Count50 = 0,
    CountMiss = 0,
});
Console.WriteLine(string.Format("Play is worth {0:F2}pp ({1:F2} aim pp, {2:F2} acc pp, {3:F2} speed pp) " +
                                "and has an accuracy of {4:F2}%", 
    pp.Total, pp.Aim, pp.Acc, pp.Speed, pp.ComputedAccuracy.Value() * 100));

oppaisharp's People

Contributors

holly-hacker avatar piotrekol avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

oppaisharp's Issues

Exceptions on map parsing and/or PP calc

2 ranked:
https://osu.ppy.sh/b/1391940
https://github.com/HoLLy-HaCKeR/OppaiSharp/blob/master/OppaiSharp/Parser.cs#L182
sublime_text_2018-02-13_21-36-49

https://osu.ppy.sh/b/407140
sublime_text_2018-02-13_21-40-04

I also have several modified/unmodified submited/unsubmited maps that simply fail to parse, while osu has no problems with them. 141(of with 99 is one huge mappack) of them to be specific. Should I also include these?

code used for testing:

public void run(){
    var maps = Directory.GetFiles(@"D:\Random\OppaiFailedMaps\");
    DiffCalc diffCalculator = new DiffCalc();

    foreach (var filelocation in maps)
    {
        var fileinfo = new FileInfo(filelocation);
        if (fileinfo.Length == 0) continue;
        Console.WriteLine(filelocation);
        using (var stream = new FileStream(filelocation, FileMode.Open))
        {
            using (var reader = new StreamReader(stream))
            {
                var beatmap = Beatmap.Read(reader);
                var beatmapCalc = diffCalculator.Calc(beatmap, Mods.NoMod);
                new PPv2(beatmapCalc.Aim, beatmapCalc.Speed, beatmap);
                if (beatmap.Objects.Count > 0) //crashes when beatmap has no objects
                {
                    GetPp(beatmap, 99.9d);
                    GetPp(beatmap, 99d);
                    GetPp(beatmap, 98d);
                    GetPp(beatmap, 95d);
                    GetPp(beatmap, 90d);
                }
            }
        }
    }
}
public double GetPp(Beatmap beatmap, double acc)
{
    Accuracy _accCalculator = new Accuracy(acc, beatmap.Objects.Count, 0);
    PPv2 _ppCalculator = new PPv2(new PPv2Parameters(beatmap, _accCalculator.Count100, _accCalculator.Count50, _accCalculator.CountMiss, -1, _accCalculator.Count300));
    return Math.Round(_ppCalculator.Total, 2);
}

Exception on PPv2 calc

This fails when count300 is negative with Either countObjects or Count300 must be specified. Example would be inputting an unfinished (failed) score.
oppai-ng is handling this properly.

Can't calculate pp when c100 >= beatmap circles

when doing the example program on README.md, but instead of passing c100: 8 we pass c100: beatmap.CountCircles the resulting pp will be of a 100% acc play

Alternatively, if a value higher than beatmap.CountCircles is passed Either countObjects or Count300 must be specified will be thrown

Tested with https://osu.ppy.sh/b/706711

Exception on float.Parse

If your system culture settings don't match osu's beatmap format (for example separator is ',' instead of '.') float parsing will fail with Input string was not in a correct format.

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.