1. David Stone
  2. Technical Machine

Commits

David Stone  committed f00a3b5

Moved Battles to the generic non-networked Client.

  • Participants
  • Parent commits 1ec64db
  • Branches default

Comments (0)

Files changed (5)

File source/clients/battles.hpp

View file
  • Ignore whitespace
 #include <memory>
 #include <string>
 
+#include "battle.hpp"
+
 namespace technicalmachine {
-class Battle;
 
 class Battles {
 	public:

File source/clients/client.cpp

View file
  • Ignore whitespace
 	return m_evaluation_constants;
 }
 
+void Client::handle_battle_begin(uint32_t battle_id, std::string const & opponent, Party const party) {
+	auto & battle = battles.handle_begin(battle_id, opponent);
+	battle.set_party_if_unknown(party);
+}
+
+void Client::handle_battle_end(uint32_t const battle_id, Result const result) {
+	auto const & battle = battles.find(battle_id);
+	battle.handle_end(*this, result);
+	battles.handle_end(battle_id);
+}
+
+bool Client::challenges_are_queued() const {
+	return battles.challenges_are_queued();
+}
+
+std::string const & Client::first_challenger() const {
+	return battles.first_challenger();
+}
+
 }	// namespace technicalmachine

File source/clients/client.hpp

View file
  • Ignore whitespace
 #ifndef CLIENTS__CLIENT_HPP_
 #define CLIENTS__CLIENT_HPP_
 
+#include <string>
+
+#include "battles.hpp"
+
 #include "../evaluate/evaluate.hpp"
 
 #include "../team_predictor/detailed_stats.hpp"
 	protected:
 		Settings load_settings();
 		void reload_settings();
+		template<typename ... Args>
+		void handle_challenge_withdrawn(Args && ... args) {
+			return battles.handle_challenge_withdrawn(std::forward<Args>(args)...);
+		}
+		void handle_battle_begin(uint32_t battle_id, std::string const & opponent, Party party = Party());
+		void handle_battle_end(uint32_t battle_id, Result result);
+		template<typename ... Args>
+		Battle const & find_battle(Args && ... args) const {
+			return battles.find(std::forward<Args>(args)...);
+		}
+		template<typename ... Args>
+		Battle & find_battle(Args && ... args) {
+			return battles.find(std::forward<Args>(args)...);
+		}
+		template<typename Battle, typename ... Args>
+		Battle const & add_pending_challenge(Args && ... args) {
+			return battles.add_pending_challenge<Battle>(std::forward<Args>(args)...);
+		}
+		bool challenges_are_queued() const;
+		std::string const & first_challenger() const;
 	private:
 		std::string time_stamp() const;
+		Battles battles;
 		DetailedStats detailed_stats;
 		Evaluate m_evaluation_constants;
 		std::string time_format;

File source/clients/network/client.cpp

View file
  • Ignore whitespace
 	handle_finalize_challenge (opponent, accepted, challenger);
 }
 
-void Client::handle_challenge_withdrawn (std::string const & opponent) {
-	battles.handle_challenge_withdrawn(opponent);
-}
-
-void Client::handle_battle_begin (uint32_t battle_id, std::string const & opponent, Party const party) {
-	auto & battle = battles.handle_begin(battle_id, opponent);
-	battle.set_party_if_unknown(party);
-//	pause_at_start_of_battle ();
-}
-
-void Client::pause_at_start_of_battle () {
-	// The bot pauses before it sends actions at the start of the battle to
-	// give spectators a chance to join.
-	boost::asio::deadline_timer pause (io, boost::posix_time::seconds (10));
-	pause.wait ();
-}
-
 std::string const & Client::username() const {
 	return current_username;
 }
 	return current_password;
 }
 
-void Client::handle_battle_end (uint32_t const battle_id, Result const result) {
-	auto const & battle = battles.find(battle_id);
-	battle.handle_end (*this, result);
-	battles.handle_end(battle_id);
-}
-
 Team Client::generate_team() {
 	return Team(random_engine, team_file_name);
 }
 	reload_settings();
 }
 
-bool Client::challenges_are_queued() const {
-	return battles.challenges_are_queued();
-}
-
-std::string const & Client::first_challenger() const {
-	return battles.first_challenger();
-}
-
 }	// namespace network
 }	// namespace technicalmachine

File source/clients/network/client.hpp

View file
  • Ignore whitespace
 #include <boost/asio/ip/tcp.hpp>
 
 #include "../battle.hpp"
-#include "../battles.hpp"
 #include "../client.hpp"
 
 namespace technicalmachine {
 		void handle_incoming_challenge (std::string const & opponent, GenericBattleSettings const & settings);
 		template<typename Battle, typename ... Args>
 		Battle const & add_pending_challenge (Team const & team, std::string const & opponent, Args && ... args) {
-			return battles.add_pending_challenge<Battle>(opponent, rd(), depth, std::forward<Args>(args)..., team);
+			return ::technicalmachine::Client::add_pending_challenge<Battle>(opponent, rd(), depth, std::forward<Args>(args)..., team);
 		}
 		template<typename Battle, typename ... Args>
 		Battle const & add_pending_challenge (std::string const & opponent, Args && ... args) {
-			return battles.add_pending_challenge<Battle>(opponent, rd(), depth, std::forward<Args>(args)..., team_file_name);
+			return ::technicalmachine::Client::add_pending_challenge<Battle>(opponent, rd(), depth, std::forward<Args>(args)..., team_file_name);
 		}
-		template<typename ... Args>
-		Battle const & find_battle(Args && ... args) const {
-			return battles.find(std::forward<Args>(args)...);
-		}
-		template<typename ... Args>
-		Battle & find_battle(Args && ... args) {
-			return battles.find(std::forward<Args>(args)...);
-		}
-		template<typename ... Args>
-		void handle_challenge_withdrawn(Args && ... args) {
-			return battles.handle_challenge_withdrawn(std::forward<Args>(args)...);
-		}
-		bool challenges_are_queued() const;
-		std::string const & first_challenger() const;
 		template<typename Timer>
 		std::unique_ptr<Timer> make_timer() {
 			return std::unique_ptr<Timer>(new Timer(io));
 		}
-		void handle_challenge_withdrawn (std::string const & opponent);
-		void handle_battle_begin (uint32_t battle_id, std::string const & opponent, Party party = Party());
-		void pause_at_start_of_battle ();
 		virtual void handle_finalize_challenge (std::string const & opponent, bool accepted, bool challenger) = 0;
-		void handle_battle_end(uint32_t battle_id, Result result);
 		void handle_private_message (std::string const & sender, std::string const & message);
 	private:
 		bool is_trusted (std::string const & user) const;
 		virtual void send_battle_challenge (std::string const & opponent) = 0;
 
 		boost::asio::io_service io;
-		Battles battles;
 		std::string host;
 		std::string port;
 		std::random_device rd;