Giter VIP home page Giter VIP logo

ianfhunter / gnoll Goto Github PK

View Code? Open in Web Editor NEW
39.0 4.0 23.0 2.71 MB

GNOLL is an efficient dice notation parser for multiple programming languages that supports a wide set of dice notation

Home Page: https://www.ianhunter.ie/GNOLL/

License: GNU General Public License v3.0

Makefile 6.15% Python 28.07% C 25.58% Lex 4.52% Yacc 28.46% SWIG 0.50% Perl 0.18% Go 0.36% Julia 0.53% R 0.33% Java 0.55% C++ 0.28% Haskell 0.63% Ruby 0.25% C# 0.49% PHP 0.17% Rust 1.09% Lua 0.46% JavaScript 0.81% HTML 0.59%
dice dice-roller dice-notation board-game c cpp dice-rolls python roleplaying-games ttrpg

gnoll's Introduction

GNOLL

Downloads

Test: Functionality Test: Language Bindings Test: OS Support

CodeFactor Codacy Badge

status TTRPG compatibility rate GitHub license GitHub last commit Donate

An easy to integrate dice notation library for multiple programming languages. Use for instant support of common syntax and a library that can scale with your demands, rather than a sticky taped monstrousity of regular expressions and tears.

Here's an example of how you might use GNOLL:

**Grindon The Brave**: I want to steal from the goblin sitting at the bar.
**Dungeon Master**: Okay, give me a stealth check!
**Grindon The Brave**: Okay, that's a <1d20+5>
[GNOLL]: 21
**Dungeon Master**: Hurrah! You successfully pickpocket the goblin! However, all he had in there were some crummy dice...

You can follow Grindon's full adventure through the world of dice notation in our Documentation.

Many of our notation design decisions are explained in the documentation and compared to other dice notation parsers.

Play around

Try out our web demo! โœจ

Current Status

๐Ÿง‘โ€๐Ÿ’ป Language Support

GNOLL was written to be the definitive solution to dice notation. The core has been written in C, but fear not! You can use GNOLL in many other programming languages too. Here are some we have examples for:

C C++ C# Go Haskell Java JavaScript Julia Lua Perl PHP Python R Ruby Rust

Primarily tested on Linux (Ubuntu), but functional in various forms on Windows (10, WSL) and Mac.

๐ŸŽฒ Dice Notation

  • XdY notation
  • Arithmetic
  • Fate Dice
  • Miscellaneous Symbolic Dice
  • Shorthands & Macros
  • Alternate Syntax
  • Explosions
  • Drop/Keep
  • Rerolling
  • Filtering
  • Functions

There's so many different things, we'd bore you to list them all here. For the specific details of supported notation, check out our documentation.

Getting Started

Usage from a package manager

Python

pip3 install GNOLL

Then, in your code:

from gnoll import roll
roll("1d20")
>> (0, [[12]], None)
# (return code, final result, dice breakdown (if enabled))

Or, use the command-line interface (see --help):

$ python3 -m gnoll 2d4
6
$ function gnoll() { python3 -m gnoll --breakdown "$@" ; }
$ gnoll 3d6 + 10
[5, 5, 4] --> 24

๐Ÿ› ๏ธ Installing From Source

Basic Requirements

sudo apt-get install bison flex make python3-pip -y
pip install -r reqs/requirements.txt
make all

To verify your setup, try our tests:

make test

Or, just try some commands yourself!

$ ./build/dice 1d20
20

If you would like to run the 'dice' command from anywhere, use make install to add the executable to your path.

(Note that not all commands may not be able to be used this way as some symbols are reserved for use by different terminal interfaces (e.g. bash uses ! and #))

For languages other than Python/C/C++ call the corresponding make target after the commands above.

๐Ÿ› Issues / Bugs / FAQs / Feature Requests

If you encounter any issues or have any ideas, please file them in our Issue Tracker.

โœ‹ Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

๐Ÿ”ข Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

๐Ÿคน Authors / Contributers / Attributions

See also the list of contributors who participated in this project.

๐Ÿ“ƒ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE.md file for details.

Individual licensing arrangements can be made if this is an issue for your project - Contact Me at LinkedIn to discuss.

๐Ÿ‘ Acknowledgments

๐Ÿ—๏ธ Built With

  • Flex & Bison - Grammar Lexing & Parsing
  • uthash - C hashtable lib
  • PCG - Random Number Generation
  • Arc4Random - Random Number Generation (Cryptographically secure)
  • Love! ๐Ÿ’–

๐Ÿ’ฐ Donate

Keep this project alive

gnoll's People

Contributors

aswarthm avatar codewadi avatar danielskatz avatar deepsource-autofix[bot] avatar deepsourcebot avatar falcon2k1 avatar ianfhunter avatar infiniteverma avatar itsagift avatar kailashchoudhary11 avatar kineolyan avatar kodiologist avatar michaeljmcd avatar oliviacarino avatar pyr0x1 avatar smattr avatar snyk-bot avatar tanmay-bajaj 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  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gnoll's Issues

Minimize dependencies

Our dependency logic isnt super clear.
To clean it up so that users only install what is nessicary

Packing as releases to managers such as npm pip

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen. Provide an example if possible

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Chess Dice

Is your feature request related to a problem? Please describe.
Chess Dice have the faces:
the one represents a pawn, two a knight, three a bishop, four a rook, five a queen, and six a king.

Describe the solution you'd like
Add to builtins.macros, possibly add to the Unicode allowed in dice.g4 and then create a unit test

Describe alternatives
If Unicode adding is causing issues, you could use letters instead

Unicode Error

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

import dice_tower.dice as d
>>> d.roll("A")
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='C:\\Users\\ihunter\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\dice_tower\\links/macros.dice' mode='r' encoding='cp1252'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\ihunter\AppData\Local\Programs\Python\Python37-32\lib\site-packages\dice_tower\dice.py", line 145, in roll
    vt = predefined_macros()
  File "C:\Users\ihunter\AppData\Local\Programs\Python\Python37-32\lib\site-packages\dice_tower\dice.py", line 101, in predefined_macros
    for x in f:
  File "C:\Users\ihunter\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 84: character maps to <undefined>

Expected behavior
Result: 1

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: Windows
  • Browser N/A
  • Version 1.2.13
  • Language: Python3.7.2

Additional context
Downlaoded from pip

Penetrating Exploding Dice (Hackmaster-Style Exploding Dice)

HackMaster (and some other systems) use a special style of exploding dice where the the additional rolls for each dice have 1 subtracted from the roll. To do this, add a p after the exclamation mark. So for example to roll 5 d6's, you would do /roll 5d6!p.

/roll 5d6!p

Improve Roadmap

Understand how we can communicate better our intended tasks - and how to best gather feedback from users

Discord Bot

This would likely increase the usage and popularity of our codebase

Low Power Mode

For embedded devices, disable high processing dice

Requires C Code

Cards

Is your feature request related to a problem? Please describe.
Cards have several options:
Full deck
Royals and aces only
Italian deck
Tarot
Suits

Describe the solution you'd like
Add to builtins.macros, possibly add to the Unicode allowed in dice.g4 and then create a unit test

Describe alternatives
If Unicode adding is causing issues, you could use letters instead

Negative Explosions not negative

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]
  • Language: [e.g. Python, Javascript]

Additional context
Add any other context about the problem here.

Black suits of cards are very difficult to distinguish in Discord Dark Mode.

Describe the bug
Title.

To Reproduce

  1. Deal cards to get a Club or a Spade.
  2. Be unable to tell which one you got.
  3. Deal more cards until you get a Club and a Spade in a single hand.
  4. Be unable to tell them apart.

Expected behavior
Black suits should be recoloured or given a border to be visible in Dark Mode.

Screenshots

8D, JD, 2C, 5C, 5S

Environment (please complete the following information):

  • OS: Windows 10
  • Desktop
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Demo App

Let users try out our code before they integrate it

Compounding Exploding Dice (Shadowrun-Style Exploding Dice)

Shadowrun (and some other systems) use a special style of exploding dice where the the additional rolls for each dice are added together as a single "roll". To do this, just use two exclamation marks instead of one. So for example to roll 5 d6's, you would do /roll 5d6!!. A common Shadowrun roll would be exploding dice compared to a target number, for example /roll {5d6!!}>8 (notice the use of the brackets to show that we don't mean "explode on anything greater than 8", but rather "explode on 6's compounding, then compare to 8 for successes). Even though the target number (8) is higher than the possible roll from a single die, with the compounding exploding rolls a single roll can be infinitely high!

/roll {5d6!!}>8

Sequences

Not just multople dice in one calc

Sorting Resultant Rolls

given >1 roll, sort them in either ascending or descending order

e.g. 10d6: 3,1,3,4,5,6,3
Sorted: 1,3,3,3,4,5,6

Degrees of success

Some games have a concept of Degrees of Success. For example a d20 could be interpreted in different tiers:

  • 0-4 Major Failure
  • 5-8 Minor Failure
  • 9-11 Neutral Event
  • 12-16 Minor Success
  • 17-20 Major Success

Currently we do no comparison against 'difficulties' or 'critieria' .
The closest we have is filtering, which can only apply one conditional at a time, so perhaps it would need to be expanded

Related: ArtemGr/Sidekick#6

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.