Updated by
Modified
tic-tac-toe.sql- Ignore whitespace
- select x_moves, o_moves, winning_position, lag(winning_position is not null) over () as win_pos_lag
- from game_with_xo_moves left join winning_positions on x_moves @> winning_position or o_moves @> winning_position
- case when 9 = ANY(x_moves) then 'X' when 9 = ANY(o_moves) then 'O' else '.' end || chr(10) as board,
+select array_to_string(board[1:3] || chr(10) || board[4:6] || chr(10) || board[7:9] || chr(10), '') board,
- values (ARRAY[1, 2, 3]), (ARRAY[4, 5, 6]), (ARRAY[7, 8, 9]), (ARRAY[1, 4, 7]), (ARRAY[2, 5, 8]), (ARRAY[3, 6, 9])
+ values (ARRAY[1, 2, 3]), (ARRAY[4, 5, 6]), (ARRAY[7, 8, 9]), (ARRAY[1, 4, 7]), (ARRAY[2, 5, 8]), (ARRAY[3, 6, 9])
+ select x_moves, o_moves, winning_position, lag(winning_position is not null) over () as win_pos_lag
+ from game_with_xo_moves left join winning_positions on x_moves @> winning_position or o_moves @> winning_position
+ case when 9 = ANY(x_moves) then 'X' when 9 = ANY(o_moves) then 'O' else '.' end || chr(10) as board,
You can clone a snippet to your computer for local editing. Learn more.