-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdatePlayer.m
More file actions
79 lines (63 loc) · 2.88 KB
/
Copy pathUpdatePlayer.m
File metadata and controls
79 lines (63 loc) · 2.88 KB
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
72
73
74
75
76
function [updatedPlayer, updatedBall] = UpdatePlayer(players, ball, indexOfPlayer, timeDelta, playerOriginalPosition)
% Updates the player state and ball state by action rules
% This is the function we can replace with different variants for
% comparing different players
global lastTeamOnBall;
nAttributes = size(players{3},2);
updatedPlayer = {[0 0],[1 0],players{3}};
nPlayers=length(players{1});
kickBallSigma = 1/200;
passBallSigma = 1/200;
kickBallAcceleration = 1;
passBallAcceleration = 1;
shootBallCoefficient=9;
passBallCoefficient=0.2;
moveForwardCoefficient=0.5;
markedDistance=12; %10-15 seems optimal
kickBallProbabilityCoefficient=25;
actionBallDistance = 1.5;
actionPlayerDistance = 36;
actionGoalDistance = 30;
%fieldWidth=90;
%nPlayers=size(players{1},1);
playerTeam=players{3}(indexOfPlayer);
if playerTeam==0
goalPosition = [+60 0];%60 0
else
goalPosition = [-60 0];
end
kickBallLikelihood = 0.0;
passBallLikelihood = 0.5;
doNothingWithBallLikelihood = 0.5;
sumOfLikelihoods = kickBallLikelihood + passBallLikelihood + doNothingWithBallLikelihood;
if sumOfLikelihoods ~= 1
ME = MException('The sum of the likelyhoods has to equal 1. They are currently summed to %s',sumOfLikelihoods);
throw(ME)
end
playerPosition = players{1}(indexOfPlayer,:);
ballPosition = ball(1,:);
distanceToBall = sqrt((ballPosition(1) - playerPosition(1))^2 + (ballPosition(2) - playerPosition(2))^2);
distanceToGoal = sqrt((goalPosition(1) - playerPosition(1)).^2 + (goalPosition(2) - playerPosition(2)).^2);
if distanceToBall < actionBallDistance
lastTeamOnBall=playerTeam;
kickBallLikelihood=exp(-distanceToGoal/kickBallProbabilityCoefficient);
whatTodo = rand();
kickLikeRange = kickBallLikelihood;
passLikeRange = kickBallLikelihood + passBallLikelihood;
if whatTodo <= kickLikeRange || distanceToGoal < actionGoalDistance
targetPosition = goalPosition;
ball = KickBall(ball, kickBallSigma, shootBallCoefficient, kickBallAcceleration, targetPosition, timeDelta);
elseif IsMarked(players,indexOfPlayer,playerTeam,markedDistance) || mod(indexOfPlayer,nPlayers/2)==0 %pass if you are the goalie
targetPosition = ChoosePlayerToPass(players,indexOfPlayer,markedDistance);
ball = PassBall(ball, passBallSigma, passBallCoefficient, passBallAcceleration, targetPosition, timeDelta);
else % I am not marked and can go forward with the ball
targetPosition = [goalPosition(1)+sign(playerTeam-1/2) players{1}(indexOfPlayer,2)];
ball = KickBall(ball, kickBallSigma, moveForwardCoefficient, kickBallAcceleration, targetPosition, timeDelta);
end
end
updatedBall = ball;
updatedPlayer = Move(players, indexOfPlayer, updatedBall, timeDelta, playerOriginalPosition);
end
% NOTE: To make sure that the only file that we need to change to compare
% different PlayerAction.m files make sure to put all your helpfiles inside
% this function.