Starting with the tic-tac-toe program of Figure 12.4, draw a directed acyclic graph in which every clause is a node and an arc from A to B indicates that it is important, either for correctness or efficiency, that A come before B in the program. (Do not draw any other arcs.) Any topological sort of your graph should constitute an equally efficient version of the program. (Is the existing program one of them?)
Starting with the tic-tac-toe program of Figure 12.4, draw a directed acyclic graph in which every clause is a node and an arc from A to B indicates that it is important, either for correctness or efficiency, that A come before B in the program. (Do not draw any other arcs.) Any topological sort of your graph should constitute an equally efficient version of the program. (Is the existing program one of them?)
Related questions
Question
Starting with the tic-tac-toe program of Figure 12.4, draw a directed acyclic graph in which every clause is a node and an arc from A to B indicates that it is important, either for correctness or efficiency, that A come before B in the program. (Do not draw any other arcs.) Any topological sort of your graph should constitute an equally efficient version of the program. (Is the existing program one of them?)

Transcribed Image Text:ordered line(1, 2, 3). ordered 1ine (4,5, 6). ordered_line (7,8,9).
ordered line(1,4,7). ordered_line (2, 5, 8). ordered line (3, 6,9).
ordered line(1, 5,9). ordered 1ine (3, 5, 7).
line (A, B, C) :- ordered_lino(A, B, C). lino(A, B, C) :- ordored_line (A, C, B).
line (A, B, C) :- ordered lino (B, A,C). lino(A, B, c) :- ordered_line (B, C, A).
line (A, B, C) :- ordered lino (C, A, B). lino(A, B, c) :- ordered_line (C, B, A).
full (A) :- x(A). full (A) :- o(A). empty(A) :- (full(A)).
% MB: empty must be called vith an already-instantiated A.
same (A, A). different (A, B) :- +(sane (A, B)).
move (A) :- good (A), empty (A), !.
% stratogy:
good (A) :- win(A).
good (A) :- strong build(A).
good (5). good (1). good (3). good(7). good (9). good(2). good (4). good(6). good (8).
good(A) :- block_win(A).
good(A) :- voak build(A).
good (A) :- split(A).
vin(A) :- 1(B). x(C), line(A, B, C).
block vin (A) :- o(B), o(C), 1ine(A, B, C).
яplit (4) :- 1(В) . х (С). dafferant (B, C). 1ina(А, В. D). 11па(А, С. Е). спрty D). спpty (E).
strong build(A) :- 1(B), line(A, B.C), anpty(C). (risky(C)).
veak_build(A) :- 1(B), line(A, B, C). ampty(C). v(double_risky (C)).
risky (C) :- o(D). line (C, D, E). capty (E).
double_risky(C) :- o(D). o(E). different (D. E). line (C, D, F). line(C, E, G), ampty (F). ampty (G).
all_full :- full(1), full(2). full(3), full(4), full(5).
full(6), full(7). full(8), full(9).
done :- ordered_line (A, B, C), 1(A), x(B), x(C), write('I von.'), nl.
done :- all_full, write('Draw. '). al.
getaove :- repeat, vrite('Please enter a nove: '), read(X), empty(X), assert(o(X)).
makenove :- nove (X), !, assert(x(X)).
makenove :- al1_full.
printsquare (N) :- o(N), write(' o ').
printsquare (N) :- x(N), write(' x ').
printsquare (N) :- empty (N), write('
printboard :- printsquare (1), printsquare(2). printsquare (3), nl,
').
printsquare (4), printsquare (5), printsquare (6), nl,
printsquare(7), printsquare(8), printsquare (9), nl.
clar :- retractall(x()), retractall(o()).
% main goal:
play :- clear, repeat, getaove, respond.
respond :- ordered_line(A, B, C). o(A). o(B). o(C).
printboard, vrite('You won. '). nl.
% shouldn' t evar happan!
respond :- nakonove, printboard, dona.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 1 images
