First attempt at a matlab link.
[progcomp10.git] / src / link / MATLAB / matlab-consts.m
1 #
2 # matlab-consts.m
3 # matlab-link
4 #
5 # Created by Daniel Axtens on 28/07/10.
6 # Licensed under an MIT-style license: see the LICENSE file for details.
7 #
8
9 # A collection of useful functions and constants for use in your agent-writing.
10 # Please use the symbolic values (see the sample agents) and don't use hard-coded
11 # values: if we have to change how things are represented internally, for example
12 # to make things run faster, we don't want to suddenly have your agent break.
13 #
14 # For example, use rps.rock to get a rock, don't use 1.
15
16
17 # Define some constants
18 # access these with rps.<whatever>, see the sample agents for examples
19
20 global rps = struct (
21         "rock",         1,
22         "paper",        2,
23         "scissors",     3,
24
25         "itemToString", {{ "Rock", "Paper", "Scissors" }}
26 );
27
28 # Random Item/Attack
29 function item = RandomAttack()
30         global rps
31
32         switch (floor(rand(1)*3))
33         case 0
34                 item = rps.rock;
35         case 1
36                 item = rps.paper;
37         otherwise
38                 item = rps.scissors;
39         endswitch
40 endfunction
41
42
43 function item = stringToItem( itemString )
44         global rps;
45
46         switch itemString
47         case "Rock"
48                 item = rps.rock;
49         case "Scissors"
50                 item = rps.scissors;
51         case "Paper"
52                 item = rps.paper;
53         otherwise
54                 # this shouldn't happen; this is passed by the supervisor, not a user
55                 error( "tried to convert invalid string into Rock/Paper/Scissors!" )
56         endswitch
57
58 endfunction

UCC git Repository :: git.ucc.asn.au