% -*- prolog -*-
%
%
%%%%%

black(black).
white(white).
blank(space).


% flip_disc/2  (exported)
% flip_disc(?Self, ?Opponent)

flip_disc(black, white).
flip_disc(white, black).

% count_discs_diff/4  (exported)
% count_discs_diff(+Board, +Self, +Opponent, ?Diff)
% Board にある Self の石の個数から Opponent の石の個数を引いた差を求める。

count_discs_diff(Board, Self, Opponent, Diff) :-
	count_discs_diff(Board, Self, Opponent, 0, Diff), !.

% count_discs_diff/5
% count_discs_diff(+Board, +Self, +Opponent, +Diff_now, ?Diff)
%   count_discs_diff/4 の下請け。

count_discs_diff([], _, _, Diff, Diff).
count_discs_diff([[]|Rows], Self, Opponent, Diff_now, Diff) :-
	count_discs_diff(Rows, Self, Opponent, Diff_now, Diff).

count_discs_diff([[Self|Cells]|Rows], Self, Opponent, Diff_now, Diff) :-
	!,
	Diff1 is Diff_now + 1,
	count_discs_diff([Cells|Rows], Self, Opponent, Diff1, Diff).
count_discs_diff([[Opponent|Cells]|Rows], Self, Opponent, Diff_now, Diff) :-
	!,
	Diff1 is Diff_now - 1,
	count_discs_diff([Cells|Rows], Self, Opponent, Diff1, Diff).

count_discs_diff([[space|Cells]|Rows], Self, Opponent, Diff_now, Diff) :-
	count_discs_diff([Cells|Rows], Self, Opponent, Diff_now, Diff).

count_stones_sub2([], _, N, N).
count_stones_sub2([Stone|Cells], Stone, N1, N3) :-
    !,
    N2 is N1 + 1,
    count_stones_sub2(Cells, Stone, N2, N3).
count_stones_sub2([_|Cells], Stone, N1, N2) :-
    count_stones_sub2(Cells, Stone, N1, N2).

count_stones_sub1([], _, N, N).
count_stones_sub1([Line|Lines], Stone, N1, N4) :-
    count_stones_sub2(Line, Stone, 0, N2),
    N3 is N1 + N2,
    count_stones_sub1(Lines, Stone, N3, N4).

count_stones(Board, Stone, N) :-
    count_stones_sub1(Board, Stone, 0, N).

% flip_line/4
% flip_line(?Self, ?Opponent, ?Line, ?Line1)
%   列 Line で石を返した後の列が Line1 である。
%   石を返せなければ fail する。

flip_line(Self, Opponent, [Opponent|Line], [Self|Line1]) :-
	flip_line1(Self, Opponent, Line, Line1).
flip_line1(Self, _, [Self|Line], [Self|Line]).
flip_line1(Self, Opponent, [Opponent|Line], [Self|Line1]) :-
	flip_line1(Self, Opponent, Line, Line1).

% flip_line_if_possible/5
% flip_line_if_possible(+Self, +Opponent, +Line, ?Line1, ?Flipped)
%   列 Line で石を返せれば、返した後の列を Line1 に bind し、
%   Flipped を true にバインドする。
%   石を返せなければ Line をそのまま Line1 に bind する。 Flipped はそのまま。

flip_line_if_possible(Self, Opponent, Line, Line1, Flipped) :-
	( flip_line(Self, Opponent, Line, Line2)
	  ->
	  Flipped = true,
	  Line1 = Line2
	  ;
	  Line = Line1 ).

% place_disc/6  (exported)
% place_disc(?I, ?J, +Self, +Opponent, +Board, ?Board1)
%   盤 Board でマス (I, J) に石を打つと盤 Board1 になる。
%   打てない場合は fail する。

place_disc(1, J, Self, Opponent, Board, Board1) :-
	place_sub1(J, Self, Opponent, Board, Board1).
place_disc(2, J, Self, Opponent, Board, Board1) :-
	place_sub2(J, Self, Opponent, Board, Board1).
place_disc(3, J, Self, Opponent, Board, Board1) :-
	place_sub3(J, Self, Opponent, Board, Board1).
place_disc(4, J, Self, Opponent, Board, Board1) :-
	place_sub4(J, Self, Opponent, Board, Board1).
place_disc(5, J, Self, Opponent, Board, Board1) :-
	place_sub5(J, Self, Opponent, Board, Board1).
place_disc(6, J, Self, Opponent, Board, Board1) :-
	place_sub6(J, Self, Opponent, Board, Board1).
place_disc(7, J, Self, Opponent, Board, Board1) :-
	place_sub7(J, Self, Opponent, Board, Board1).
place_disc(8, J, Self, Opponent, Board, Board1) :-
	place_sub8(J, Self, Opponent, Board, Board1).

% place_sub1/5, place_sub2/5, ..., place_sub8/5
% place_subI(?J, +Self, +Opponent, +Board, ?Board1)  (I = 1,2,...,8)
%   盤 Board でマス (I, J) に石を打つと盤 Board1 になる。
%   打てない場合は fail する。

place_sub1(1, Self, Opponent,
	[[space, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22|Cs2],
	 [C13, C23, C33|Cs3],
	 [C14, C24, C34, C44|Cs4],
	 [C15, C25, C35, C45, C55|Cs5],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[Self, D21, D31, D41, D51, D61, D71, D81],
	 [D12, D22|Cs2],
	 [D13, C23, D33|Cs3],
	 [D14, C24, C34, D44|Cs4],
	 [D15, C25, C35, C45, D55|Cs5],
	 [D16, C26, C36, C46, C56, D66|Cs6],
	 [D17, C27, C37, C47, C57, C67, D77|Cs7],
	 [D18, C28, C38, C48, C58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C22, C33, C44, C55, C66, C77, C88],
			      [D22, D33, D44, D55, D66, D77, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C21, C31, C41, C51, C61, C71, C81],
			      [D21, D31, D41, D51, D61, D71, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C12, C13, C14, C15, C16, C17, C18],
			      [D12, D13, D14, D15, D16, D17, D18], Flipped),
	Flipped == true.
place_sub1(2, Self, Opponent,
	[Cs1,
	 [space, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23|Cs3],
	 [C14, C24, C34|Cs4],
	 [C15, C25, C35, C45|Cs5],
	 [C16, C26, C36, C46, C56|Cs6],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[Cs1,
	 [Self, D22, D32, D42, D52, D62, D72, D82],
	 [D13, D23|Cs3],
	 [D14, C24, D34|Cs4],
	 [D15, C25, C35, D45|Cs5],
	 [D16, C26, C36, C46, D56|Cs6],
	 [D17, C27, C37, C47, C57, D67|Cs7],
	 [D18, C28, C38, C48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C23, C34, C45, C56, C67, C78],
			      [D23, D34, D45, D56, D67, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C22, C32, C42, C52, C62, C72, C82],
			      [D22, D32, D42, D52, D62, D72, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C13, C14, C15, C16, C17, C18],
			      [D13, D14, D15, D16, D17, D18], Flipped),
	Flipped == true.
place_sub1(3, Self, Opponent,
	[[C11, C21, C31|Cs1],
	 [C12, C22|Cs2],
	 [space, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24|Cs4],
	 [C15, C25, C35|Cs5],
	 [C16, C26, C36, C46|Cs6],
	 [C17, C27, C37, C47, C57|Cs7],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[[D11, C21, D31|Cs1],
	 [D12, D22|Cs2],
	 [Self, D23, D33, D43, D53, D63, D73, D83],
	 [D14, D24|Cs4],
	 [D15, C25, D35|Cs5],
	 [D16, C26, C36, D46|Cs6],
	 [D17, C27, C37, C47, D57|Cs7],
	 [D18, C28, C38, C48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C24, C35, C46, C57, C68],
			      [D24, D35, D46, D57, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C23, C33, C43, C53, C63, C73, C83],
			      [D23, D33, D43, D53, D63, D73, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C22, C31],
			      [D22, D31], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C14, C15, C16, C17, C18],
			      [D14, D15, D16, D17, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C12, C11],
			      [D12, D11], Flipped),
	Flipped == true.
place_sub1(4, Self, Opponent,
	[[C11, C21, C31, C41|Cs1],
	 [C12, C22, C32|Cs2],
	 [C13, C23|Cs3],
	 [space, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25|Cs5],
	 [C16, C26, C36|Cs6],
	 [C17, C27, C37, C47|Cs7],
	 [C18, C28, C38, C48, C58|Cs8]],
	[[D11, C21, C31, D41|Cs1],
	 [D12, C22, D32|Cs2],
	 [D13, D23|Cs3],
	 [Self, D24, D34, D44, D54, D64, D74, D84],
	 [D15, D25|Cs5],
	 [D16, C26, D36|Cs6],
	 [D17, C27, C37, D47|Cs7],
	 [D18, C28, C38, C48, D58|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C25, C36, C47, C58],
			      [D25, D36, D47, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C24, C34, C44, C54, C64, C74, C84],
			      [D24, D34, D44, D54, D64, D74, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C23, C32, C41],
			      [D23, D32, D41], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C15, C16, C17, C18],
			      [D15, D16, D17, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C13, C12, C11],
			      [D13, D12, D11], Flipped),
	Flipped == true.
place_sub1(5, Self, Opponent,
	[[C11, C21, C31, C41, C51|Cs1],
	 [C12, C22, C32, C42|Cs2],
	 [C13, C23, C33|Cs3],
	 [C14, C24|Cs4],
	 [space, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26|Cs6],
	 [C17, C27, C37|Cs7],
	 [C18, C28, C38, C48|Cs8]],
	[[D11, C21, C31, C41, D51|Cs1],
	 [D12, C22, C32, D42|Cs2],
	 [D13, C23, D33|Cs3],
	 [D14, D24|Cs4],
	 [Self, D25, D35, D45, D55, D65, D75, D85],
	 [D16, D26|Cs6],
	 [D17, C27, D37|Cs7],
	 [D18, C28, C38, D48|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C26, C37, C48],
			      [D26, D37, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C25, C35, C45, C55, C65, C75, C85],
			      [D25, D35, D45, D55, D65, D75, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C24, C33, C42, C51],
			      [D24, D33, D42, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C16, C17, C18],
			      [D16, D17, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C14, C13, C12, C11],
			      [D14, D13, D12, D11], Flipped),
	Flipped == true.
place_sub1(6, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52|Cs2],
	 [C13, C23, C33, C43|Cs3],
	 [C14, C24, C34|Cs4],
	 [C15, C25|Cs5],
	 [space, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27|Cs7],
	 [C18, C28, C38|Cs8]],
	[[D11, C21, C31, C41, C51, D61|Cs1],
	 [D12, C22, C32, C42, D52|Cs2],
	 [D13, C23, C33, D43|Cs3],
	 [D14, C24, D34|Cs4],
	 [D15, D25|Cs5],
	 [Self, D26, D36, D46, D56, D66, D76, D86],
	 [D17, D27|Cs7],
	 [D18, C28, D38|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C27, C38],
			      [D27, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C26, C36, C46, C56, C66, C76, C86],
			      [D26, D36, D46, D56, D66, D76, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C25, C34, C43, C52, C61],
			      [D25, D34, D43, D52, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C17, C18],
			      [D17, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C15, C14, C13, C12, C11],
			      [D15, D14, D13, D12, D11], Flipped),
	Flipped == true.
place_sub1(7, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53|Cs3],
	 [C14, C24, C34, C44|Cs4],
	 [C15, C25, C35|Cs5],
	 [C16, C26|Cs6],
	 [space, C27, C37, C47, C57, C67, C77, C87]|Rest],
	[[D11, C21, C31, C41, C51, C61, D71|Cs1],
	 [D12, C22, C32, C42, C52, D62|Cs2],
	 [D13, C23, C33, C43, D53|Cs3],
	 [D14, C24, C34, D44|Cs4],
	 [D15, C25, D35|Cs5],
	 [D16, D26|Cs6],
	 [Self, D27, D37, D47, D57, D67, D77, D87]|Rest]) :-
	flip_line_if_possible(Self, Opponent,
			      [C27, C37, C47, C57, C67, C77, C87],
			      [D27, D37, D47, D57, D67, D77, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C26, C35, C44, C53, C62, C71],
			      [D26, D35, D44, D53, D62, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C16, C15, C14, C13, C12, C11],
			      [D16, D15, D14, D13, D12, D11], Flipped),
	Flipped == true.
place_sub1(8, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54|Cs4],
	 [C15, C25, C35, C45|Cs5],
	 [C16, C26, C36|Cs6],
	 [C17, C27|Cs7],
	 [space, C28, C38, C48, C58, C68, C78, C88]],
	[[D11, C21, C31, C41, C51, C61, C71, D81],
	 [D12, C22, C32, C42, C52, C62, D72|Cs2],
	 [D13, C23, C33, C43, C53, D63|Cs3],
	 [D14, C24, C34, C44, D54|Cs4],
	 [D15, C25, C35, D45|Cs5],
	 [D16, C26, D36|Cs6],
	 [D17, D27|Cs7],
	 [Self, D28, D38, D48, D58, D68, D78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C28, C38, C48, C58, C68, C78, C88],
			      [D28, D38, D48, D58, D68, D78, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C27, C36, C45, C54, C63, C72, C81],
			      [D27, D36, D45, D54, D63, D72, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C17, C16, C15, C14, C13, C12, C11],
			      [D17, D16, D15, D14, D13, D12, D11], Flipped),
	Flipped == true.
place_sub2(1, Self, Opponent,
	[[C11, space, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32|Cs2],
	 [C13, C23, C33, C43|Cs3],
	 [C14, C24, C34, C44, C54|Cs4],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28|Cs8]],
	[[C11, Self, D31, D41, D51, D61, D71, D81],
	 [C12, D22, D32|Cs2],
	 [C13, D23, C33, D43|Cs3],
	 [C14, D24, C34, C44, D54|Cs4],
	 [C15, D25, C35, C45, C55, D65|Cs5],
	 [C16, D26, C36, C46, C56, C66, D76|Cs6],
	 [C17, D27, C37, C47, C57, C67, C77, D87],
	 [C18, D28|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C32, C43, C54, C65, C76, C87],
			      [D32, D43, D54, D65, D76, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C31, C41, C51, C61, C71, C81],
			      [D31, D41, D51, D61, D71, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C22, C23, C24, C25, C26, C27, C28],
			      [D22, D23, D24, D25, D26, D27, D28], Flipped),
	Flipped == true.
place_sub2(2, Self, Opponent,
	[Cs1,
	 [C12, space, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33|Cs3],
	 [C14, C24, C34, C44|Cs4],
	 [C15, C25, C35, C45, C55|Cs5],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[Cs1,
	 [C12, Self, D32, D42, D52, D62, D72, D82],
	 [C13, D23, D33|Cs3],
	 [C14, D24, C34, D44|Cs4],
	 [C15, D25, C35, C45, D55|Cs5],
	 [C16, D26, C36, C46, C56, D66|Cs6],
	 [C17, D27, C37, C47, C57, C67, D77|Cs7],
	 [C18, D28, C38, C48, C58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C33, C44, C55, C66, C77, C88],
			      [D33, D44, D55, D66, D77, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C32, C42, C52, C62, C72, C82],
			      [D32, D42, D52, D62, D72, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C23, C24, C25, C26, C27, C28],
			      [D23, D24, D25, D26, D27, D28], Flipped),
	Flipped == true.
place_sub2(3, Self, Opponent,
	[[C11, C21, C31, C41|Cs1],
	 [C12, C22, C32|Cs2],
	 [C13, space, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34|Cs4],
	 [C15, C25, C35, C45|Cs5],
	 [C16, C26, C36, C46, C56|Cs6],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[C11, D21, C31, D41|Cs1],
	 [C12, D22, D32|Cs2],
	 [C13, Self, D33, D43, D53, D63, D73, D83],
	 [C14, D24, D34|Cs4],
	 [C15, D25, C35, D45|Cs5],
	 [C16, D26, C36, C46, D56|Cs6],
	 [C17, D27, C37, C47, C57, D67|Cs7],
	 [C18, D28, C38, C48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C34, C45, C56, C67, C78],
			      [D34, D45, D56, D67, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C33, C43, C53, C63, C73, C83],
			      [D33, D43, D53, D63, D73, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C32, C41],
			      [D32, D41], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C24, C25, C26, C27, C28],
			      [D24, D25, D26, D27, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C22, C21],
			      [D22, D21], Flipped),
	Flipped == true.
place_sub2(4, Self, Opponent,
	[[C11, C21, C31, C41, C51|Cs1],
	 [C12, C22, C32, C42|Cs2],
	 [C13, C23, C33|Cs3],
	 [C14, space, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35|Cs5],
	 [C16, C26, C36, C46|Cs6],
	 [C17, C27, C37, C47, C57|Cs7],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[[C11, D21, C31, C41, D51|Cs1],
	 [C12, D22, C32, D42|Cs2],
	 [C13, D23, D33|Cs3],
	 [C14, Self, D34, D44, D54, D64, D74, D84],
	 [C15, D25, D35|Cs5],
	 [C16, D26, C36, D46|Cs6],
	 [C17, D27, C37, C47, D57|Cs7],
	 [C18, D28, C38, C48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C35, C46, C57, C68],
			      [D35, D46, D57, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C34, C44, C54, C64, C74, C84],
			      [D34, D44, D54, D64, D74, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C33, C42, C51],
			      [D33, D42, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C25, C26, C27, C28],
			      [D25, D26, D27, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C23, C22, C21],
			      [D23, D22, D21], Flipped),
	Flipped == true.
place_sub2(5, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52|Cs2],
	 [C13, C23, C33, C43|Cs3],
	 [C14, C24, C34|Cs4],
	 [C15, space, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36|Cs6],
	 [C17, C27, C37, C47|Cs7],
	 [C18, C28, C38, C48, C58|Cs8]],
	[[C11, D21, C31, C41, C51, D61|Cs1],
	 [C12, D22, C32, C42, D52|Cs2],
	 [C13, D23, C33, D43|Cs3],
	 [C14, D24, D34|Cs4],
	 [C15, Self, D35, D45, D55, D65, D75, D85],
	 [C16, D26, D36|Cs6],
	 [C17, D27, C37, D47|Cs7],
	 [C18, D28, C38, C48, D58|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C36, C47, C58],
			      [D36, D47, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C35, C45, C55, C65, C75, C85],
			      [D35, D45, D55, D65, D75, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C34, C43, C52, C61],
			      [D34, D43, D52, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C26, C27, C28],
			      [D26, D27, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C24, C23, C22, C21],
			      [D24, D23, D22, D21], Flipped),
	Flipped == true.
place_sub2(6, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53|Cs3],
	 [C14, C24, C34, C44|Cs4],
	 [C15, C25, C35|Cs5],
	 [C16, space, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37|Cs7],
	 [C18, C28, C38, C48|Cs8]],
	[[C11, D21, C31, C41, C51, C61, D71|Cs1],
	 [C12, D22, C32, C42, C52, D62|Cs2],
	 [C13, D23, C33, C43, D53|Cs3],
	 [C14, D24, C34, D44|Cs4],
	 [C15, D25, D35|Cs5],
	 [C16, Self, D36, D46, D56, D66, D76, D86],
	 [C17, D27, D37|Cs7],
	 [C18, D28, C38, D48|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C37, C48],
			      [D37, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C36, C46, C56, C66, C76, C86],
			      [D36, D46, D56, D66, D76, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C35, C44, C53, C62, C71],
			      [D35, D44, D53, D62, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C27, C28],
			      [D27, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C25, C24, C23, C22, C21],
			      [D25, D24, D23, D22, D21], Flipped),
	Flipped == true.
place_sub2(7, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54|Cs4],
	 [C15, C25, C35, C45|Cs5],
	 [C16, C26, C36|Cs6],
	 [C17, space, C37, C47, C57, C67, C77, C87]|Rest],
	[[C11, D21, C31, C41, C51, C61, C71, D81],
	 [C12, D22, C32, C42, C52, C62, D72|Cs2],
	 [C13, D23, C33, C43, C53, D63|Cs3],
	 [C14, D24, C34, C44, D54|Cs4],
	 [C15, D25, C35, D45|Cs5],
	 [C16, D26, D36|Cs6],
	 [C17, Self, D37, D47, D57, D67, D77, D87]|Rest]) :-
	flip_line_if_possible(Self, Opponent,
			      [C37, C47, C57, C67, C77, C87],
			      [D37, D47, D57, D67, D77, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C36, C45, C54, C63, C72, C81],
			      [D36, D45, D54, D63, D72, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C26, C25, C24, C23, C22, C21],
			      [D26, D25, D24, D23, D22, D21], Flipped),
	Flipped == true.
place_sub2(8, Self, Opponent,
	[[C11, C21|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55|Cs5],
	 [C16, C26, C36, C46|Cs6],
	 [C17, C27, C37|Cs7],
	 [C18, space, C38, C48, C58, C68, C78, C88]],
	[[C11, D21|Cs1],
	 [C12, D22, C32, C42, C52, C62, C72, D82],
	 [C13, D23, C33, C43, C53, C63, D73|Cs3],
	 [C14, D24, C34, C44, C54, D64|Cs4],
	 [C15, D25, C35, C45, D55|Cs5],
	 [C16, D26, C36, D46|Cs6],
	 [C17, D27, D37|Cs7],
	 [C18, Self, D38, D48, D58, D68, D78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C38, C48, C58, C68, C78, C88],
			      [D38, D48, D58, D68, D78, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C37, C46, C55, C64, C73, C82],
			      [D37, D46, D55, D64, D73, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C27, C26, C25, C24, C23, C22, C21],
			      [D27, D26, D25, D24, D23, D22, D21], Flipped),
	Flipped == true.
place_sub3(1, Self, Opponent,
	[[C11, C21, space, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42|Cs2],
	 [C13, C23, C33, C43, C53|Cs3],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37|Cs7],
	 [C18, C28, C38|Cs8]],
	[[D11, D21, Self, D41, D51, D61, D71, D81],
	 [C12, D22, D32, D42|Cs2],
	 [D13, C23, D33, C43, D53|Cs3],
	 [C14, C24, D34, C44, C54, D64|Cs4],
	 [C15, C25, D35, C45, C55, C65, D75|Cs5],
	 [C16, C26, D36, C46, C56, C66, C76, D86],
	 [C17, C27, D37|Cs7],
	 [C18, C28, D38|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C42, C53, C64, C75, C86],
			      [D42, D53, D64, D75, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C41, C51, C61, C71, C81],
			      [D41, D51, D61, D71, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C32, C33, C34, C35, C36, C37, C38],
			      [D32, D33, D34, D35, D36, D37, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C22, C13],
			      [D22, D13], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C21, C11],
			      [D21, D11], Flipped),
	Flipped == true.
place_sub3(2, Self, Opponent,
	[Cs1,
	 [C12, C22, space, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43|Cs3],
	 [C14, C24, C34, C44, C54|Cs4],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38|Cs8]],
	[Cs1,
	 [D12, D22, Self, D42, D52, D62, D72, D82],
	 [C13, D23, D33, D43|Cs3],
	 [D14, C24, D34, C44, D54|Cs4],
	 [C15, C25, D35, C45, C55, D65|Cs5],
	 [C16, C26, D36, C46, C56, C66, D76|Cs6],
	 [C17, C27, D37, C47, C57, C67, C77, D87],
	 [C18, C28, D38|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C43, C54, C65, C76, C87],
			      [D43, D54, D65, D76, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C42, C52, C62, C72, C82],
			      [D42, D52, D62, D72, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C33, C34, C35, C36, C37, C38],
			      [D33, D34, D35, D36, D37, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C23, C14],
			      [D23, D14], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C22, C12],
			      [D22, D12], Flipped),
	Flipped == true.
place_sub3(3, Self, Opponent,
	[[C11, C21, C31, C41, C51|Cs1],
	 [C12, C22, C32, C42|Cs2],
	 [C13, C23, space, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44|Cs4],
	 [C15, C25, C35, C45, C55|Cs5],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[D11, C21, D31, C41, D51|Cs1],
	 [C12, D22, D32, D42|Cs2],
	 [D13, D23, Self, D43, D53, D63, D73, D83],
	 [C14, D24, D34, D44|Cs4],
	 [D15, C25, D35, C45, D55|Cs5],
	 [C16, C26, D36, C46, C56, D66|Cs6],
	 [C17, C27, D37, C47, C57, C67, D77|Cs7],
	 [C18, C28, D38, C48, C58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C44, C55, C66, C77, C88],
			      [D44, D55, D66, D77, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C43, C53, C63, C73, C83],
			      [D43, D53, D63, D73, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C42, C51],
			      [D42, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C34, C35, C36, C37, C38],
			      [D34, D35, D36, D37, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C32, C31],
			      [D32, D31], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C24, C15],
			      [D24, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C23, C13],
			      [D23, D13], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C22, C11],
			      [D22, D11], Flipped),
	Flipped == true.
place_sub3(4, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52|Cs2],
	 [C13, C23, C33, C43|Cs3],
	 [C14, C24, space, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45|Cs5],
	 [C16, C26, C36, C46, C56|Cs6],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[C11, C21, D31, C41, C51, D61|Cs1],
	 [D12, C22, D32, C42, D52|Cs2],
	 [C13, D23, D33, D43|Cs3],
	 [D14, D24, Self, D44, D54, D64, D74, D84],
	 [C15, D25, D35, D45|Cs5],
	 [D16, C26, D36, C46, D56|Cs6],
	 [C17, C27, D37, C47, C57, D67|Cs7],
	 [C18, C28, D38, C48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C45, C56, C67, C78],
			      [D45, D56, D67, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C44, C54, C64, C74, C84],
			      [D44, D54, D64, D74, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C43, C52, C61],
			      [D43, D52, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C35, C36, C37, C38],
			      [D35, D36, D37, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C33, C32, C31],
			      [D33, D32, D31], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C25, C16],
			      [D25, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C24, C14],
			      [D24, D14], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C23, C12],
			      [D23, D12], Flipped),
	Flipped == true.
place_sub3(5, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53|Cs3],
	 [C14, C24, C34, C44|Cs4],
	 [C15, C25, space, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46|Cs6],
	 [C17, C27, C37, C47, C57|Cs7],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[[C11, C21, D31, C41, C51, C61, D71|Cs1],
	 [C12, C22, D32, C42, C52, D62|Cs2],
	 [D13, C23, D33, C43, D53|Cs3],
	 [C14, D24, D34, D44|Cs4],
	 [D15, D25, Self, D45, D55, D65, D75, D85],
	 [C16, D26, D36, D46|Cs6],
	 [D17, C27, D37, C47, D57|Cs7],
	 [C18, C28, D38, C48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C46, C57, C68],
			      [D46, D57, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C45, C55, C65, C75, C85],
			      [D45, D55, D65, D75, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C44, C53, C62, C71],
			      [D44, D53, D62, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C36, C37, C38],
			      [D36, D37, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C34, C33, C32, C31],
			      [D34, D33, D32, D31], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C26, C17],
			      [D26, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C25, C15],
			      [D25, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C24, C13],
			      [D24, D13], Flipped),
	Flipped == true.
place_sub3(6, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54|Cs4],
	 [C15, C25, C35, C45|Cs5],
	 [C16, C26, space, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47|Cs7],
	 [C18, C28, C38, C48, C58|Cs8]],
	[[C11, C21, D31, C41, C51, C61, C71, D81],
	 [C12, C22, D32, C42, C52, C62, D72|Cs2],
	 [C13, C23, D33, C43, C53, D63|Cs3],
	 [D14, C24, D34, C44, D54|Cs4],
	 [C15, D25, D35, D45|Cs5],
	 [D16, D26, Self, D46, D56, D66, D76, D86],
	 [C17, D27, D37, D47|Cs7],
	 [D18, C28, D38, C48, D58|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C47, C58],
			      [D47, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C46, C56, C66, C76, C86],
			      [D46, D56, D66, D76, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C45, C54, C63, C72, C81],
			      [D45, D54, D63, D72, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C37, C38],
			      [D37, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C35, C34, C33, C32, C31],
			      [D35, D34, D33, D32, D31], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C27, C18],
			      [D27, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C26, C16],
			      [D26, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C25, C14],
			      [D25, D14], Flipped),
	Flipped == true.
place_sub3(7, Self, Opponent,
	[[C11, C21, C31|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55|Cs5],
	 [C16, C26, C36, C46|Cs6],
	 [C17, C27, space, C47, C57, C67, C77, C87]|Rest],
	[[C11, C21, D31|Cs1],
	 [C12, C22, D32, C42, C52, C62, C72, D82],
	 [C13, C23, D33, C43, C53, C63, D73|Cs3],
	 [C14, C24, D34, C44, C54, D64|Cs4],
	 [D15, C25, D35, C45, D55|Cs5],
	 [C16, D26, D36, D46|Cs6],
	 [D17, D27, Self, D47, D57, D67, D77, D87]|Rest]) :-
	flip_line_if_possible(Self, Opponent,
			      [C47, C57, C67, C77, C87],
			      [D47, D57, D67, D77, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C46, C55, C64, C73, C82],
			      [D46, D55, D64, D73, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C36, C35, C34, C33, C32, C31],
			      [D36, D35, D34, D33, D32, D31], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C27, C17],
			      [D27, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C26, C15],
			      [D26, D15], Flipped),
	Flipped == true.
place_sub3(8, Self, Opponent,
	[[C11, C21, C31|Cs1],
	 [C12, C22, C32|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56|Cs6],
	 [C17, C27, C37, C47|Cs7],
	 [C18, C28, space, C48, C58, C68, C78, C88]],
	[[C11, C21, D31|Cs1],
	 [C12, C22, D32|Cs2],
	 [C13, C23, D33, C43, C53, C63, C73, D83],
	 [C14, C24, D34, C44, C54, C64, D74|Cs4],
	 [C15, C25, D35, C45, C55, D65|Cs5],
	 [D16, C26, D36, C46, D56|Cs6],
	 [C17, D27, D37, D47|Cs7],
	 [D18, D28, Self, D48, D58, D68, D78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C48, C58, C68, C78, C88],
			      [D48, D58, D68, D78, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C47, C56, C65, C74, C83],
			      [D47, D56, D65, D74, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C37, C36, C35, C34, C33, C32, C31],
			      [D37, D36, D35, D34, D33, D32, D31], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C28, C18],
			      [D28, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C27, C16],
			      [D27, D16], Flipped),
	Flipped == true.
place_sub4(1, Self, Opponent,
	[[C11, C21, C31, space, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46|Cs6],
	 [C17, C27, C37, C47|Cs7],
	 [C18, C28, C38, C48|Cs8]],
	[[D11, D21, D31, Self, D51, D61, D71, D81],
	 [C12, C22, D32, D42, D52|Cs2],
	 [C13, D23, C33, D43, C53, D63|Cs3],
	 [D14, C24, C34, D44, C54, C64, D74|Cs4],
	 [C15, C25, C35, D45, C55, C65, C75, D85],
	 [C16, C26, C36, D46|Cs6],
	 [C17, C27, C37, D47|Cs7],
	 [C18, C28, C38, D48|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C52, C63, C74, C85],
			      [D52, D63, D74, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C51, C61, C71, C81],
			      [D51, D61, D71, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C42, C43, C44, C45, C46, C47, C48],
			      [D42, D43, D44, D45, D46, D47, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C32, C23, C14],
			      [D32, D23, D14], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C31, C21, C11],
			      [D31, D21, D11], Flipped),
	Flipped == true.
place_sub4(2, Self, Opponent,
	[Cs1,
	 [C12, C22, C32, space, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53|Cs3],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47|Cs7],
	 [C18, C28, C38, C48|Cs8]],
	[Cs1,
	 [D12, D22, D32, Self, D52, D62, D72, D82],
	 [C13, C23, D33, D43, D53|Cs3],
	 [C14, D24, C34, D44, C54, D64|Cs4],
	 [D15, C25, C35, D45, C55, C65, D75|Cs5],
	 [C16, C26, C36, D46, C56, C66, C76, D86],
	 [C17, C27, C37, D47|Cs7],
	 [C18, C28, C38, D48|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C53, C64, C75, C86],
			      [D53, D64, D75, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C52, C62, C72, C82],
			      [D52, D62, D72, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C43, C44, C45, C46, C47, C48],
			      [D43, D44, D45, D46, D47, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C33, C24, C15],
			      [D33, D24, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C32, C22, C12],
			      [D32, D22, D12], Flipped),
	Flipped == true.
place_sub4(3, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52|Cs2],
	 [C13, C23, C33, space, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54|Cs4],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48|Cs8]],
	[[C11, D21, C31, D41, C51, D61|Cs1],
	 [C12, C22, D32, D42, D52|Cs2],
	 [D13, D23, D33, Self, D53, D63, D73, D83],
	 [C14, C24, D34, D44, D54|Cs4],
	 [C15, D25, C35, D45, C55, D65|Cs5],
	 [D16, C26, C36, D46, C56, C66, D76|Cs6],
	 [C17, C27, C37, D47, C57, C67, C77, D87],
	 [C18, C28, C38, D48|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C54, C65, C76, C87],
			      [D54, D65, D76, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C53, C63, C73, C83],
			      [D53, D63, D73, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C52, C61],
			      [D52, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C44, C45, C46, C47, C48],
			      [D44, D45, D46, D47, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C42, C41],
			      [D42, D41], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C34, C25, C16],
			      [D34, D25, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C33, C23, C13],
			      [D33, D23, D13], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C32, C21],
			      [D32, D21], Flipped),
	Flipped == true.
place_sub4(4, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53|Cs3],
	 [C14, C24, C34, space, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55|Cs5],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[D11, C21, C31, D41, C51, C61, D71|Cs1],
	 [C12, D22, C32, D42, C52, D62|Cs2],
	 [C13, C23, D33, D43, D53|Cs3],
	 [D14, D24, D34, Self, D54, D64, D74, D84],
	 [C15, C25, D35, D45, D55|Cs5],
	 [C16, D26, C36, D46, C56, D66|Cs6],
	 [D17, C27, C37, D47, C57, C67, D77|Cs7],
	 [C18, C28, C38, D48, C58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C55, C66, C77, C88],
			      [D55, D66, D77, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C54, C64, C74, C84],
			      [D54, D64, D74, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C53, C62, C71],
			      [D53, D62, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C45, C46, C47, C48],
			      [D45, D46, D47, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C43, C42, C41],
			      [D43, D42, D41], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C35, C26, C17],
			      [D35, D26, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C34, C24, C14],
			      [D34, D24, D14], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C33, C22, C11],
			      [D33, D22, D11], Flipped),
	Flipped == true.
place_sub4(5, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54|Cs4],
	 [C15, C25, C35, space, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56|Cs6],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[C11, C21, C31, D41, C51, C61, C71, D81],
	 [D12, C22, C32, D42, C52, C62, D72|Cs2],
	 [C13, D23, C33, D43, C53, D63|Cs3],
	 [C14, C24, D34, D44, D54|Cs4],
	 [D15, D25, D35, Self, D55, D65, D75, D85],
	 [C16, C26, D36, D46, D56|Cs6],
	 [C17, D27, C37, D47, C57, D67|Cs7],
	 [D18, C28, C38, D48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C56, C67, C78],
			      [D56, D67, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C55, C65, C75, C85],
			      [D55, D65, D75, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C54, C63, C72, C81],
			      [D54, D63, D72, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C46, C47, C48],
			      [D46, D47, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C44, C43, C42, C41],
			      [D44, D43, D42, D41], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C36, C27, C18],
			      [D36, D27, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C35, C25, C15],
			      [D35, D25, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C34, C23, C12],
			      [D34, D23, D12], Flipped),
	Flipped == true.
place_sub4(6, Self, Opponent,
	[[C11, C21, C31, C41|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55|Cs5],
	 [C16, C26, C36, space, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57|Cs7],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[[C11, C21, C31, D41|Cs1],
	 [C12, C22, C32, D42, C52, C62, C72, D82],
	 [D13, C23, C33, D43, C53, C63, D73|Cs3],
	 [C14, D24, C34, D44, C54, D64|Cs4],
	 [C15, C25, D35, D45, D55|Cs5],
	 [D16, D26, D36, Self, D56, D66, D76, D86],
	 [C17, C27, D37, D47, D57|Cs7],
	 [C18, D28, C38, D48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C57, C68],
			      [D57, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C56, C66, C76, C86],
			      [D56, D66, D76, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C55, C64, C73, C82],
			      [D55, D64, D73, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C47, C48],
			      [D47, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C45, C44, C43, C42, C41],
			      [D45, D44, D43, D42, D41], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C37, C28],
			      [D37, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C36, C26, C16],
			      [D36, D26, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C35, C24, C13],
			      [D35, D24, D13], Flipped),
	Flipped == true.
place_sub4(7, Self, Opponent,
	[[C11, C21, C31, C41|Cs1],
	 [C12, C22, C32, C42|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56|Cs6],
	 [C17, C27, C37, space, C57, C67, C77, C87]|Rest],
	[[C11, C21, C31, D41|Cs1],
	 [C12, C22, C32, D42|Cs2],
	 [C13, C23, C33, D43, C53, C63, C73, D83],
	 [D14, C24, C34, D44, C54, C64, D74|Cs4],
	 [C15, D25, C35, D45, C55, D65|Cs5],
	 [C16, C26, D36, D46, D56|Cs6],
	 [D17, D27, D37, Self, D57, D67, D77, D87]|Rest]) :-
	flip_line_if_possible(Self, Opponent,
			      [C57, C67, C77, C87],
			      [D57, D67, D77, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C56, C65, C74, C83],
			      [D56, D65, D74, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C46, C45, C44, C43, C42, C41],
			      [D46, D45, D44, D43, D42, D41], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C37, C27, C17],
			      [D37, D27, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C36, C25, C14],
			      [D36, D25, D14], Flipped),
	Flipped == true.
place_sub4(8, Self, Opponent,
	[[C11, C21, C31, C41|Cs1],
	 [C12, C22, C32, C42|Cs2],
	 [C13, C23, C33, C43|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57|Cs7],
	 [C18, C28, C38, space, C58, C68, C78, C88]],
	[[C11, C21, C31, D41|Cs1],
	 [C12, C22, C32, D42|Cs2],
	 [C13, C23, C33, D43|Cs3],
	 [C14, C24, C34, D44, C54, C64, C74, D84],
	 [D15, C25, C35, D45, C55, C65, D75|Cs5],
	 [C16, D26, C36, D46, C56, D66|Cs6],
	 [C17, C27, D37, D47, D57|Cs7],
	 [D18, D28, D38, Self, D58, D68, D78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C58, C68, C78, C88],
			      [D58, D68, D78, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C57, C66, C75, C84],
			      [D57, D66, D75, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C47, C46, C45, C44, C43, C42, C41],
			      [D47, D46, D45, D44, D43, D42, D41], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C38, C28, C18],
			      [D38, D28, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C37, C26, C15],
			      [D37, D26, D15], Flipped),
	Flipped == true.
place_sub5(1, Self, Opponent,
	[[C11, C21, C31, C41, space, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55|Cs5],
	 [C16, C26, C36, C46, C56|Cs6],
	 [C17, C27, C37, C47, C57|Cs7],
	 [C18, C28, C38, C48, C58|Cs8]],
	[[D11, D21, D31, D41, Self, D61, D71, D81],
	 [C12, C22, C32, D42, D52, D62|Cs2],
	 [C13, C23, D33, C43, D53, C63, D73|Cs3],
	 [C14, D24, C34, C44, D54, C64, C74, D84],
	 [D15, C25, C35, C45, D55|Cs5],
	 [C16, C26, C36, C46, D56|Cs6],
	 [C17, C27, C37, C47, D57|Cs7],
	 [C18, C28, C38, C48, D58|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C62, C73, C84],
			      [D62, D73, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C61, C71, C81],
			      [D61, D71, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C52, C53, C54, C55, C56, C57, C58],
			      [D52, D53, D54, D55, D56, D57, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C42, C33, C24, C15],
			      [D42, D33, D24, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C41, C31, C21, C11],
			      [D41, D31, D21, D11], Flipped),
	Flipped == true.
place_sub5(2, Self, Opponent,
	[Cs1,
	 [C12, C22, C32, C42, space, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56|Cs6],
	 [C17, C27, C37, C47, C57|Cs7],
	 [C18, C28, C38, C48, C58|Cs8]],
	[Cs1,
	 [D12, D22, D32, D42, Self, D62, D72, D82],
	 [C13, C23, C33, D43, D53, D63|Cs3],
	 [C14, C24, D34, C44, D54, C64, D74|Cs4],
	 [C15, D25, C35, C45, D55, C65, C75, D85],
	 [D16, C26, C36, C46, D56|Cs6],
	 [C17, C27, C37, C47, D57|Cs7],
	 [C18, C28, C38, C48, D58|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C63, C74, C85],
			      [D63, D74, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C62, C72, C82],
			      [D62, D72, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C53, C54, C55, C56, C57, C58],
			      [D53, D54, D55, D56, D57, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C43, C34, C25, C16],
			      [D43, D34, D25, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C42, C32, C22, C12],
			      [D42, D32, D22, D12], Flipped),
	Flipped == true.
place_sub5(3, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, space, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57|Cs7],
	 [C18, C28, C38, C48, C58|Cs8]],
	[[C11, C21, D31, C41, D51, C61, D71|Cs1],
	 [C12, C22, C32, D42, D52, D62|Cs2],
	 [D13, D23, D33, D43, Self, D63, D73, D83],
	 [C14, C24, C34, D44, D54, D64|Cs4],
	 [C15, C25, D35, C45, D55, C65, D75|Cs5],
	 [C16, D26, C36, C46, D56, C66, C76, D86],
	 [D17, C27, C37, C47, D57|Cs7],
	 [C18, C28, C38, C48, D58|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C64, C75, C86],
			      [D64, D75, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C63, C73, C83],
			      [D63, D73, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C62, C71],
			      [D62, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C54, C55, C56, C57, C58],
			      [D54, D55, D56, D57, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C52, C51],
			      [D52, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C44, C35, C26, C17],
			      [D44, D35, D26, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C43, C33, C23, C13],
			      [D43, D33, D23, D13], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C42, C31],
			      [D42, D31], Flipped),
	Flipped == true.
place_sub5(4, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, space, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58|Cs8]],
	[[C11, D21, C31, C41, D51, C61, C71, D81],
	 [C12, C22, D32, C42, D52, C62, D72|Cs2],
	 [C13, C23, C33, D43, D53, D63|Cs3],
	 [D14, D24, D34, D44, Self, D64, D74, D84],
	 [C15, C25, C35, D45, D55, D65|Cs5],
	 [C16, C26, D36, C46, D56, C66, D76|Cs6],
	 [C17, D27, C37, C47, D57, C67, C77, D87],
	 [D18, C28, C38, C48, D58|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C65, C76, C87],
			      [D65, D76, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C64, C74, C84],
			      [D64, D74, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C63, C72, C81],
			      [D63, D72, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C55, C56, C57, C58],
			      [D55, D56, D57, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C53, C52, C51],
			      [D53, D52, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C45, C36, C27, C18],
			      [D45, D36, D27, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C44, C34, C24, C14],
			      [D44, D34, D24, D14], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C43, C32, C21],
			      [D43, D32, D21], Flipped),
	Flipped == true.
place_sub5(5, Self, Opponent,
	[[C11, C21, C31, C41, C51|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, space, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[D11, C21, C31, C41, D51|Cs1],
	 [C12, D22, C32, C42, D52, C62, C72, D82],
	 [C13, C23, D33, C43, D53, C63, D73|Cs3],
	 [C14, C24, C34, D44, D54, D64|Cs4],
	 [D15, D25, D35, D45, Self, D65, D75, D85],
	 [C16, C26, C36, D46, D56, D66|Cs6],
	 [C17, C27, D37, C47, D57, C67, D77|Cs7],
	 [C18, D28, C38, C48, D58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C66, C77, C88],
			      [D66, D77, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C65, C75, C85],
			      [D65, D75, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C64, C73, C82],
			      [D64, D73, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C56, C57, C58],
			      [D56, D57, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C54, C53, C52, C51],
			      [D54, D53, D52, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C46, C37, C28],
			      [D46, D37, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C45, C35, C25, C15],
			      [D45, D35, D25, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C44, C33, C22, C11],
			      [D44, D33, D22, D11], Flipped),
	Flipped == true.
place_sub5(6, Self, Opponent,
	[[C11, C21, C31, C41, C51|Cs1],
	 [C12, C22, C32, C42, C52|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, space, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[C11, C21, C31, C41, D51|Cs1],
	 [D12, C22, C32, C42, D52|Cs2],
	 [C13, D23, C33, C43, D53, C63, C73, D83],
	 [C14, C24, D34, C44, D54, C64, D74|Cs4],
	 [C15, C25, C35, D45, D55, D65|Cs5],
	 [D16, D26, D36, D46, Self, D66, D76, D86],
	 [C17, C27, C37, D47, D57, D67|Cs7],
	 [C18, C28, D38, C48, D58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C67, C78],
			      [D67, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C66, C76, C86],
			      [D66, D76, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C65, C74, C83],
			      [D65, D74, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C57, C58],
			      [D57, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C55, C54, C53, C52, C51],
			      [D55, D54, D53, D52, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C47, C38],
			      [D47, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C46, C36, C26, C16],
			      [D46, D36, D26, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C45, C34, C23, C12],
			      [D45, D34, D23, D12], Flipped),
	Flipped == true.
place_sub5(7, Self, Opponent,
	[[C11, C21, C31, C41, C51|Cs1],
	 [C12, C22, C32, C42, C52|Cs2],
	 [C13, C23, C33, C43, C53|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, space, C67, C77, C87]|Rest],
	[[C11, C21, C31, C41, D51|Cs1],
	 [C12, C22, C32, C42, D52|Cs2],
	 [D13, C23, C33, C43, D53|Cs3],
	 [C14, D24, C34, C44, D54, C64, C74, D84],
	 [C15, C25, D35, C45, D55, C65, D75|Cs5],
	 [C16, C26, C36, D46, D56, D66|Cs6],
	 [D17, D27, D37, D47, Self, D67, D77, D87]|Rest]) :-
	flip_line_if_possible(Self, Opponent,
			      [C67, C77, C87],
			      [D67, D77, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C66, C75, C84],
			      [D66, D75, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C56, C55, C54, C53, C52, C51],
			      [D56, D55, D54, D53, D52, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C47, C37, C27, C17],
			      [D47, D37, D27, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C46, C35, C24, C13],
			      [D46, D35, D24, D13], Flipped),
	Flipped == true.
place_sub5(8, Self, Opponent,
	[[C11, C21, C31, C41, C51|Cs1],
	 [C12, C22, C32, C42, C52|Cs2],
	 [C13, C23, C33, C43, C53|Cs3],
	 [C14, C24, C34, C44, C54|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, space, C68, C78, C88]],
	[[C11, C21, C31, C41, D51|Cs1],
	 [C12, C22, C32, C42, D52|Cs2],
	 [C13, C23, C33, C43, D53|Cs3],
	 [D14, C24, C34, C44, D54|Cs4],
	 [C15, D25, C35, C45, D55, C65, C75, D85],
	 [C16, C26, D36, C46, D56, C66, D76|Cs6],
	 [C17, C27, C37, D47, D57, D67|Cs7],
	 [D18, D28, D38, D48, Self, D68, D78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C68, C78, C88],
			      [D68, D78, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C67, C76, C85],
			      [D67, D76, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C57, C56, C55, C54, C53, C52, C51],
			      [D57, D56, D55, D54, D53, D52, D51], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C48, C38, C28, C18],
			      [D48, D38, D28, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C47, C36, C25, C14],
			      [D47, D36, D25, D14], Flipped),
	Flipped == true.
place_sub6(1, Self, Opponent,
	[[C11, C21, C31, C41, C51, space, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[[D11, D21, D31, D41, D51, Self, D71, D81],
	 [C12, C22, C32, C42, D52, D62, D72|Cs2],
	 [C13, C23, C33, D43, C53, D63, C73, D83],
	 [C14, C24, D34, C44, C54, D64|Cs4],
	 [C15, D25, C35, C45, C55, D65|Cs5],
	 [D16, C26, C36, C46, C56, D66|Cs6],
	 [C17, C27, C37, C47, C57, D67|Cs7],
	 [C18, C28, C38, C48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C72, C83],
			      [D72, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C71, C81],
			      [D71, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C62, C63, C64, C65, C66, C67, C68],
			      [D62, D63, D64, D65, D66, D67, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C52, C43, C34, C25, C16],
			      [D52, D43, D34, D25, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C51, C41, C31, C21, C11],
			      [D51, D41, D31, D21, D11], Flipped),
	Flipped == true.
place_sub6(2, Self, Opponent,
	[Cs1,
	 [C12, C22, C32, C42, C52, space, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[Cs1,
	 [D12, D22, D32, D42, D52, Self, D72, D82],
	 [C13, C23, C33, C43, D53, D63, D73|Cs3],
	 [C14, C24, C34, D44, C54, D64, C74, D84],
	 [C15, C25, D35, C45, C55, D65|Cs5],
	 [C16, D26, C36, C46, C56, D66|Cs6],
	 [D17, C27, C37, C47, C57, D67|Cs7],
	 [C18, C28, C38, C48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C73, C84],
			      [D73, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C72, C82],
			      [D72, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C63, C64, C65, C66, C67, C68],
			      [D63, D64, D65, D66, D67, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C53, C44, C35, C26, C17],
			      [D53, D44, D35, D26, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C52, C42, C32, C22, C12],
			      [D52, D42, D32, D22, D12], Flipped),
	Flipped == true.
place_sub6(3, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, space, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66|Cs6],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[[C11, C21, C31, D41, C51, D61, C71, D81],
	 [C12, C22, C32, C42, D52, D62, D72|Cs2],
	 [D13, D23, D33, D43, D53, Self, D73, D83],
	 [C14, C24, C34, C44, D54, D64, D74|Cs4],
	 [C15, C25, C35, D45, C55, D65, C75, D85],
	 [C16, C26, D36, C46, C56, D66|Cs6],
	 [C17, D27, C37, C47, C57, D67|Cs7],
	 [D18, C28, C38, C48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C74, C85],
			      [D74, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C73, C83],
			      [D73, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C72, C81],
			      [D72, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C64, C65, C66, C67, C68],
			      [D64, D65, D66, D67, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C62, C61],
			      [D62, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C54, C45, C36, C27, C18],
			      [D54, D45, D36, D27, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C53, C43, C33, C23, C13],
			      [D53, D43, D33, D23, D13], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C52, C41],
			      [D52, D41], Flipped),
	Flipped == true.
place_sub6(4, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, space, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67|Cs7],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[[C11, C21, D31, C41, C51, D61|Cs1],
	 [C12, C22, C32, D42, C52, D62, C72, D82],
	 [C13, C23, C33, C43, D53, D63, D73|Cs3],
	 [D14, D24, D34, D44, D54, Self, D74, D84],
	 [C15, C25, C35, C45, D55, D65, D75|Cs5],
	 [C16, C26, C36, D46, C56, D66, C76, D86],
	 [C17, C27, D37, C47, C57, D67|Cs7],
	 [C18, D28, C38, C48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C75, C86],
			      [D75, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C74, C84],
			      [D74, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C73, C82],
			      [D73, D82], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C65, C66, C67, C68],
			      [D65, D66, D67, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C63, C62, C61],
			      [D63, D62, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C55, C46, C37, C28],
			      [D55, D46, D37, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C54, C44, C34, C24, C14],
			      [D54, D44, D34, D24, D14], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C53, C42, C31],
			      [D53, D42, D31], Flipped),
	Flipped == true.
place_sub6(5, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, space, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58, C68|Cs8]],
	[[C11, D21, C31, C41, C51, D61|Cs1],
	 [C12, C22, D32, C42, C52, D62|Cs2],
	 [C13, C23, C33, D43, C53, D63, C73, D83],
	 [C14, C24, C34, C44, D54, D64, D74|Cs4],
	 [D15, D25, D35, D45, D55, Self, D75, D85],
	 [C16, C26, C36, C46, D56, D66, D76|Cs6],
	 [C17, C27, C37, D47, C57, D67, C77, D87],
	 [C18, C28, D38, C48, C58, D68|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C76, C87],
			      [D76, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C75, C85],
			      [D75, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C74, C83],
			      [D74, D83], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C66, C67, C68],
			      [D66, D67, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C64, C63, C62, C61],
			      [D64, D63, D62, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C56, C47, C38],
			      [D56, D47, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C55, C45, C35, C25, C15],
			      [D55, D45, D35, D25, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C54, C43, C32, C21],
			      [D54, D43, D32, D21], Flipped),
	Flipped == true.
place_sub6(6, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, space, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[D11, C21, C31, C41, C51, D61|Cs1],
	 [C12, D22, C32, C42, C52, D62|Cs2],
	 [C13, C23, D33, C43, C53, D63|Cs3],
	 [C14, C24, C34, D44, C54, D64, C74, D84],
	 [C15, C25, C35, C45, D55, D65, D75|Cs5],
	 [D16, D26, D36, D46, D56, Self, D76, D86],
	 [C17, C27, C37, C47, D57, D67, D77|Cs7],
	 [C18, C28, C38, D48, C58, D68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C77, C88],
			      [D77, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C76, C86],
			      [D76, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C75, C84],
			      [D75, D84], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C67, C68],
			      [D67, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C65, C64, C63, C62, C61],
			      [D65, D64, D63, D62, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C57, C48],
			      [D57, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C56, C46, C36, C26, C16],
			      [D56, D46, D36, D26, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C55, C44, C33, C22, C11],
			      [D55, D44, D33, D22, D11], Flipped),
	Flipped == true.
place_sub6(7, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, space, C77, C87]|Rest],
	[[C11, C21, C31, C41, C51, D61|Cs1],
	 [D12, C22, C32, C42, C52, D62|Cs2],
	 [C13, D23, C33, C43, C53, D63|Cs3],
	 [C14, C24, D34, C44, C54, D64|Cs4],
	 [C15, C25, C35, D45, C55, D65, C75, D85],
	 [C16, C26, C36, C46, D56, D66, D76|Cs6],
	 [D17, D27, D37, D47, D57, Self, D77, D87]|Rest]) :-
	flip_line_if_possible(Self, Opponent,
			      [C77, C87],
			      [D77, D87], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C76, C85],
			      [D76, D85], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C66, C65, C64, C63, C62, C61],
			      [D66, D65, D64, D63, D62, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C57, C47, C37, C27, C17],
			      [D57, D47, D37, D27, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C56, C45, C34, C23, C12],
			      [D56, D45, D34, D23, D12], Flipped),
	Flipped == true.
place_sub6(8, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61|Cs1],
	 [C12, C22, C32, C42, C52, C62|Cs2],
	 [C13, C23, C33, C43, C53, C63|Cs3],
	 [C14, C24, C34, C44, C54, C64|Cs4],
	 [C15, C25, C35, C45, C55, C65|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, space, C78, C88]],
	[[C11, C21, C31, C41, C51, D61|Cs1],
	 [C12, C22, C32, C42, C52, D62|Cs2],
	 [D13, C23, C33, C43, C53, D63|Cs3],
	 [C14, D24, C34, C44, C54, D64|Cs4],
	 [C15, C25, D35, C45, C55, D65|Cs5],
	 [C16, C26, C36, D46, C56, D66, C76, D86],
	 [C17, C27, C37, C47, D57, D67, D77|Cs7],
	 [D18, D28, D38, D48, D58, Self, D78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C78, C88],
			      [D78, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C77, C86],
			      [D77, D86], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C67, C66, C65, C64, C63, C62, C61],
			      [D67, D66, D65, D64, D63, D62, D61], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C58, C48, C38, C28, C18],
			      [D58, D48, D38, D28, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C57, C46, C35, C24, C13],
			      [D57, D46, D35, D24, D13], Flipped),
	Flipped == true.
place_sub7(1, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, space|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[D11, D21, D31, D41, D51, D61, Self|Cs1],
	 [C12, C22, C32, C42, C52, D62, D72|Cs2],
	 [C13, C23, C33, C43, D53, C63, D73|Cs3],
	 [C14, C24, C34, D44, C54, C64, D74|Cs4],
	 [C15, C25, D35, C45, C55, C65, D75|Cs5],
	 [C16, D26, C36, C46, C56, C66, D76|Cs6],
	 [D17, C27, C37, C47, C57, C67, D77|Cs7],
	 [C18, C28, C38, C48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C72, C73, C74, C75, C76, C77, C78],
			      [D72, D73, D74, D75, D76, D77, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C62, C53, C44, C35, C26, C17],
			      [D62, D53, D44, D35, D26, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C61, C51, C41, C31, C21, C11],
			      [D61, D51, D41, D31, D21, D11], Flipped),
	Flipped == true.
place_sub7(2, Self, Opponent,
	[Cs1,
	 [C12, C22, C32, C42, C52, C62, space|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[Cs1,
	 [D12, D22, D32, D42, D52, D62, Self|Cs2],
	 [C13, C23, C33, C43, C53, D63, D73|Cs3],
	 [C14, C24, C34, C44, D54, C64, D74|Cs4],
	 [C15, C25, C35, D45, C55, C65, D75|Cs5],
	 [C16, C26, D36, C46, C56, C66, D76|Cs6],
	 [C17, D27, C37, C47, C57, C67, D77|Cs7],
	 [D18, C28, C38, C48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C73, C74, C75, C76, C77, C78],
			      [D73, D74, D75, D76, D77, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C63, C54, C45, C36, C27, C18],
			      [D63, D54, D45, D36, D27, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C62, C52, C42, C32, C22, C12],
			      [D62, D52, D42, D32, D22, D12], Flipped),
	Flipped == true.
place_sub7(3, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63, space|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[C11, C21, C31, C41, D51, C61, D71|Cs1],
	 [C12, C22, C32, C42, C52, D62, D72|Cs2],
	 [D13, D23, D33, D43, D53, D63, Self|Cs3],
	 [C14, C24, C34, C44, C54, D64, D74|Cs4],
	 [C15, C25, C35, C45, D55, C65, D75|Cs5],
	 [C16, C26, C36, D46, C56, C66, D76|Cs6],
	 [C17, C27, D37, C47, C57, C67, D77|Cs7],
	 [C18, D28, C38, C48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C74, C75, C76, C77, C78],
			      [D74, D75, D76, D77, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C72, C71],
			      [D72, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C64, C55, C46, C37, C28],
			      [D64, D55, D46, D37, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C63, C53, C43, C33, C23, C13],
			      [D63, D53, D43, D33, D23, D13], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C62, C51],
			      [D62, D51], Flipped),
	Flipped == true.
place_sub7(4, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, space|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[C11, C21, C31, D41, C51, C61, D71|Cs1],
	 [C12, C22, C32, C42, D52, C62, D72|Cs2],
	 [C13, C23, C33, C43, C53, D63, D73|Cs3],
	 [D14, D24, D34, D44, D54, D64, Self|Cs4],
	 [C15, C25, C35, C45, C55, D65, D75|Cs5],
	 [C16, C26, C36, C46, D56, C66, D76|Cs6],
	 [C17, C27, C37, D47, C57, C67, D77|Cs7],
	 [C18, C28, D38, C48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C75, C76, C77, C78],
			      [D75, D76, D77, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C73, C72, C71],
			      [D73, D72, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C65, C56, C47, C38],
			      [D65, D56, D47, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C64, C54, C44, C34, C24, C14],
			      [D64, D54, D44, D34, D24, D14], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C63, C52, C41],
			      [D63, D52, D41], Flipped),
	Flipped == true.
place_sub7(5, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, space|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[C11, C21, D31, C41, C51, C61, D71|Cs1],
	 [C12, C22, C32, D42, C52, C62, D72|Cs2],
	 [C13, C23, C33, C43, D53, C63, D73|Cs3],
	 [C14, C24, C34, C44, C54, D64, D74|Cs4],
	 [D15, D25, D35, D45, D55, D65, Self|Cs5],
	 [C16, C26, C36, C46, C56, D66, D76|Cs6],
	 [C17, C27, C37, C47, D57, C67, D77|Cs7],
	 [C18, C28, C38, D48, C58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C76, C77, C78],
			      [D76, D77, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C74, C73, C72, C71],
			      [D74, D73, D72, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C66, C57, C48],
			      [D66, D57, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C65, C55, C45, C35, C25, C15],
			      [D65, D55, D45, D35, D25, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C64, C53, C42, C31],
			      [D64, D53, D42, D31], Flipped),
	Flipped == true.
place_sub7(6, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, space|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, C78|Cs8]],
	[[C11, D21, C31, C41, C51, C61, D71|Cs1],
	 [C12, C22, D32, C42, C52, C62, D72|Cs2],
	 [C13, C23, C33, D43, C53, C63, D73|Cs3],
	 [C14, C24, C34, C44, D54, C64, D74|Cs4],
	 [C15, C25, C35, C45, C55, D65, D75|Cs5],
	 [D16, D26, D36, D46, D56, D66, Self|Cs6],
	 [C17, C27, C37, C47, C57, D67, D77|Cs7],
	 [C18, C28, C38, C48, D58, C68, D78|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C77, C78],
			      [D77, D78], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C75, C74, C73, C72, C71],
			      [D75, D74, D73, D72, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C67, C58],
			      [D67, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C66, C56, C46, C36, C26, C16],
			      [D66, D56, D46, D36, D26, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C65, C54, C43, C32, C21],
			      [D65, D54, D43, D32, D21], Flipped),
	Flipped == true.
place_sub7(7, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, space|Cs7]|Rest],
	[[D11, C21, C31, C41, C51, C61, D71|Cs1],
	 [C12, D22, C32, C42, C52, C62, D72|Cs2],
	 [C13, C23, D33, C43, C53, C63, D73|Cs3],
	 [C14, C24, C34, D44, C54, C64, D74|Cs4],
	 [C15, C25, C35, C45, D55, C65, D75|Cs5],
	 [C16, C26, C36, C46, C56, D66, D76|Cs6],
	 [D17, D27, D37, D47, D57, D67, Self|Cs7]|Rest]) :-
	flip_line_if_possible(Self, Opponent,
			      [C76, C75, C74, C73, C72, C71],
			      [D76, D75, D74, D73, D72, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C67, C57, C47, C37, C27, C17],
			      [D67, D57, D47, D37, D27, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C66, C55, C44, C33, C22, C11],
			      [D66, D55, D44, D33, D22, D11], Flipped),
	Flipped == true.
place_sub7(8, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71|Cs1],
	 [C12, C22, C32, C42, C52, C62, C72|Cs2],
	 [C13, C23, C33, C43, C53, C63, C73|Cs3],
	 [C14, C24, C34, C44, C54, C64, C74|Cs4],
	 [C15, C25, C35, C45, C55, C65, C75|Cs5],
	 [C16, C26, C36, C46, C56, C66, C76|Cs6],
	 [C17, C27, C37, C47, C57, C67, C77|Cs7],
	 [C18, C28, C38, C48, C58, C68, space|Cs8]],
	[[C11, C21, C31, C41, C51, C61, D71|Cs1],
	 [D12, C22, C32, C42, C52, C62, D72|Cs2],
	 [C13, D23, C33, C43, C53, C63, D73|Cs3],
	 [C14, C24, D34, C44, C54, C64, D74|Cs4],
	 [C15, C25, C35, D45, C55, C65, D75|Cs5],
	 [C16, C26, C36, C46, D56, C66, D76|Cs6],
	 [C17, C27, C37, C47, C57, D67, D77|Cs7],
	 [D18, D28, D38, D48, D58, D68, Self|Cs8]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C77, C76, C75, C74, C73, C72, C71],
			      [D77, D76, D75, D74, D73, D72, D71], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C68, C58, C48, C38, C28, C18],
			      [D68, D58, D48, D38, D28, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C67, C56, C45, C34, C23, C12],
			      [D67, D56, D45, D34, D23, D12], Flipped),
	Flipped == true.
place_sub8(1, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, space],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[D11, D21, D31, D41, D51, D61, D71, Self],
	 [C12, C22, C32, C42, C52, C62, D72, D82],
	 [C13, C23, C33, C43, C53, D63, C73, D83],
	 [C14, C24, C34, C44, D54, C64, C74, D84],
	 [C15, C25, C35, D45, C55, C65, C75, D85],
	 [C16, C26, D36, C46, C56, C66, C76, D86],
	 [C17, D27, C37, C47, C57, C67, C77, D87],
	 [D18, C28, C38, C48, C58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C82, C83, C84, C85, C86, C87, C88],
			      [D82, D83, D84, D85, D86, D87, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C72, C63, C54, C45, C36, C27, C18],
			      [D72, D63, D54, D45, D36, D27, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C71, C61, C51, C41, C31, C21, C11],
			      [D71, D61, D51, D41, D31, D21, D11], Flipped),
	Flipped == true.
place_sub8(2, Self, Opponent,
	[Cs1,
	 [C12, C22, C32, C42, C52, C62, C72, space],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[Cs1,
	 [D12, D22, D32, D42, D52, D62, D72, Self],
	 [C13, C23, C33, C43, C53, C63, D73, D83],
	 [C14, C24, C34, C44, C54, D64, C74, D84],
	 [C15, C25, C35, C45, D55, C65, C75, D85],
	 [C16, C26, C36, D46, C56, C66, C76, D86],
	 [C17, C27, D37, C47, C57, C67, C77, D87],
	 [C18, D28, C38, C48, C58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C83, C84, C85, C86, C87, C88],
			      [D83, D84, D85, D86, D87, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C73, C64, C55, C46, C37, C28],
			      [D73, D64, D55, D46, D37, D28], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C72, C62, C52, C42, C32, C22, C12],
			      [D72, D62, D52, D42, D32, D22, D12], Flipped),
	Flipped == true.
place_sub8(3, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73, space],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[C11, C21, C31, C41, C51, D61, C71, D81],
	 [C12, C22, C32, C42, C52, C62, D72, D82],
	 [D13, D23, D33, D43, D53, D63, D73, Self],
	 [C14, C24, C34, C44, C54, C64, D74, D84],
	 [C15, C25, C35, C45, C55, D65, C75, D85],
	 [C16, C26, C36, C46, D56, C66, C76, D86],
	 [C17, C27, C37, D47, C57, C67, C77, D87],
	 [C18, C28, D38, C48, C58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C84, C85, C86, C87, C88],
			      [D84, D85, D86, D87, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C82, C81],
			      [D82, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C74, C65, C56, C47, C38],
			      [D74, D65, D56, D47, D38], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C73, C63, C53, C43, C33, C23, C13],
			      [D73, D63, D53, D43, D33, D23, D13], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C72, C61],
			      [D72, D61], Flipped),
	Flipped == true.
place_sub8(4, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74, space],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[C11, C21, C31, C41, D51, C61, C71, D81],
	 [C12, C22, C32, C42, C52, D62, C72, D82],
	 [C13, C23, C33, C43, C53, C63, D73, D83],
	 [D14, D24, D34, D44, D54, D64, D74, Self],
	 [C15, C25, C35, C45, C55, C65, D75, D85],
	 [C16, C26, C36, C46, C56, D66, C76, D86],
	 [C17, C27, C37, C47, D57, C67, C77, D87],
	 [C18, C28, C38, D48, C58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C85, C86, C87, C88],
			      [D85, D86, D87, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C83, C82, C81],
			      [D83, D82, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C75, C66, C57, C48],
			      [D75, D66, D57, D48], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C74, C64, C54, C44, C34, C24, C14],
			      [D74, D64, D54, D44, D34, D24, D14], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C73, C62, C51],
			      [D73, D62, D51], Flipped),
	Flipped == true.
place_sub8(5, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75, space],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[C11, C21, C31, D41, C51, C61, C71, D81],
	 [C12, C22, C32, C42, D52, C62, C72, D82],
	 [C13, C23, C33, C43, C53, D63, C73, D83],
	 [C14, C24, C34, C44, C54, C64, D74, D84],
	 [D15, D25, D35, D45, D55, D65, D75, Self],
	 [C16, C26, C36, C46, C56, C66, D76, D86],
	 [C17, C27, C37, C47, C57, D67, C77, D87],
	 [C18, C28, C38, C48, D58, C68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C86, C87, C88],
			      [D86, D87, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C84, C83, C82, C81],
			      [D84, D83, D82, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C76, C67, C58],
			      [D76, D67, D58], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C75, C65, C55, C45, C35, C25, C15],
			      [D75, D65, D55, D45, D35, D25, D15], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C74, C63, C52, C41],
			      [D74, D63, D52, D41], Flipped),
	Flipped == true.
place_sub8(6, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76, space],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58, C68, C78, C88]],
	[[C11, C21, D31, C41, C51, C61, C71, D81],
	 [C12, C22, C32, D42, C52, C62, C72, D82],
	 [C13, C23, C33, C43, D53, C63, C73, D83],
	 [C14, C24, C34, C44, C54, D64, C74, D84],
	 [C15, C25, C35, C45, C55, C65, D75, D85],
	 [D16, D26, D36, D46, D56, D66, D76, Self],
	 [C17, C27, C37, C47, C57, C67, D77, D87],
	 [C18, C28, C38, C48, C58, D68, C78, D88]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C87, C88],
			      [D87, D88], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C85, C84, C83, C82, C81],
			      [D85, D84, D83, D82, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C77, C68],
			      [D77, D68], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C76, C66, C56, C46, C36, C26, C16],
			      [D76, D66, D56, D46, D36, D26, D16], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C75, C64, C53, C42, C31],
			      [D75, D64, D53, D42, D31], Flipped),
	Flipped == true.
place_sub8(7, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77, space]|Rest],
	[[C11, D21, C31, C41, C51, C61, C71, D81],
	 [C12, C22, D32, C42, C52, C62, C72, D82],
	 [C13, C23, C33, D43, C53, C63, C73, D83],
	 [C14, C24, C34, C44, D54, C64, C74, D84],
	 [C15, C25, C35, C45, C55, D65, C75, D85],
	 [C16, C26, C36, C46, C56, C66, D76, D86],
	 [D17, D27, D37, D47, D57, D67, D77, Self]|Rest]) :-
	flip_line_if_possible(Self, Opponent,
			      [C86, C85, C84, C83, C82, C81],
			      [D86, D85, D84, D83, D82, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C77, C67, C57, C47, C37, C27, C17],
			      [D77, D67, D57, D47, D37, D27, D17], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C76, C65, C54, C43, C32, C21],
			      [D76, D65, D54, D43, D32, D21], Flipped),
	Flipped == true.
place_sub8(8, Self, Opponent,
	[[C11, C21, C31, C41, C51, C61, C71, C81],
	 [C12, C22, C32, C42, C52, C62, C72, C82],
	 [C13, C23, C33, C43, C53, C63, C73, C83],
	 [C14, C24, C34, C44, C54, C64, C74, C84],
	 [C15, C25, C35, C45, C55, C65, C75, C85],
	 [C16, C26, C36, C46, C56, C66, C76, C86],
	 [C17, C27, C37, C47, C57, C67, C77, C87],
	 [C18, C28, C38, C48, C58, C68, C78, space]],
	[[D11, C21, C31, C41, C51, C61, C71, D81],
	 [C12, D22, C32, C42, C52, C62, C72, D82],
	 [C13, C23, D33, C43, C53, C63, C73, D83],
	 [C14, C24, C34, D44, C54, C64, C74, D84],
	 [C15, C25, C35, C45, D55, C65, C75, D85],
	 [C16, C26, C36, C46, C56, D66, C76, D86],
	 [C17, C27, C37, C47, C57, C67, D77, D87],
	 [D18, D28, D38, D48, D58, D68, D78, Self]]) :-
	flip_line_if_possible(Self, Opponent,
			      [C87, C86, C85, C84, C83, C82, C81],
			      [D87, D86, D85, D84, D83, D82, D81], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C78, C68, C58, C48, C38, C28, C18],
			      [D78, D68, D58, D48, D38, D28, D18], Flipped),
	flip_line_if_possible(Self, Opponent,
			      [C77, C66, C55, C44, C33, C22, C11],
			      [D77, D66, D55, D44, D33, D22, D11], Flipped),
	Flipped == true.
