Phoenix2D-Library  0.10
PlayOn.cpp
Go to the documentation of this file.
1 /*
2  * Phoenix2D (RoboCup Soccer Simulation 2D League)
3  * Copyright (c) 2013 Ivan Gonzalez
4  *
5  * This file is part of Phoenix2D.
6  *
7  * Phoenix2D is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Phoenix2D is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Phoenix2D. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <iostream>
22 #include <vector>
23 #include <boost/circular_buffer.hpp>
24 #include "PlayOn.h"
25 #include "Commands.h"
26 #include "Game.h"
27 #include "Self.h"
28 #include "Actions.h"
29 #include "Player.h"
30 #include "Config.h"
31 namespace Phoenix
32 {
33 boost::circular_buffer<Position> positions(4);
34 bool move = false;
35 
36 PlayOn::PlayOn(Commands* commands, Actions* actions) : PlayMode(commands) {
37  this->actions = actions;
38 }
39 
41 
42 }
43 
45  if (Config::LOGGING) {
46  std::list<Player*> players = world.getPlayers();
47  std::clog << Game::GAME_TIME << Self::getPosition().toString() << " [" << players.size() << "]";
48  for (std::list<Player*>::iterator it = players.begin(); it != players.end(); ++it) {
49  std::clog << " - " << (*it)->getTeam() << "(" << (*it)->getUniformNumber() << "): [" << ((*it)->getPosition()).toString() << "," << ((*it)->getVelocity()).toString() << "]";
50  }
51  std::clog << std::endl;
52  std::clog.flush();
53  } else {
54  switch (Self::UNIFORM_NUMBER) {
55  case 1:
56  if (Self::TEAM_NAME.compare("Nemesis") == 0) {
57  positions.push_back(Position(0.0, 0.0));
58  }
59  move = true;
60  break;
61  case 2:
62  if (Self::TEAM_NAME.compare("Nemesis") == 0) {
63  positions.push_back(Position(-30.0, -20.0));
64  } else {
65  positions.push_back(Position(40.0, 0.0));
66  positions.push_back(Position(40.0, 20.0));
67  }
68  move = true;
69  break;
70  case 3:
71  if (Self::TEAM_NAME.compare("Nemesis") == 0) {
72  positions.push_back(Position(-20.0, 15.0));
73  } else {
74  positions.push_back(Position(50.0, -30.0));
75  }
76  move = true;
77  break;
78  default:
79  break;
80  }
81  }
82  commands->changeView("narrow");
83 }
84 
86  if (move) {
87  if (actions->goTo(positions.front())) {
88  if (positions.size() > 1) {
89  positions.rotate(positions.begin() + 1);
90  }
91  }
92  }
93  if (Config::LOGGING) {
94  std::list<Player*> players = world.getPlayers();
95  std::clog << Game::GAME_TIME << Self::getPosition().toString() << " [" << players.size() << "]";
96  for (std::list<Player*>::iterator it = players.begin(); it != players.end(); ++it) {
97  std::clog << " - " << (*it)->getTeam() << "(" << (*it)->getUniformNumber() << "): [" << ((*it)->getPosition()).toString() << "," << ((*it)->getVelocity()).toString() << "]";
98  }
99  std::clog << std::endl;
100  std::clog.flush();
101  }
102 }
103 
105 
106 }
107 
109 
110 }
111 
112 void PlayOn::onMessageReceived(std::string message, int sender) {
113 
114 }
115 }
static int UNIFORM_NUMBER
Definition: Self.h:49
void onMessageReceived(std::string message, int sender)
Definition: PlayOn.cpp:112
std::list< Player * > getPlayers()
Definition: WorldModel.cpp:42
void setup(WorldModel world)
Definition: PlayOn.cpp:44
void changeView(std::string width)
Definition: Commands.cpp:159
Commands * commands
Definition: PlayMode.h:61
Position The Position lorem Ipsum
Definition: Position.h:50
boost::circular_buffer< Position > positions(4)
static Position getPosition()
Definition: Self.cpp:714
Commands The Commans lorem Ipsum
Definition: Commands.h:42
void onPlayerExecute(WorldModel world)
Definition: PlayOn.cpp:85
WorldModel The WorldModel lorem Ipsum
Definition: WorldModel.h:38
static std::string TEAM_NAME
Definition: Self.h:48
bool goTo(Position position)
Definition: Actions.cpp:37
void onCoachExecute(WorldModel world)
Definition: PlayOn.cpp:108
void onGoalieExecute(WorldModel world)
Definition: PlayOn.cpp:104
std::string toString()
Definition: Position.cpp:105
bool move
Definition: PlayOn.cpp:34
PlayOn(Commands *commands, Actions *actions)
Definition: PlayOn.cpp:36
Actions * actions
Definition: PlayOn.h:45
static unsigned int GAME_TIME
Definition: Game.h:39
static bool LOGGING
Definition: Config.h:36
PlayMode The PlayMode lorem Ipsum
Definition: PlayMode.h:59
Actions The Actions lorem Ipsum
Definition: Actions.h:38
std::list< Player > players
Definition: World.cpp:30