Created
January 16, 2016 07:48
-
-
Save masyax/4db7ebe560fedefe60cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef _INC_DICE | |
| #define _INC_DICE | |
| #include <random> | |
| class dice{ | |
| private: | |
| int top; | |
| int front; | |
| public: | |
| static const int side[6][4]; | |
| dice(){ | |
| top = 1; | |
| front = 0; | |
| } | |
| dice(int a, int b){ | |
| top = a; | |
| front = 0; | |
| for (int i = 0; i < 4; i++) | |
| if (b == side[top - 1][i]){ | |
| front = i; | |
| break; | |
| } | |
| } | |
| public: | |
| int getT(){ return top; } | |
| int getF(){ return side[top - 1][front]; } | |
| void set(int a, int b){ | |
| top = a; | |
| front = 0; | |
| for (int i = 0; i < 4; i++) | |
| if (b == side[top - 1][i]){ | |
| front = i; | |
| break; | |
| } | |
| } | |
| void throwDice(){ | |
| std::random_device rd; | |
| top = (rd() % 6) + 1; | |
| front = (rd() % 4); | |
| } | |
| void rollX(int n){ | |
| n %= 4; | |
| int top2 = top; | |
| int front2 = front; | |
| for (int i = 0; i < 4; i++) | |
| if (top2 == side[side[top2 - 1][(front2 + 3) % 4] - 1][i]){ | |
| top = side[side[top2 - 1][(front2 + 3) % 4] - 1][(i + n + 4) % 4]; | |
| for (int j = 0; j < 4; j++) | |
| if (side[top - 1][j] == side[side[top2 - 1][(front2 + 3) % 4] - 1][(i + n + 4 + 3) % 4]){ | |
| front = j; | |
| break; | |
| } | |
| break; | |
| } | |
| } | |
| void rollY(int n){ | |
| n %= 4; | |
| front += n + 4; | |
| front %= 4; | |
| } | |
| void rollZ(int n){ | |
| n %= 4; | |
| int top2 = top; | |
| int front2 = front; | |
| for (int i = 0; i < 4; i++) | |
| if (top2 == side[side[top2 - 1][front2] - 1][i]){ | |
| top = side[side[top2 - 1][front2] - 1][(i + n + 4) % 4]; | |
| for (int j = 0; j < 4;j++) | |
| if (side[top - 1][j] == side[top2 - 1][front2]){ | |
| front = j; | |
| break; | |
| } | |
| break; | |
| } | |
| } | |
| }; | |
| const int dice::side[6][4] = { | |
| { 2, 4, 5, 3 }, { 1, 3, 6, 4 }, { 1, 5, 6, 2 }, { 1, 2, 6, 5 }, { 1, 4, 6, 3 }, { 2, 3, 5, 4 } | |
| }; | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment