-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.cpp
71 lines (56 loc) · 1.84 KB
/
strategy.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "strategy.h"
#include "game.h"
#define PI 3.14159265
Strategy::Strategy()
{
}
Player *Strategy::init_players()
{
Player *players = new Player[5];
/*
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[0] = Player("R. Ahmadi" , Pos(-6.5,0) , 0);
players[1] = Player("E. Hajisafi", Pos(-2,1) , 1);
players[2] = Player("M. Karimi" , Pos(-5,-2) , 2);
players[3] = Player("M. Navidkia", Pos(-5,2) , 3);
players[4] = Player("H. Aghili" , Pos(-2,-1) , 4);
return players;
}
Triple Strategy::do_turn(Game *game)
{
Triple act;
/*
Write your code here
At the end you have to set 3 parameter:
player id -> act.setPlayerID()
angle -> act.setAngle()
power -> act.setPower()
*/
//Sample code for shooting a random player in the ball direction with the maximum power:
int your_player_Id = rand() % 5;
act.setPlayerID(your_player_Id);
double x1,x2,y1,y2;
x1 = game->get_myTeam()->get_players()[your_player_Id].get_pos().get_x();
y1 = game->get_myTeam()->get_players()[your_player_Id].get_pos().get_y();
x2 = game->get_ball()->get_Position().get_x();
y2 = game->get_ball()->get_Position().get_y();
double radian_angle = abs(atan((double)(y2-y1)/(double)(x2-x1)));//Calculate the angle from the chosen player to the ball
int degree_angle = radian_angle * (180.0/PI) ;
if(x2>x1)
{
if(y2<y1)
degree_angle =360-degree_angle;
}
else
{
if(y2<y1)
degree_angle += 180;
else
degree_angle = 180 - degree_angle;
}
act.setAngle(degree_angle);
act.setPower(100);
return act;
}