Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core dump with "g" operator #12

Closed
robinmoussu opened this issue Apr 12, 2018 · 8 comments
Closed

Core dump with "g" operator #12

robinmoussu opened this issue Apr 12, 2018 · 8 comments

Comments

@robinmoussu
Copy link

Hello, I was reading the documentation, and I don't understand what the Group operator is supposed to do. Can you please explain me what it is supposed to do?

I tried to test it, but I always got a core dump:

#0  0x00007ffffddc6c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffffddca028 in __GI_abort () at abort.c:89
#2  0x00007ffffedd5655 in QMessageLogger::fatal(char const*, ...) const () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#3  0x00007ffffedd2454 in qt_assert(char const*, char const*, int) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#4  0x000000000045e85a in QMap<long long, DieGroup>::first (this=0x7ffffffdda50) at /usr/include/qt5/QtCore/qmap.h:403
#5  0x000000000045c895 in GroupNode::getGroup (this=0x6afff0, values=...) at /home/robin/DiceParser/node/groupnode.cpp:266
#6  0x000000000045ba8c in GroupNode::run (this=0x6afff0, previous=0x6ad550) at /home/robin/DiceParser/node/groupnode.cpp:88
#7  0x000000000044e047 in DiceRollerNode::run (this=0x6ad550, previous=0x6ad030) at /home/robin/DiceParser/node/dicerollernode.cpp:61
#8  0x00000000004554ad in NumberNode::run (this=0x6ad030, previous=0x0) at /home/robin/DiceParser/node/numbernode.cpp:48
#9  0x0000000000433553 in DiceParser::start (this=0x7ffffffddf20) at /home/robin/DiceParser/diceparser.cpp:286
#10 0x0000000000464651 in startDiceParsing (cmds=..., treeFile=..., withColor=true, format=TERMINAL) at /home/robin/DiceParser/cli/main.cpp:213
@obiwankennedy
Copy link
Member

It is dedicated to build groups.
this command works for me but I made a fix perhaps it will fix your issue.

5d10g10

The group operator bring together die values to reach the group value (10 in previous example).
And the final result is the group count. In some games it is your success count.

result: 3 9 6 10 2
This sum of the result is 30. So you may think there is 3 group but in fact you can only build 2.
Number can only be part of one group.

10 => 1 group
+
9+6 => 1 group ( lost 5)
or
9+2 => 1 group ( lost 1)
or
6+3+2 => 1 group (lost 1)
or
9+3 => 1 group ( lost 2)

@robinmoussu
Copy link
Author

Isn't that just integer division?

10g3 => 3 group (lost 1)

@obiwankennedy
Copy link
Member

No it is more complex than that.
For example:
3d10g10 => 9, 9, 2

In this result, the integer division (9+9+2)/10 is 2
But in that case, g operator must return 1.
Because:
9+9 => 1 group (lost 8)
or
9+2 => 1 group (lost 1)
or
2+9 => 1 group (lost 1)
or
9+9 => 1 group (lost 8)

When you use a number, you lost it.
So if I use one 9 and the 2. I overcome 10. So I get one success. But one 9 remains and I can't reach 10 with 9.

Same if I use both 9, 18 > 10, So I get one success. But the 2 remains and I can't reach 10 with 2.

@robinmoussu
Copy link
Author

Ok, thanks for the precision. I think you should add this example to the documentation.

@robinmoussu
Copy link
Author

Btw, I'm happily surprise that he is able to correctly solve the backpack problem for case like 4d2g3 with the possible corner cases {2,2,1,1} and {1,1,2,2} who both need re-ordering. I just tested it, it effectively answers 2 in both cases.

@obiwankennedy
Copy link
Member

I'm not quiet sure my algorithm works every time and I can't prove it is right.
but as far I had tested, it never gives me a wrong result.

It was really funny to implement, but it is a bit dirty. Perhaps there are ways to make it cleaner and more optimized

@robinmoussu
Copy link
Author

I found a corner case (see commit 1b00f06 in the PR #15). I'm sad because this mean that I can't just copie your code in my re-write draft.

@obiwankennedy
Copy link
Member

I set many unit test on rolisteam code and I fix an issue about g operator. It was en endless loop in some case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants