From 1ce2f82187dc028c9987873a57312d88df0a1e82 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 24 Jun 2005 18:23:48 +0000 Subject: [PATCH] initial commit --- bot.cpp | 38 ++++++++++++++++++++++++++++++ bot.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 bot.cpp create mode 100644 bot.h diff --git a/bot.cpp b/bot.cpp new file mode 100644 index 0000000..c7af4a6 --- /dev/null +++ b/bot.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include "bot.h" + +using namespace std; +using namespace __gnu_cxx; + +Bot::Bot(string name, string type){ + _name = name; + _type = type; +} + +void Bot::play(){ + cout << "reg: " << _name << " " << _type << endl; + + string input; + getline(cin, input); + if (input != "wsk\\") + return; + getline(cin, input); + _name = tokenizeString(input)[1]; + cerr << "Got name: " << _name << endl; + buildGraph(); + updateWorld(); + turn(); +} + +void Bot::buildGraph(){ + +} + +std::vector tokenizeString(std::string input){ + istringstream istr(input); + vector strings; + copy(istream_iterator(istr), istream_iterator(), back_inserter(strings)); + return strings; +} diff --git a/bot.h b/bot.h new file mode 100644 index 0000000..d07fb06 --- /dev/null +++ b/bot.h @@ -0,0 +1,73 @@ +#ifndef __BOT_H__ +#define __BOT_H__ + +#include +#include +#include +#include +// These are needed to be able to use std::string as key in a hash_map. +namespace __gnu_cxx { + template< typename CharT, typename Traits, typename Alloc > + struct hash< std::basic_string > { + size_t operator()(const std::basic_string& s) const { + + const std::collate& c = std::use_facet< std::collate >(std::locale()); + + return c.hash(s.c_str(), s.c_str() + s.size()); + + } + + }; + + template< typename CharT, typename Traits, typename Alloc > + struct hash< const std::basic_string > { //yes you need this version aswell! + + size_t operator()(const std::basic_string& s) const { + + const std::collate& c = std::use_facet< std::collate >(std::locale()); + + return c.hash(s.c_str(), s.c_str() + s.size()); + } + + }; +}; + +struct AdjInfo{ + std::string intersection; +}; + +struct Intersection{ + std::vector adjs; +}; + +struct Player{ + std::string type; + std::string location; +}; + +struct Bank{ + std::string location; + int value; +}; + +std::vector tokenizeString(std::string input); + +class Bot { + public: + Bot(std::string name, std::string type); + + void play(); + void buildGraph(); + void updateWorld(); + virtual void turn() = 0; + + private: + __gnu_cxx::hash_map _intersections; + __gnu_cxx::hash_map _players; + std::string _name; + std::string _type; + std::string _position; +}; + + +#endif -- 2.39.2