Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <iterator>
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12. unsigned char z = '0';
  13. int size;
  14. int playerState[4] = { 0 };
  15. bool playerStart[4] = { false };
  16. int lineNum = 0;
  17. int playerNum = 0;
  18.  
  19. string line;
  20. ifstream myfile("commands.txt");
  21.  
  22. for (int i = 0; i <= 7; i++)
  23. z &= ~(1 << i);
  24.  
  25.  
  26. if (myfile.is_open())
  27. {
  28. while (getline(myfile, line))
  29. {
  30. if (line.length() <= 3) {
  31.  
  32. if (lineNum == 0) {
  33. //1st line
  34. size = stoi(line);
  35.  
  36. }
  37. else {
  38. if (line.length() == 1 && line.at(0) == 'P') {
  39. //P
  40. for (int i = 0; i <= 3; i++) {
  41. if (playerStart[i] == true)
  42. std::cout << playerState[i] << " ";
  43. else
  44. std::cout << "0 ";
  45. }
  46.  
  47. for (int i = 0; i <= 7; i++) {
  48. int j = (z >> i) & 1;
  49. std::cout << j;
  50. }
  51.  
  52. std::cout << endl;
  53.  
  54.  
  55. }
  56. else if (line.length() == 3 && line.at(0) == 'M') {
  57. //M x
  58. int steps = line.at(2) - '0';
  59. int currentPlayerState = playerState[playerNum % 4];
  60. if (playerStart[playerNum % 4]== false) {
  61. if (playerState[playerNum % 4] == 0 && steps == 1) {
  62. //player rolled 1
  63. playerState[playerNum % 4]++;
  64.  
  65. }
  66. if (playerState[playerNum % 4] == 1 && steps == 6) {
  67. //player rolled 1 & 6
  68. playerState[playerNum % 4] = 0;
  69. playerStart[playerNum % 4] = true;
  70. z |= (1 << (playerNum % 4) * 2);
  71.  
  72. }
  73. }
  74. else {
  75.  
  76. currentPlayerState += steps;s
  77. if (currentPlayerState != playerState[0] && currentPlayerState != playerState[1] && currentPlayerState != playerState[2] && currentPlayerState != playerState[3] || currentPlayerState <= 1) {
  78. playerState[playerNum % 4] += steps;
  79.  
  80.  
  81. if (playerState[playerNum % 4] % 2 == 1) {
  82. z |= (1 << ((playerNum % 4) * 2) + 1);
  83. }
  84. else {
  85. z &= ~(1 << ((playerNum % 4) * 2) + 1);
  86. }
  87.  
  88. if (playerState[playerNum % 4] >= size) {
  89. std::cout << "END OF GAME" << "Wygral gracz z numerem " << (playerNum % 4) + 1;
  90. return 0;
  91. }
  92. }
  93. else {
  94. playerState[playerNum % 4] = 0;
  95. playerStart[playerNum % 4] = false;
  96. z &= ~(1 << (playerNum % 4) * 2);
  97.  
  98. }
  99. }
  100.  
  101.  
  102. //cout << steps << endl;
  103. playerNum++;
  104.  
  105.  
  106.  
  107. }
  108. }
  109. }
  110. else {
  111. //Line too long
  112. }
  113.  
  114. lineNum++;
  115. }
  116.  
  117. myfile.close();
  118. }
  119.  
  120. else std::cout << "Unable to open file";
  121. return 0;
  122.  
  123.  
  124.  
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement