Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <iterator>
- using namespace std;
- int main()
- {
- unsigned char z = '0';
- int size;
- int playerState[4] = { 0 };
- bool playerStart[4] = { false };
- int lineNum = 0;
- int playerNum = 0;
- string line;
- ifstream myfile("commands.txt");
- for (int i = 0; i <= 7; i++)
- z &= ~(1 << i);
- if (myfile.is_open())
- {
- while (getline(myfile, line))
- {
- if (line.length() <= 3) {
- if (lineNum == 0) {
- //1st line
- size = stoi(line);
- }
- else {
- if (line.length() == 1 && line.at(0) == 'P') {
- //P
- for (int i = 0; i <= 3; i++) {
- if (playerStart[i] == true)
- std::cout << playerState[i] << " ";
- else
- std::cout << "0 ";
- }
- for (int i = 0; i <= 7; i++) {
- int j = (z >> i) & 1;
- std::cout << j;
- }
- std::cout << endl;
- }
- else if (line.length() == 3 && line.at(0) == 'M') {
- //M x
- int steps = line.at(2) - '0';
- int currentPlayerState = playerState[playerNum % 4];
- if (playerStart[playerNum % 4]== false) {
- if (playerState[playerNum % 4] == 0 && steps == 1) {
- //player rolled 1
- playerState[playerNum % 4]++;
- }
- if (playerState[playerNum % 4] == 1 && steps == 6) {
- //player rolled 1 & 6
- playerState[playerNum % 4] = 0;
- playerStart[playerNum % 4] = true;
- z |= (1 << (playerNum % 4) * 2);
- }
- }
- else {
- currentPlayerState += steps;s
- if (currentPlayerState != playerState[0] && currentPlayerState != playerState[1] && currentPlayerState != playerState[2] && currentPlayerState != playerState[3] || currentPlayerState <= 1) {
- playerState[playerNum % 4] += steps;
- if (playerState[playerNum % 4] % 2 == 1) {
- z |= (1 << ((playerNum % 4) * 2) + 1);
- }
- else {
- z &= ~(1 << ((playerNum % 4) * 2) + 1);
- }
- if (playerState[playerNum % 4] >= size) {
- std::cout << "END OF GAME" << "Wygral gracz z numerem " << (playerNum % 4) + 1;
- return 0;
- }
- }
- else {
- playerState[playerNum % 4] = 0;
- playerStart[playerNum % 4] = false;
- z &= ~(1 << (playerNum % 4) * 2);
- }
- }
- //cout << steps << endl;
- playerNum++;
- }
- }
- }
- else {
- //Line too long
- }
- lineNum++;
- }
- myfile.close();
- }
- else std::cout << "Unable to open file";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement