<commit_before>/*
 * main.cpp
 *
 *  Created on: Oct 13, 2017
 *      Author: austinhoffmann
 */

#include <iostream>
#include <unordered_map>
#include "./rapidXML/rapidxml_utils.hpp"
#include "./rapidXML/rapidxml.hpp"
#include "Object.h"
#include "Room.h"
#include "Container.hpp"
#include <sstream>
#include <iterator>
#include "helper.hpp"


int main(int argc, char* argv[]) {
	if(argc != 2) {
		std::cout << "Zork usage: ./Zork [filename]" << std::endl;
		return 0;
	}
	//create a c-string that will be parsed by rapidxml using the input file
	rapidxml::file<>ifile(argv[1]);
	//create a DOM model of the input file that is parsed
	rapidxml::xml_document<> doc;
	doc.parse<0>(ifile.data());


	//create an unordered map to store all of our Room objects
	std::unordered_map<std::string, Room> roomMap;

	//Map node is the first child of the XML overall tree
	rapidxml::xml_node<>* mapNode = doc.first_node("map");
  
  //Room creation
	rapidxml::xml_node<>* node = mapNode->first_node("room");

	if(node == nullptr) {
		std::cout << "Could not find a valid room with the XML parser" <<std::endl;
		return 0;
	}

	//keep creating rooms while we have new ones
	while(node) {
		//create Room
		Room room(node);
		//Add room to unordered map
		roomMap.insert(std::make_pair(room.get_name(), room));
		//Get next room node
		node = node->next_sibling("room");
	}
  
  //End Room Creation
  
  //Container creation
  
  node = mapNode->first_node("container");
  
  std::unordered_map<std::string, Container> containerMap;
  while(node) {
    Container container(node);
    containerMap.insert(std::make_pair(container.get_name(), container));
    node = node->next_sibling("container");
  }
  
  //End Container creation
  
  //Item creation
  
  node = mapNode->first_node("item");
  
  std::unordered_map<std::string, Item> itemMap;
  while(node) {
    Item item(node);
    itemMap.insert(std::make_pair(item.get_name(), item));
    node = node->next_sibling("item");
  }
  
  //End item Creation
  
  //Create the player's inventory
  auto inventory = Container();


	//END OF SETUP

	//START OF GAMEPLAY

	//Find the Entrance to start the game
	auto search = roomMap.find("Entrance");
	auto currentRoom = search->second;
  std::cout << currentRoom.get_description() << std::endl;
  
  //Start game
  bool exit_condition = false;
	while(exit_condition == false) {
		//Get user input
		std::string input;
		std::getline(std::cin, input);
    
    //n, s, e, w
    if(input == "n" || input == "s" || input == "e" || input == "w") {
       currentRoom = currentRoom.movement(input, roomMap);
    }
    
    //open exit
    else if(input == "open exit") {
      exit_condition = currentRoom.exit_check();
    }
    
    //i
    else if(input == "i") {
      inventory.open_container();
    }
    
    //open (container)
    else if(input.substr(0,4) == "open") {
      std::string containerName = input.substr(5);
      bool found = currentRoom.find_container(containerName);
      if(found) {
        auto containerSearch = containerMap.find(containerName);
        auto container = containerSearch->second;
        container.open_container();
      }
      else {
        std::cout << "Error: that container is not in this room" << std::endl;
      }
    }
    
    //put (item) in (container)
    else if(input.substr(0,3) == "put") {
      std::istringstream iss{input};
      std::vector<std::string> tokens{std::istream_iterator<std::string>{iss}, std::istream_iterator<std::string>{}};
      bool found = inventory.find_item(tokens[1]);
      if(found) {
        bool containerFound = currentRoom.find_container(tokens[3]);
        if(containerFound) {
          auto containerSearch = containerMap.find(tokens[3]);
          auto container = containerSearch->second;
          container.add_item(tokens[1]);
          
          //update container stored in the map for future lookup
          update_map<Container>(container, containerMap);
          
          inventory.remove_item(tokens[1]);
          
          std::cout << "Item " << tokens[1] << " added to " << tokens[3] << std::endl;
        }
        else {
          std::cout << "Error: that container is not in this room" << std::endl;
        }
        
      }
      else {
        std::cout << "Error: you dont have " << tokens[1] << " in your inventory" << std::endl;
      }
    }
    
    //take (item)
    else if(input.substr(0,4) == "take") {
      std::string itemName = input.substr(5);
      bool found = currentRoom.find_item(itemName, containerMap);
      if(found) {
        inventory.add_item(itemName);
        currentRoom.remove_item(itemName, containerMap);
        
        update_map<Room>(currentRoom, roomMap);
        std::cout << "Item " << itemName << " added to inventory" << std::endl;
      }
      else {
        std::cout << "Error: that item is not in the current room" << std::endl;
      }
    }
    
    else {
      std::cout << "Invalid Command" << std::endl;
    }
    
	}


	return 0;
}

<commit_msg>Add support for drop item<commit_after>/*
 * main.cpp
 *
 *  Created on: Oct 13, 2017
 *      Author: austinhoffmann
 */

#include <iostream>
#include <unordered_map>
#include "./rapidXML/rapidxml_utils.hpp"
#include "./rapidXML/rapidxml.hpp"
#include "Object.h"
#include "Room.h"
#include "Container.hpp"
#include <sstream>
#include <iterator>
#include "helper.hpp"


int main(int argc, char* argv[]) {
	if(argc != 2) {
		std::cout << "Zork usage: ./Zork [filename]" << std::endl;
		return 0;
	}
	//create a c-string that will be parsed by rapidxml using the input file
	rapidxml::file<>ifile(argv[1]);
	//create a DOM model of the input file that is parsed
	rapidxml::xml_document<> doc;
	doc.parse<0>(ifile.data());


	//create an unordered map to store all of our Room objects
	std::unordered_map<std::string, Room> roomMap;

	//Map node is the first child of the XML overall tree
	rapidxml::xml_node<>* mapNode = doc.first_node("map");
  
  //Room creation
	rapidxml::xml_node<>* node = mapNode->first_node("room");

	if(node == nullptr) {
		std::cout << "Could not find a valid room with the XML parser" <<std::endl;
		return 0;
	}

	//keep creating rooms while we have new ones
	while(node) {
		//create Room
		Room room(node);
		//Add room to unordered map
		roomMap.insert(std::make_pair(room.get_name(), room));
		//Get next room node
		node = node->next_sibling("room");
	}
  
  //End Room Creation
  
  //Container creation
  
  node = mapNode->first_node("container");
  
  std::unordered_map<std::string, Container> containerMap;
  while(node) {
    Container container(node);
    containerMap.insert(std::make_pair(container.get_name(), container));
    node = node->next_sibling("container");
  }
  
  //End Container creation
  
  //Item creation
  
  node = mapNode->first_node("item");
  
  std::unordered_map<std::string, Item> itemMap;
  while(node) {
    Item item(node);
    itemMap.insert(std::make_pair(item.get_name(), item));
    node = node->next_sibling("item");
  }
  
  //End item Creation
  
  //Create the player's inventory
  auto inventory = Container();


	//END OF SETUP

	//START OF GAMEPLAY

	//Find the Entrance to start the game
	auto search = roomMap.find("Entrance");
	auto currentRoom = search->second;
  std::cout << currentRoom.get_description() << std::endl;
  
  //Start game
  bool exit_condition = false;
	while(exit_condition == false) {
		//Get user input
		std::string input;
		std::getline(std::cin, input);
    
    //n, s, e, w
    if(input == "n" || input == "s" || input == "e" || input == "w") {
       currentRoom = currentRoom.movement(input, roomMap);
    }
    
    //open exit
    else if(input == "open exit") {
      exit_condition = currentRoom.exit_check();
    }
    
    //i
    else if(input == "i") {
      inventory.open_container();
    }
    
    //open (container)
    else if(input.substr(0,4) == "open" && input.size() > 5) {
      std::string containerName = input.substr(5);
      bool found = currentRoom.find_container(containerName);
      if(found) {
        auto containerSearch = containerMap.find(containerName);
        auto container = containerSearch->second;
        container.open_container();
      }
      else {
        std::cout << "Error: that container is not in this room" << std::endl;
      }
    }
    
    //put (item) in (container)
    else if(input.substr(0,3) == "put" && input.size() > 3) {
      std::istringstream iss{input};
      std::vector<std::string> tokens{std::istream_iterator<std::string>{iss}, std::istream_iterator<std::string>{}};
      if(tokens.size() == 4) {
        bool found = inventory.find_item(tokens[1]);
        if(found) {
          bool containerFound = currentRoom.find_container(tokens[3]);
          if(containerFound) {
            auto containerSearch = containerMap.find(tokens[3]);
            auto container = containerSearch->second;
            container.add_item(tokens[1]);
            
            //update container stored in the map for future lookup
            update_map<Container>(container, containerMap);
            
            inventory.remove_item(tokens[1]);
            
            std::cout << "Item " << tokens[1] << " added to " << tokens[3] << std::endl;
          }
          else {
            std::cout << "Error: that container is not in this room" << std::endl;
          }
          
        }
        else {
          std::cout << "Error: you dont have " << tokens[1] << " in your inventory" << std::endl;
        }
      }
      else {
        std::cout << "Invalid command" << std::endl;
      }
    }
    
    //take (item)
    else if(input.substr(0,4) == "take" && input.size() > 4) {
      std::string itemName = input.substr(5);
      bool found = currentRoom.find_item(itemName, containerMap);
      if(found) {
        inventory.add_item(itemName);
        currentRoom.remove_item(itemName, containerMap);
        
        update_map<Room>(currentRoom, roomMap);
        std::cout << "Item " << itemName << " added to inventory" << std::endl;
      }
      else {
        std::cout << "Error: that item is not in the current room" << std::endl;
      }
    }
    
    //drop (item)
    else if(input.substr(0,4) == "drop" && input.size() > 5) {
      std::string itemName = input.substr(5);
      bool found = inventory.find_item(itemName);
      if(found) {
        inventory.remove_item(itemName);
        currentRoom.add_item(itemName);
        update_map<Room>(currentRoom, roomMap);
        std::cout << itemName << " dropped" << std::endl;
      }
      else {
        std::cout << "Error: you do not have " << itemName << " in your inventory" << std::endl;
      }
    }
    
    else {
      std::cout << "Invalid Command" << std::endl;
    }
    
	}


	return 0;
}


{'fraction_non_alphanumeric': 0.14942421991084695, 'fraction_numerical': 0.005943536404160475, 'mean_word_length': 2.71986183074266, 'pattern_counts': {'":': 0, '<': 164, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2413980', 'n_tokens_mistral': 3506, 'n_tokens_neox': 3430, 'n_words': 845}