def begin_round(self, team1, team2, state): dist = self.params['dist'][0] ball = Vector2D.create_random(low=-1, high=1) if ball.x < 0. : ball.x = -ball.x aleat = Vector2D.create_random(low=15, high=dist) ball.normalize().scale(aleat.x) ball.y += GAME_HEIGHT/2. # Player and ball postion (random) self.simu.state.states[(2, 0)].position = ball.copy() # Shooter position self.simu.state.states[(2, 0)].vitesse = Vector2D() # Shooter acceleration self.simu.state.ball.position = ball.copy() # Ball position # Last step of the game self.last = self.simu.step # Set the current value for the current parameter for i, (key, values) in zip(self.param_id, self.params.items()): setattr(self.strategy, key, values[i])
def compute_strategy(self, state, player, teamid): pos = state.ball.position - player.position shoot = Vector2D(0, 0) if (PLAYER_RADIUS + BALL_RADIUS) >= (state.ball.position.distance( player.position)): shoot = Vector2D.create_random(-5, 5) teamadverse = 2 if teamid == 2: teamadverse = 1 state.get_goal_center(teamadverse) return SoccerAction(pos, shoot)
def campeur(a): rayon=22 if a.key[0]==2 and a.my_position.x >= settings.GAME_WIDTH/2.5: return SoccerAction(Vector2D(settings.GAME_WIDTH/2.5,settings.GAME_HEIGHT/3)-a.my_position,Vector2D()) else: if a.key[0]==2: a=App(miroir(a.state),a.key[0],a.key[1]) if a.my_position.distance(a.ball_position) <= (settings.BALL_RADIUS+settings.PLAYER_RADIUS)*rayon: return miroir_action(fonceur(a)) else: return SoccerAction(Vector2D.create_random(-1,1),Vector2D()) else: if a.my_position.x <= settings.GAME_WIDTH-settings.GAME_WIDTH/2.5: return SoccerAction(Vector2D(settings.GAME_WIDTH-settings.GAME_WIDTH/2.5,settings.GAME_HEIGHT/3)-a.my_position,Vector2D()) else: if a.my_position.distance(a.ball_position) <= (settings.BALL_RADIUS+settings.PLAYER_RADIUS)*rayon: return fonceur(a) else: return SoccerAction(Vector2D.create_random(-1,1),Vector2D())
def begin_round(self, team1, team2, state): ball = Vector2D.create_random(low=-30, high=30) ball.x += GAME_WIDTH * 8 / 10 ball.y += GAME_HEIGHT / 2 a = Vector2D.create_random(low=-30, high=30) a.x += GAME_WIDTH * 8 / 10 a.y += GAME_HEIGHT / 2 b = Vector2D.create_random(low=-30, high=30) b.x += GAME_WIDTH * 8 / 10 b.y += GAME_HEIGHT / 2 # Player and ball postion ( random ) self.simu.state.states[(1, 0)].position = a # Player position self.simu.state.states[(1, 0)].vitesse = Vector2D() # Player accelerati self.simu.state.ball.position = ball.copy() # Ball position self.simu.state.ball.vitesse = b / 4 self.last_step = self.simu.step # Last step of the game # Set the current value for the current parameters for key, value in self.cur_param.items(): setattr(self.strategy, key, value)
def begin_round(self, team1, team2, state): ball = Vector2D.create_random(low=-1, high=1) if ball.x < 0. : ball.x = -ball.x aleat = Vector2D.create_random(low=25, high=45) ball.normalize().scale(aleat.x) ball.y += GAME_HEIGHT/2. angle = Vector2D.create_random(low=0., high=pi*2.) aleat = Vector2D.create_random(low=5, high=15) fonc = ball + Vector2D(aleat.x*cos(angle.x), aleat.x*sin(angle.x)) # Player and ball postion (random) self.simu.state.states[(2, 0)].position = ball.copy() # Shooter position self.simu.state.states[(2, 0)].vitesse = Vector2D() # Shooter acceleration self.simu.state.states[(1, 0)].position = fonc.copy() # Shooter position self.simu.state.states[(1, 0)].vitesse = Vector2D() # Shooter acceleration self.simu.state.ball.position = ball.copy() # Ball position # Last step of the game self.last = self.simu.step # Set the current value for the current parameter for i, (key, values) in zip(self.param_id, self.params.items()): setattr(self.strategy, key, values[i])
def begin_round(self, team1, team2, state): ball = Vector2D.create_random(low=0, high=1) ball.y = ball.y * settings.GAME_HEIGHT ball.x = ball.x * settings.GAME_WIDTH * ( 3 / 5) + settings.GAME_WIDTH * (3 / 5) self.simu.state.states[(1, 0)].vitesse = Vector2D() # Player accelerati self.simu.state.ball.position = ball.copy() # Ball position self.last_step = self.simu.step self.simu.state.states[(1, 0)].position = self.simu.state.ball.position # Last step of the game # Set the current value for the current parameters for key, value in self.cur_param.items(): setattr(self.strategy, key, value)
def shiftAsideMark(state, opp, distDemar): """ Se decale en s'eloignant de l'adversaire """ dest = None while True: dest = Vector2D.create_random(low=-1, high=1) dest.norm = distDemar dest += opp.position if state.is_valid_position(dest) and \ distance_horizontale(dest, state.my_goal) > distance_horizontale(opp.position, state.my_goal): break return goTo(state, dest)
def begin_round(self, team1, team2, state): ball = Vector2D.create_random(low=0, high=1) ball.x *= GAME_WIDTH ball.y *= GAME_HEIGHT # Player and ball postion ( random ) self.simu.state.states[(1, 0)].position = ball.copy() # Player position self.simu.state.states[(1, 0)].vitesse = Vector2D() # Player accelerati self.simu.state.ball.position = ball.copy() # Ball position # Last step of the game self.last_step = self.simu.step self.last_state = None self.last_score = self.simu.score[1] # Score of Team 1 self.cur_state = self.strategy.get_state(state, id_team=1, id_player=0) self.rewards = []
def begin_round(self, team1, team2, state): ball = Vector2D.create_random(low=0, high=1) ball.x *= GAME_WIDTH / 2 ball.x += GAME_WIDTH / 2 ball.y *= GAME_HEIGHT # Player and ball postion (random) self.simu.state.states[(1, 0)].position = ball.copy() # Player position self.simu.state.states[(1, 0)].vitesse = Vector2D() # Player acceleration self.simu.state.ball.position = ball.copy() # Ball position # Last step of the game self.last = self.simu.step # Set the current value for the current parameter for i, (key, values) in zip(self.param_id, self.params.items()): setattr(self.strategy, key, values[i])
def begin_round(self, team1, team2, state): ball = Vector2D.create_random(low=0, high=1) ball.y *= GAME_HEIGHT #de 100 a 120 ball.x = (GAME_WIDTH - 120) * ball.x ball.x += 90 # Player and ball postion ( random ) self.simu.state.states[(1, 0)].position = ball.copy() # Player position self.simu.state.states[(1, 0)].vitesse = Vector2D() # Player accelerati self.simu.state.ball.position = ball.copy() # Ball position self.last_step = self.simu.step # Last step of the game # Set the current value for the current parameters for key, value in self.cur_param.items(): setattr(self.strategy, key, value)
def begin_round(self, team1, team2, state): x_disc, y_disc = 3, 4 x_step, y_step = GAME_WIDTH * 1. / (2 * x_disc), GAME_HEIGHT * 1. / y_disc case_x, case_y = 0, 2 xmin = GAME_WIDTH / 2. + case_x * x_step ymin = case_y * y_step ball = Vector2D.create_random(low=0, high=1) ball.x = ball.x * x_step + xmin ball.y = ball.y * y_step + ymin # Player and ball postion (random) self.simu.state.states[(1, 0)].position = ball.copy() # Player position self.simu.state.states[(1, 0)].vitesse = Vector2D() # Player acceleration self.simu.state.ball.position = ball.copy() # Ball position # Last step of the game self.last = self.simu.step # Set the current value for the current parameter for i, (key, values) in zip(self.param_id, self.params.items()): setattr(self.strategy, key, values[i])
def get_random_vec(): return Vector2D.create_random(-1,1)
def randomMove(d): # Debug return Vector2D.create_random()
def randomShot(d): # Debug return Vector2D.create_random()
def compute_strategy(self,state,id_team,id_player): return SoccerAction(Vector2D.create_random(-1,1),Vector2D.create_random(-1,1))
def get_random_vector(): """ Renvoie un vecteur a coordonnees aleatoires comprises entre -1 et 1 (exclu) """ return Vector2D.create_random(-1.,1.)
def compute_strategy(self, state, id_team, id_player): mystate = PlayerStateDecorator( state, id_team, id_player) if (mystate.danger(state)): return SoccerAction(acceleration = Vector2D.create_random(low=-1.,high=1.), shoot = Vector2D.create_random(low=-1.,high=1.)) else : return suivre_ball (state, id_team, id_player)
def compute_strategy(self, state, id_team, id_player): return SoccerAction(Vector2D.create_random(-1,1),Vector2D.create_random(-1,1))
def get_random_vec(self, x, y): return Vector2D.create_random(x, y)
def compute_strategy(self, state, id_team, id_player): # id_team is 1 or 2 # id_player starts at 0 return SoccerAction(Vector2D.create_random(), Vector2D.create_random())
# -*- coding: utf-8 -*- import math import pyglet import soccersimulator import numpy as np from soccersimulator import Vector2D, SoccerBattle, SoccerPlayer, SoccerTeam, SoccerStrategy, SoccerAction from soccersimulator import PygletObserver, ConsoleListener, LogListener, PLAYER_RADIUS, BALL_RADIUS u = Vector2D(3, 4) v = Vector2D(1, 2) w = Vector2D.create_random() u + v u - v u.norm acc = Vector2D(1, 2) tir = Vector2D(5, 5) action2 = SoccerAction(acc, tir) vitesse = Vector2D.create_random() tir = Vector2D.create_random() action = SoccerAction(vitesse, tir) class RandomStrategy(SoccerStrategy): def __init__(self): self.name = "Random"
def compute_strategy(self,state,player,teamid): pos = state.ball.position-player.position shoot = Vector2D.create_random(-5,5) return SoccerAction(pos,shoot)
def random (self): return SoccerAction(Vector2D.create_random(-1.,1.), Vector2D.create_random(-1.,1.))
def compute_strategy(self, state, player, teamid): vitesse = Vector2D.create_random(-1, 1) tir = Vector2D.create_random(-1, 1) return SoccerAction(vitesse, tir)
u = Vector2D(1, 3) w = u + v w.norm u.norm u.norm u.x acceleration = Vector2D(1, 3) shoot = Vector2D(10, 10) action = SoccerAction(acceleration, shoot) pos = Vector2D.create_random() shoot = Vector2D.create_random() action = SoccerAction(pos, shoot) from soccersimulator import Vector2D, SoccerBattle, SoccerPlayer, SoccerTeam, SoccerStrategy from soccersimulator import PygletObserver, ConsoleListener, LogListener class RandomStrategy(SoccerStrategy): def __init__(self): self.name = "Random" def start_battle(self, state): pass def finish_battle(self, won):
def compute_strategy(self, state, player, teamid): pos = Vector2D.create_random(-1, 1) shoot = Vector2D.create_random(-1, 1) action = SoccerAction(pos, shoot) return action
def random(mystate): return SoccerAction(Vector2D.create_random()-0.5, Vector2D.create_random())
def compute_strategy(self, state, id_team, id_player): return SoccerAction(acceleration = Vector2D.create_random(low=-1.,high=1.), shoot = Vector2D.create_random(low=-1.,high=1.))
def compute_strategy(self, state, player, teamid): return SoccerAction(Vector2D.create_random(-0.1, 0.1), Vector2D.create_random(-0.1, 0.1))
def compute_strategy(self, state, teamid, player): return SoccerAction(Vector2D.create_random(low=-1.,high=1.), Vector2D.create_random(low=-1.,high=1.))
def compute_strategy(self,state,player,teamid): return SoccerAction(Vector2D.create_random(-0.1,0.1),Vector2D.create_random(-0.1,0.1))
def random(mystate): return SoccerAction(Vector2D.create_random() - 0.5, Vector2D.create_random())
# -*- coding: utf-8 -*- """ Éditeur de Spyder Ce script temporaire est sauvegardé ici : /users/Etu2/3202002/.spyder2/.temp.py """ from soccersimulator import Vector2D, SoccerState, SoccerAction, SoccerStrategy, SoccerBattle, SoccerPlayer, SoccerTeam from soccersimulator import PygletObserver, ConsoleListener, LogListener, pyglet, PLAYER_RADIUS, BALL_RADIUS v = Vector2D() v1 = Vector2D(1, 2) v2 = Vector2D(2, 3) v3 = v1 + v2 v3 += v3 v4 = v3 - v1 v5 = Vector2D.create_random(0, 1) v5.x v5.norm action = SoccerAction(v1, v5) action.shoot action.acceleration action.acceleration.norm class RandomStrategy(SoccerStrategy): def __init__(self): self.name = "Random" def start_battle(self, state): pass