X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Flink%2FMATLAB%2Fmatlab-consts.m;fp=src%2Flink%2FMATLAB%2Fmatlab-consts.m;h=5b3b3a615dc7801d45161eaa5974d2c0f50a0985;hb=9ff4794ed54c3dfddf56117268d8e85c77d70cd6;hp=0000000000000000000000000000000000000000;hpb=f3b1a5c26bb9362a9cd507a5d749df98231d5463;p=progcomp10.git diff --git a/src/link/MATLAB/matlab-consts.m b/src/link/MATLAB/matlab-consts.m new file mode 100644 index 0000000..5b3b3a6 --- /dev/null +++ b/src/link/MATLAB/matlab-consts.m @@ -0,0 +1,58 @@ +# +# matlab-consts.m +# matlab-link +# +# Created by Daniel Axtens on 28/07/10. +# Licensed under an MIT-style license: see the LICENSE file for details. +# + +# A collection of useful functions and constants for use in your agent-writing. +# Please use the symbolic values (see the sample agents) and don't use hard-coded +# values: if we have to change how things are represented internally, for example +# to make things run faster, we don't want to suddenly have your agent break. +# +# For example, use rps.rock to get a rock, don't use 1. + + +# Define some constants +# access these with rps., see the sample agents for examples + +global rps = struct ( + "rock", 1, + "paper", 2, + "scissors", 3, + + "itemToString", {{ "Rock", "Paper", "Scissors" }} +); + +# Random Item/Attack +function item = RandomAttack() + global rps + + switch (floor(rand(1)*3)) + case 0 + item = rps.rock; + case 1 + item = rps.paper; + otherwise + item = rps.scissors; + endswitch +endfunction + + +function item = stringToItem( itemString ) + global rps; + + switch itemString + case "Rock" + item = rps.rock; + case "Scissors" + item = rps.scissors; + case "Paper" + item = rps.paper; + otherwise + # this shouldn't happen; this is passed by the supervisor, not a user + error( "tried to convert invalid string into Rock/Paper/Scissors!" ) + endswitch + +endfunction