-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowGame.m
More file actions
79 lines (64 loc) · 3.12 KB
/
showGame.m
File metadata and controls
79 lines (64 loc) · 3.12 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
77
78
79
%% This a function of embed Graphical engine used optionally in simulator D2DSS
% It is responsable for plotting variable graphicals structures of soccer game
% Score, iteration time, labels, ball position, players position of game simulation
% with aspects defined for parameters from State, setSimulator[SimulatorCore], setGame[J]
% function showGame( S, M, J )
%%
function showGame( S, M, J )
pause(M.delay);
clf;
%Field personalization
subplot(10,5,[6,50]);
axis on;grid on;
xlim([0 M.Nx*M.cellWidth]);
ylim([0 M.Ny*M.cellWidth]);
set(gca,'XTick',M.cellWidth:M.cellWidth:M.Nx*M.cellWidth);
set(gca,'YTick',M.cellWidth:M.cellWidth:M.Ny*M.cellWidth);
set(gca, 'XTickLabelMode', 'manual', 'XTickLabel', []);
set(gca, 'YTickLabelMode', 'manual', 'YTickLabel', []);
%Colorizing
field=rectangle('position',[(0)*M.cellWidth+.0 (0)*M.cellWidth+.0 (M.cellWidth*M.Nx) (M.cellWidth*M.Ny)],'LineWidth',.1);
set(field,'FaceColor',[0.0,1.0,0.0]);
%Goals areas
golA=rectangle('position',[0 (floor(M.Ny/2)*M.cellWidth-M.cellWidth*M.goalWidth) M.cellWidth M.cellWidth*(M.goalWidth*2+1)],'LineWidth',2);
set(golA,'FaceColor',[0.8,0.8,0.8]);
golB=rectangle('position',[M.Nx*M.cellWidth-M.cellWidth (floor(M.Ny/2)*M.cellWidth-M.cellWidth*M.goalWidth) M.cellWidth M.cellWidth*(M.goalWidth*2+1)],'LineWidth',2);
set(golB,'FaceColor',[0.4,0.4,0.4]);
%Players of team A
if(M.Ta>0)
for i=1:M.Ta
player=rectangle('position',[(S.P{i}.x-1)*M.cellWidth+.5 (S.P{i}.y-1)*M.cellWidth+.5 (M.cellWidth-1) (M.cellWidth-1)],'LineWidth',.1);
set(player,'FaceColor',[0.7,0.7,0.7]);
text((S.P{i}.x-1)*M.cellWidth+1,(S.P{i}.y-1)*M.cellWidth+1,num2str(i));
end
end
%Players of team B
if (M.Tb>0)
for i=M.Ta+1:M.Ta+M.Tb
player=rectangle('position',[(S.P{i}.x-1)*M.cellWidth+.5 (S.P{i}.y-1)*M.cellWidth+.5 (M.cellWidth-1) (M.cellWidth-1)],'LineWidth',.1);
set(player,'FaceColor',[0.3,0.3,0.3]);
text((S.P{i}.x-1)*M.cellWidth+1,(S.P{i}.y-1)*M.cellWidth+1,num2str(i));
end
end
ball=rectangle('position',[(S.B.x-1)*M.cellWidth+1 (S.B.y-1)*M.cellWidth+1 (M.cellWidth-2) (M.cellWidth-2)],'LineWidth',.1);
set(ball,'FaceColor',[1,1,1]);
%Central circle
hold on;
numPoints=100;
radius=M.cellWidth*1;
theta=linspace(0,5*pi,numPoints);
rho=ones(1,numPoints)*radius;
[X,Y] = pol2cart(theta,rho); %circular function
plot(X+M.Nx/2*M.cellWidth,Y+M.Ny/2*M.cellWidth,'k-','linewidth',2);
%Central mid line
line([M.Nx/2*M.cellWidth,M.Nx/2*M.cellWidth],[0,M.Ny*M.cellWidth],'Color','k');
%Labels for naming, score and time
subplot(10,5,[1,5]);
axis off;
titulo='D2DSS - Discrete 2D Soccer Simulator';
placar = ['Score: \color[rgb]{0.7,0.7,0.7}{\bullet}Ta \color{black}',num2str(J.scoreA),'X', num2str(J.scoreB) , '\color[rgb]{0.3,0.3,0.3}{\bullet}Tb\color{black}',' | ',num2str(J.timer),' Iteration'];
text(0,1,titulo,'FontSize',15);
text(0,0,placar,'FontSize',14);
set(gcf, 'color', [1 1 1])
hold off;
end