-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathRandomAgent.m
More file actions
52 lines (44 loc) · 1.46 KB
/
Copy pathRandomAgent.m
File metadata and controls
52 lines (44 loc) · 1.46 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
classdef RandomAgent < handle
%RandomAgent Plays 2048 with random moves.
properties (Constant)
rows = 4;
cols = 4;
actions = 4;
action_labels = {'UP', 'RIGHT', 'DOWN', 'LEFT'};
end
properties
game;
end
methods
function this = RandomAgent()
this.game = Game(this.rows, this.cols);
end
function results = play(this, nr_games)
% PLAY Play 2048 game by making random moves.
% Parameters:
% nr_games - number of games to play. If 1, then also displays debug info.
% Returns scores in those games as a vector.
% play nr_games
for i = (1:nr_games)
% initialize game field
this.game.new();
results(i) = 0;
if (nr_games == 1)
disp(this.game.state);
end
% play till end
while (~this.game.end())
% choose random action
action = randi(this.actions);
% make a move and observe reward
points = this.game.move(action);
results(i) = results(i) + points;
if (nr_games == 1)
disp(this.action_labels{action});
disp(this.game.state);
end
end
end
end
end
end