Phoenix2D-Library  0.10
WorldModel.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 "WorldModel.h"
22 namespace Phoenix
23 {
24 
26 
27 bool compareDistances(Player* player0, Player* player1) {
28  double distance0 = player0->getPosition().getDistanceTo(positionToCompare);
29  double distance1 = player1->getPosition().getDistanceTo(positionToCompare);
30  return (distance0 < distance1);
31 }
32 
33 WorldModel::WorldModel(std::list<Player> players, Ball ball) {
34  this->players = players;
35  this->ball = ball;
36 }
37 
39 
40 }
41 
42 std::list<Player*> WorldModel::getPlayers() {
43  std::list<Player*> all_players;
44  for (std::list<Player>::iterator it = players.begin(); it != players.end(); ++it) {
45  all_players.push_back(&(*it));
46  }
47  return all_players;
48 }
49 
51  std::list<Player*> all_players;
52  positionToCompare = position;
53  for (std::list<Player>::iterator it = players.begin(); it != players.end(); ++it) {
54  all_players.push_back(&(*it));
55  }
56  all_players.sort(compareDistances);
57  return all_players;
58 }
59 
60 std::list<Player*> WorldModel::getOurPlayers() {
61  std::list<Player*> our_players;
62  for (std::list<Player>::iterator it = players.begin(); it != players.end(); ++it) {
63  if (it->getTeam().compare("our") == 0) {
64  our_players.push_back(&(*it));
65  }
66  }
67  return our_players;
68 }
69 
71  std::list<Player*> our_players;
72  positionToCompare = position;
73  for (std::list<Player>::iterator it = players.begin(); it != players.end(); ++it) {
74  if (it->getTeam().compare("our") == 0) {
75  our_players.push_back(&(*it));
76  }
77  }
78  our_players.sort(compareDistances);
79  return our_players;
80 }
81 
82 std::list<Player*> WorldModel::getOppPlayers() {
83  std::list<Player*> opp_players;
84  for (std::list<Player>::iterator it = players.begin(); it != players.end(); ++it) {
85  if (it->getTeam().compare("opp") == 0) {
86  opp_players.push_back(&(*it));
87  }
88  }
89  return opp_players;
90 }
91 
93  std::list<Player*> opp_players;
94  positionToCompare = position;
95  for (std::list<Player>::iterator it = players.begin(); it != players.end(); ++it) {
96  if (it->getTeam().compare("opp") == 0) {
97  opp_players.push_back(&(*it));
98  }
99  }
100  opp_players.sort(compareDistances);
101  return opp_players;
102 }
103 
104 std::list<Player*> WorldModel::getUndPlayers() {
105  std::list<Player*> und_players;
106  for (std::list<Player>::iterator it = players.begin(); it != players.end(); ++it) {
107  if (it->getTeam().compare("undefined") == 0) {
108  und_players.push_back(&(*it));
109  }
110  }
111  return und_players;
112 }
113 
115  std::list<Player*> und_players;
116  positionToCompare = position;
117  for (std::list<Player>::iterator it = players.begin(); it != players.end(); ++it) {
118  if (it->getTeam().compare("undefined") == 0) {
119  und_players.push_back(&(*it));
120  }
121  }
122  und_players.sort(compareDistances);
123  return und_players;
124 }
125 
127  return &ball;
128 }
129 }
WorldModel(std::list< Player > players, Ball ball)
Definition: WorldModel.cpp:33
Position positionToCompare
Definition: WorldModel.cpp:25
std::list< Player * > getPlayers()
Definition: WorldModel.cpp:42
Player The Player lorem Ipsum
Definition: Player.h:39
Ball The Ball lorem Ipsum
Definition: Ball.h:38
Position The Position lorem Ipsum
Definition: Position.h:50
Ball ball
Definition: World.cpp:31
std::list< Player * > getUndPlayersOrderedByDistanceTo(Position position)
Definition: WorldModel.cpp:114
bool compareDistances(Player *player0, Player *player1)
Definition: WorldModel.cpp:27
std::list< Player > players
Definition: WorldModel.h:39
std::list< Player * > getOppPlayersOrderedByDistanceTo(Position position)
Definition: WorldModel.cpp:92
std::list< Player * > getOurPlayers()
Definition: WorldModel.cpp:60
std::list< Player * > getUndPlayers()
Definition: WorldModel.cpp:104
std::list< Player * > getPlayersOrderedByDistanceTo(Position position)
Definition: WorldModel.cpp:50
Position getPosition()
Definition: Player.cpp:311
std::list< Player * > getOppPlayers()
Definition: WorldModel.cpp:82
std::list< Player * > getOurPlayersOrderedByDistanceTo(Position position)
Definition: WorldModel.cpp:70
std::list< Player > players
Definition: World.cpp:30
double getDistanceTo(Position position)
Definition: Position.cpp:81