%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=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; %alph=['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a']; alph=char(97*ones(10000,1)); %works for all a's fid=fopen('output.mpl','w'); state=zeros(1,bins); for x=1:bins state(1,x)=input('how many in this bin?'); end terminal(1)=1; binnum=1; nummoves(1)=1; gamelevel = 1; veclevel=2; chain(1)=0; chaining=0; fprintf(fid,'with(graphtheory):\nb:=Graph(undirected,{'); temp2='c:=Graph(undirected,{'; going=1; while(going && veclevel<2000 && sum(state(veclevel))<=stones) if(chain(gamelevel)~=0) chaining=1; binnum=chain(gamelevel); end if(state(gamelevel,binnum)~=0 && terminal(gamelevel)~=0) %[state(veclevel,:),terminal(veclevel),chain(veclevel)]=play(binnum,state(gamelevel,:),bins); [new_states,new_choices]=unplay(state(gamelevel,:)); state=[state;new_states]; %choices=[choices;new_choices]; nummoves(veclevel)=nummoves(gamelevel)+1; binvec(veclevel)=binnum; if(veclevel==2) temp2=strcat(temp2,'[',alph(nummoves(gamelevel)),vec2str(state(gamelevel,:)),',',alph(nummoves(veclevel)),vec2str(state(veclevel,:)),']'); else temp2=strcat(temp2,',[',alph(nummoves(gamelevel)),vec2str(state(gamelevel,:)),',',alph(nummoves(veclevel)),vec2str(state(veclevel,:)),']'); end if(veclevel~=2) fprintf(fid,','); end fprintf(fid,strcat(',{',num2str(gamelevel),',',num2str(veclevel),'}')); veclevel=veclevel+1; end gamelevel=gamelevel+size(new_states); if(gamelevel+1>veclevel) going=0; end state 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)>1) paths(x)=i; x=x+1; end end fprintf('counted paths'); % Here is the meat: % This is the unplay for tchukaruma choices=zeros(length(paths),1); answers=zeros(length(paths),length(state)); 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(i,:)=state; choices(i)=pos; end state=original_state; end end end