Path: csiph.com!weretis.net!feeder9.news.weretis.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!local-3.nntp.ord.giganews.com!local-2.nntp.ord.giganews.com!Xl.tags.giganews.com!local-4.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 08 Aug 2026 05:35:37 +0000 Followup-To: comp.lang.c From: steve g Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: Tic Tac Toe Quest References: <114cqjo$rh2p$2@raubtier-asyl.eternal-september.org> <114cqrq$rjmv$1@dont-email.me> <114crl1$rt8j$1@raubtier-asyl.eternal-september.org> <114hep7$203s$1@nnrp.usenet.blueworldhosting.com> <114i3ui$2mvma$1@raubtier-asyl.eternal-september.org> <114j66g$256i$1@nnrp.usenet.blueworldhosting.com> Date: Sat, 08 Aug 2026 01:35:27 -0400 Message-ID: <87h5l5i38g.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:1t5W/LgMWOkuME1bK0xZ4Bj7ju8= MIME-Version: 1.0 Content-Type: text/plain Lines: 80 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-gSKCj2T5KEgkWRl0HqHsd9P9MCPrMY0O7HQazlgfMCXrfaIKrNIIT5Oatz598gKVh2guhMqpN83mEey!SQ0zz68ZAZg2ZJ0li7kwWPkrEAbsMTU41wMMsFE6Q4lTBjI= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Xref: csiph.com comp.lang.c++:124606 comp.lang.c:400927 R Kym Horsell writes: > OK. It took a while to get an 8" floppy drive working to find > the code but this is the way we did it in 1979: > > Reading it again it's very much in the line of what the kids these > days call a "prompt". > > main :- assert(games(0)), assert(draws(0)), > play(Winner,Moves,FinalBoard), > inc_games, > (Winner=draw -> inc_draws), > fail %%% force it to try all possibilities (above) trying to succeed > > ; games(Games),writeln(Games), > draws(Draws),writeln(Draws) > . > > %% x goes first > %% 1222560 > %% 362880 > > play(Winner,G,B) :- > empboard(B), InitEmp=[1,2,3,4,5,6,7,8,9], > %% player(First), > First=x, > game(First,B,G,InitEmp,FinalEmp), > ( player(Winner),won(Winner,B) > ; Winner=draw, FinalEmp=[] > ) > . > > game(_,_,[]) --> []. %% return short solutions first > game(Me,B,[M|Ms]) --> select(M), > { updboard(Me,B,M), opponent(Me,You) }, > game(You,B,Ms). > > updboard(Who,B,M) :- arg(M,B,Sq), empty(Sq), Sq=Who. > > won(Who,B) :- hasrow(Who,B) > ; hascol(Who,B) > ; hasdiag(Who,B) > . > > %% 1 2 3 > %% 4 5 6 > %% 7 8 9 > > hasrow(Who,B) :- checksqs([1,2,3],Who,B) > ; checksqs([4,5,6],Who,B) > ; checksqs([7,8,9],Who,B) > . > > hascol(Who,B) :- checksqs([1,4,7],Who,B) > ; checksqs([2,5,8],Who,B) > ; checksqs([3,6,9],Who,B) > . > > hasdiag(Who,B) :- checksqs([1,5,9],Who,B) > ; checksqs([3,5,7],Who,B) > . > > checksqs([],_,_). > checksqs([I|Is],Who,B) :- arg(I,B,Sq), Sq == Who, checksqs(Is,Who,B). > > empboard(B) :- functor(B,board,9). > > empty(Sq) :- var(Sq). > > player(Who) :- opponent(Who,_). > > opponent(x,0). > opponent(0,x). > > inc_games :- retract(games(X)),X1 is X+1,assert(games(X1)). > > inc_draws :- retract(draws(X)),X1 is X+1,assert(draws(X1)). some beautiful code. I wish I still had my cassette tapes..