Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct Tile
- {
- bool up;
- bool right;
- bool down;
- bool left;
- int x; // just for save points, the save points cordinate
- int y; // just for save points, the save points cordinate
- int k; // just for save points, how many steps at that save point
- };
- struct Player
- {
- int num_player_quests;
- int x;
- int y;
- Tile player_tile;
- };
- struct Item
- {
- string item_name;
- int x;
- int y;
- int player_id;
- };
- struct Quest
- {
- string quest_name;
- int player_id;
- };
- bool can_up(Tile me, vector<vector<Tile> > line) // can it go one step up
- {
- if(me.y == 0)return false;
- else if(line[me.x][me.y].up == true && line[me.x][me.y - 1].down == true)return true;
- else return false;
- }
- bool can_right(Tile me, vector<vector<Tile> > line) // can it go one step right
- {
- if(me.x == 6)return false;
- else if(line[me.x][me.y].right == true && line[me.x + 1][me.y].left == true)return true;
- else return false;
- }
- bool can_down(Tile me, vector<vector<Tile> > line) // can it go one step down
- {
- if(me.y == 6)return false;
- else if(line[me.x][me.y].down == true && line[me.x][me.y + 1].up == true)return true;
- else return false;
- }
- bool can_left(Tile me, vector<vector<Tile> > line) // can it go one step left
- {
- if(me.x == 0)return false;
- else if(line[me.x][me.y].left == true && line[me.x - 1][me.y].right == true)return true;
- else return false;
- }
- bool check_if_available_path(vector<vector<Tile> > line, Item item, Player me, vector<Tile> &save_points)
- {
- int k = 0; // number of steps, limit is 20
- int save_index = -1; // which save point is which
- Tile copy_me; // the one that moves around to look if there is an available path
- int control_k = 0; // how many steps with all coming to save_points around 40 (for testing)
- copy_me.x = me.x;
- copy_me.y = me.y;
- item.x = item.x - 1;
- item.y = item.y - 1;
- if(can_up(copy_me, line) == false && can_right(copy_me, line) == false && can_down(copy_me, line) == false && can_left(copy_me, line) == false)return false;
- while((copy_me.x != item.x || copy_me.y != item.y) && k <= 20 && control_k <= 40)
- {
- //cerr << "copy_me x " << copy_me.x << " item x " << item.x <<endl << "copy_me y " << copy_me.y << " item y " << item.y <<endl;
- if(copy_me.x == item.x && copy_me.y == item.y)return true;
- if(can_up(copy_me, line) == true)
- {
- if(line[copy_me.x][copy_me.y].up + line[copy_me.x][copy_me.y].right + line[copy_me.x][copy_me.y].down + line[copy_me.x][copy_me.y].left > 1)
- {
- Tile save;
- save.up = line[copy_me.x][copy_me.y].up; save.right = line[copy_me.x][copy_me.y].right; save.down = line[copy_me.x][copy_me.y].down; save.left = line[copy_me.x][copy_me.y].left;
- save.x = copy_me.x; save.y = copy_me.y;
- save.k = k;
- save_points.push_back(save);
- save_index++;
- }
- line[copy_me.x][copy_me.y].up = false;
- save_points[save_index].up = false;
- copy_me.x = copy_me.x;
- copy_me.y = copy_me.y - 1;
- k++;
- //control_k++;
- line[copy_me.x][copy_me.y].down = false;
- }
- else if(can_right(copy_me, line) == true)
- {
- if(line[copy_me.x][copy_me.y].up + line[copy_me.x][copy_me.y].right + line[copy_me.x][copy_me.y].down + line[copy_me.x][copy_me.y].left > 1)
- {
- Tile save;
- save.up = line[copy_me.x][copy_me.y].up; save.right = line[copy_me.x][copy_me.y].right; save.down = line[copy_me.x][copy_me.y].down; save.left = line[copy_me.x][copy_me.y].left;
- save.x = copy_me.x; save.y = copy_me.y;
- save.k = k;
- save_points.push_back(save);
- save_index++;
- }
- line[copy_me.x][copy_me.y].right = false;
- save_points[save_index].right = false;
- copy_me.x = copy_me.x + 1;
- copy_me. y = copy_me.y;
- k++;
- //control_k++;
- line[copy_me.x][copy_me.y].left = false;
- }
- else if(can_down(copy_me, line) == true)
- {
- if(line[copy_me.x][copy_me.y].up + line[copy_me.x][copy_me.y].right + line[copy_me.x][copy_me.y].down + line[copy_me.x][copy_me.y].left > 1)
- {
- Tile save;
- save.up = line[copy_me.x][copy_me.y].up; save.right = line[copy_me.x][copy_me.y].right; save.down = line[copy_me.x][copy_me.y].down; save.left = line[copy_me.x][copy_me.y].left;
- save.x = copy_me.x; save.y = copy_me.y;
- save.k = k;
- save_points.push_back(save);
- save_index++;
- }
- line[copy_me.x][copy_me.y].down = false;
- save_points[save_index].down = false;
- copy_me.x = copy_me.x + 1;
- copy_me.y = copy_me.y;
- k++;
- //control_k++;
- line[copy_me.x][copy_me.y].up = false;
- }
- else if(can_left(copy_me, line) == true)
- {
- if(line[copy_me.x][copy_me.y].up + line[copy_me.x][copy_me.y].right + line[copy_me.x][copy_me.y].down + line[copy_me.x][copy_me.y].left > 1)
- {
- Tile save;
- save.up = line[copy_me.x][copy_me.y].up; save.right = line[copy_me.x][copy_me.y].right; save.down = line[copy_me.x][copy_me.y].down; save.left = line[copy_me.x][copy_me.y].left;
- save.x = copy_me.x; save.y = copy_me.y;
- save.k = k;
- save_points.push_back(save);
- save_index++;
- }
- line[copy_me.x][copy_me.y].left = false;
- save_points[save_index].left = false;
- copy_me.x = copy_me.x + 1;
- copy_me.y = copy_me.y;
- k++;
- //control_k++;
- line[copy_me.x][copy_me.y].right = false;
- }
- else if(can_up(copy_me, line) == false && can_right(copy_me, line) == false && can_down(copy_me, line) == false && can_left(copy_me, line) == false)
- {
- if(save_points.size() > 0)
- {
- copy_me = save_points[save_points.size() - 1];
- }
- k = save_points[save_points.size() - 1].k;
- if(save_points[save_points.size()-1].up + save_points[save_points.size()-1].right + save_points[save_points.size()-1].down + save_points[save_points.size()-1].left <= 1)
- {
- save_points.erase(save_points.end() - 1);
- }
- }
- control_k++;
- //cerr << control_k << endl;
- }
- //cerr << "control_k : " << control_k << " k :" << k << endl;
- if(control_k >= 40 || k >= 20)return false;
- else return true;
- }
- int main()
- {
- // game loop
- while (1)
- {
- vector<vector<Tile> > line;
- vector<Tile> save_points;
- Player me;
- Player enemy;
- vector<Item> items;
- vector<Quest> quests;
- line.resize(7);
- int turn_type;
- cin >> turn_type; cin.ignore();
- //cerr << turn_type << endl;
- for (int i = 0; i < line.size(); i++) // ivedu duomenis zaidimo lentos
- {
- for (int j = 0; j < 7; j++)
- {
- string tile;
- cin >> tile; cin.ignore();
- line[i].push_back({tile[j] - '0', tile[1] - '0', tile[2] - '0', tile[3] - '0'});
- //cerr << line[i][j].up << line[i][j].right << line[i][j].down << line[i][j].left << " ";
- //cerr << tile << " ";
- }
- //cerr << endl;
- }
- string a;string b;Tile A;Tile B;// cancer tik duomenu uzsaugojimui
- cin >> me.num_player_quests >> me.x >> me.y >> a; cin.ignore(); // ivedu duomenis apie save
- A.up = a[0] - '0'; A.right = a[1] - '0'; A.down = a[2] - '0'; A.left = a[3] - '0';
- me.player_tile = A;
- cin >> enemy.num_player_quests >> enemy.x >> enemy.y >> b; cin.ignore(); // ivedu duomenis apie priesa
- B.up = b[0] - '0'; B.right = b[1] - '0'; B.down = b[2] - '0'; B.left = b[3] - '0';
- enemy.player_tile = B;
- //cerr << me.num_player_quests << " " << me.x << " " << me.y << " " << me.player_tile.up << endl;
- int num_of_items;
- cin >> num_of_items; cin.ignore();// the total number of items available on board and on player tiles
- for (int i = 0; i < num_of_items; i++)
- {
- Item A;
- cin >> A.item_name >> A.x >> A.y >> A.player_id; cin.ignore();
- items.push_back(A);
- }
- int num_of_quests;
- cin >> num_of_quests; cin.ignore(); // the total number of revealed quests for both players
- for (int i = 0; i < num_of_quests; i++)
- {
- Quest A;
- cin >> A.quest_name >> A.player_id; cin.ignore();
- quests.push_back(A);
- }
- if(items.size() > 0)
- {
- cerr << check_if_available_path(line, items[0], me , save_points);
- }
- if(turn_type == 0) // push
- {
- cout << "PUSH 1 RIGHT" << endl; // PUSH <id> <direction> | MOVE <direction> | PASS
- }
- if(turn_type == 1) // move
- {
- cout << "MOVE RIGHT DOWN RIGHT DOWN UP RIGHT LEFT UP RIGHT DOWN LEFT" << endl;
- //cout << "PASS";
- }
- //cerr << me.player_tile.up << me.player_tile.right << me.player_tile.down << me.player_tile.left;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement