%tchukarumaRealTREE.m %state is the vector with all possible game states %temp is the character string that you need to paste into maple %in order to run this program type something like %[a,b]=tchukarumaRealTREE % a will then contain all of the states and b the stuff to paste into maple %I think the main command you need to change below is play function [state,terminal]=unplay_tree() bins = input('Please enter the number of bins, excluding the ruma.'); stones = input('Please enter the max number of stones'); alph=char(97*ones(10000,1)); %works for all a's fid=fopen('output.mpl','w'); state=zeros(1,bins); state(1,end)=stones; terminal(1)=1; nummoves(1)=1; gamelevel = 1; veclevel=1; fprintf(fid,'with(graphtheory):\nb:=Graph(undirected,{'); temp2='c:=Graph(undirected,{ '; while(gamelevel<=veclevel && veclevel<2000) if(veclevel>=2) fprintf(fid,','); end [new_states,new_choices]=unplay(state(gamelevel,:)); state=[state;new_states]; fprintf(fid,strcat('{',num2str(gamelevel),',',num2str(length(state)),'}')); [veclevel,len]=size(state); gamelevel=gamelevel+1; end fprintf(fid,'});\n'); fprintf(fid,strcat(temp2,'});\nDrawGraph(b,style=tree);\n')); fprintf(fid,'DrawGraph(c,style=circle);\n'); function str=vec2str(v) str=''; for i=1:length(v) str=strcat(str,num2str(v(i))); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [answers,choices] = unplay(state) original_state=state; paths=[]; %Counting the number of possible paths x=1; for i=1:length(state) if(state(i)>0) paths(x)=i; x=x+1; end end choices=zeros(0,1); answers=zeros(0,length(state)); x=1; for i=1:length(paths) collection=0; pos=paths(i); while(state(pos)~=0) state(pos)=state(pos)-1; collection=collection+1; if(pos>1) pos=pos-1; else pos=length(state); end end % The ruma is not a valid option if(pos~=length(state)) state(pos)=collection; answers(x,:)=state; choices(x)=pos; x=x+1; end state=original_state; end end end