Commit 050c1821 authored by gem2578's avatar gem2578 Committed by Marcus M. Scheunemann

can_kick is now returned and docs update

parent 51d2d55a
# Useful Classes
## Team (Class)
To setup a team you have to give it a Side
> Team(Side)
#### put()
Puts a Brain on the team and sets it field location
> put(Brain, (100, 250)) -> None
## Side (Enum)
......@@ -11,6 +13,7 @@
- RIGHT
#### other()
Returns the opposite side
> other() -> Side
## ObjectType (Enum)
......@@ -25,6 +28,8 @@
## Brain (Class)
- pos -> Vector2
- side -> Side
- can_kick -> Boolean
- ball -> CupObject
- self_goal -> CupObject
- other_goal -> CupObject
......@@ -32,13 +37,16 @@
- other_team -> [CupObject, ...]
#### sorted_object()
Returns a sorted list of all CupObject by distance
> sorted_object() -> [CupObject, ...]
#### action()
This needed to be defined in your inherited class
> action() -> Vector2 , Vector2
## pythocup
#### run()
When given a Left and Right Team it will run the simulation
> run(Team(LEFT), Team(RIGHT)) -> None
## Vector2 (Class)
......
......@@ -10,7 +10,7 @@ def main():
team_left.put(FollowBall, (100, 250))
team_right = Team(Side.RIGHT)
team_right.put(FollowBall, (700, 250))
# team_right.put(FollowBall, (700, 250))
pythocup.run(team_left, team_right)
......
......@@ -24,9 +24,9 @@ class Player(rs.Round):
self.other_team = other_team
def update(self):
self.brain.pre_action(self)
can_kick = self.brain.pre_action(self)
move, kick = self.brain.action()
if self.can_kick:
if can_kick:
self.ball.kick(kick)
if move.length() > self.max_speed:
move.scale_to_length(self.max_speed)
......@@ -58,9 +58,7 @@ class Brain():
def pre_action(self, body):
self.ball = CupObject(ObjectType.BALL, body.ball.rect().center)
self.pos = pygame.math.Vector2(body.rect.center)
body.can_kick = self.pos.distance_to(self.ball.pos) < 30
self.can_kick = body.can_kick
self.can_kick = self.pos.distance_to(self.ball.pos) < 30
self.self_team = []
for player in body.self_team:
......@@ -71,6 +69,8 @@ class Brain():
for player in body.other_team:
self.other_team.append(CupObject(ObjectType.PLAYER, player.rect.center, self.side.other()))
return self.can_kick
def sorted_object(self):
objects = [self.ball, self.self_goal, self.other_goal] + self.self_team + self.other_team
objects.sort(key = lambda agent: self.pos.distance_to(agent.pos))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment