-
Notifications
You must be signed in to change notification settings - Fork 0
/
Strategy.py
54 lines (43 loc) · 1.52 KB
/
Strategy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import math
import random
from client import *
def init_players():
'''
Here you can set each of your player's name and your team formation.
In case of setting wrong position, server will set default formation for your team.
'''
players = [Player(name="player_1", first_pos=Pos(-6.5, 0)),
Player(name="player_2", first_pos=Pos(-2, 1)),
Player(name="player_3", first_pos=Pos(-5, -2)),
Player(name="player_4", first_pos=Pos(-5, 2)),
Player(name="player_5", first_pos=Pos(-2, -1))]
return players
def do_turn(game):
act = Triple()
'''
Write your code here
At the end you have to set 3 parameter:
player id -> act.setPlyerID()
angle -> act.setAngle()
power -> act.setPower()
'''
# Sample code for shooting a random player in the ball direction with the maximum power:
player_id = random.randint(0, 4)
act.setPlayerID(player_id)
x1 = game.getMyTeam().getPlayer(player_id).getPosition().getX()
y1 = game.getMyTeam().getPlayer(player_id).getPosition().getY()
x2 = game.getBall().getPosition().getX()
y2 = game.getBall().getPosition().getY()
angle = math.fabs(math.degrees(math.atan((y2 - y1) / (x2 - x1))))
# Calculate the angle from the chosen player to the ball
if x2 > x1:
if y2 < y1:
angle = 360 - angle
else:
if y2 < y1:
angle += 180
else:
angle = 180 - angle
act.setAngle(angle)
act.setPower(100)
return act