procedure main() turn := "x" square := list(9, " ") every 1 to 9 do { # draw the board write("-------") every i := 1 to 3 do { write("|", square[i*3-2],"|",square[i*3-1],"|",square[i*3],"|") write("-------") } # read the player's move (X or O) repeat { write("It is player ", turn, "'s turn. Pick a square from 1 to 9:") pick := read() if square[integer(pick)] == " " then break } square[pick] := turn every i := 1 to 3 do { # check horizontally if square[i*3-2]==square[i*3-1]==square[i*3]==("x"|"o") then stop("Player ", square[i*3], " wins") # check vertically if square[i]==square[i+3]==square[i+6]==("x"|"o") then stop("Player ", square[i], " wins") } # check diagonals if square[1]==square[5]==square[9]==("x"|"o") then stop("Player ", square[1], " wins") if square[3]==square[5]==square[7]==("x"|"o") then stop("Player ", square[3], " wins") # advance to the next turn if turn == "x" then turn := "o" else turn := "x" } write("Cat game!") end