Path: utzoo!attcan!uunet!wuarchive!julius.cs.uiuc.edu!rpi!bu.edu!att!iuvax!maytag!watmath!mwnewman From: mwnewman@watmsg.waterloo.edu (mike newman) Newsgroups: comp.lang.forth Subject: Re: How do I do this in FORTH? Message-ID: <1990Oct18.171227.19790@watmath.waterloo.edu> Date: 18 Oct 90 17:12:27 GMT Sender: daemon@watmath.waterloo.edu (Owner of Many System Processes) Organization: University of Waterloo Lines: 60 In-Reply-To: <1450.2719bf62@iccgcc.decnet.ab.com> X-Redirected-From: watmsg.waterloo.edu newsgroups:@watmath In article <1450.2719bf62@iccgcc.decnet.ab.com> you write: > >I'm new to this news group and I'm also relatively new at writing >non-trivial Forth programs. I have written a 3-D Tic-Tac-Toe playing >program in 'c' which I am now trying to convert to Forth. All has >been going smoothly so far until attempting to write the minimax >routine in Forth. Intereseting you should mention this. I'm doing exactly the same thing with an othello playing program. I haven't gotten very far, as I only last week found a un*x forth to run. The way I think I'll handle it is to define a seperate stack for alpha, beta, depth. Set it up analogously to the return stack, ie: define words like alpha-pop, alpha-push, alpha@ <==> r>, >r, r@ something like: variable alpha-stack 100 allot variable alpha-pointer alpha-stack alpha-pointer ! ( stack growing upwards - why not ? ) : alpha-pop alpha-stack @ 4 ( or 2 for 16-bit forths ) alpha-pointer -! ; : alpha-push 4 alpha-pointer +! alpha-stack ! ; : alpha@ alpha-stack @ ; : alpha-drop 4 alpha-pointer -! ; Now this looks like it might involve a lot of overhead, BUT: code these in assembly language. The only overhead is fetching and storing the stack pointers. And you could even keep these stack pointers in registers and kill that little bit of overhead too. code alpha-pop move alpha-pointer,r0 move (r0)+,-(sp) move r0,alpha-pointer c; better yet: (better for speed...) code alpha-pop move (r57)+,-(sp) ; r57 is reserved for alpha stack-pointer c; Note that this last is likely faster (depending on the machine) then a normal variable "@", or a frame pointer approach, since you don't have any literal offset to deal with. Of course this assumes that there are free registers, that are not being used by anything else. Then again, depending on the machine, the first may reduce to a single instruction too. I can't think of any other efficient way to do this, but then I often can't think of what day it is today :-) Hope this helps. I'd be interested in hearing about any other suggestions you get. mike newman mwnewman@msg.waterloo.edu