[Info-vax] escape sequences, cursor positioning
Peter Weaver
info-vax at weaverconsulting.ca
Wed Jan 14 12:34:36 EST 2009
On Jan 11, 3:49 am, acid.fri... at yahoo.de wrote:
> hi everybody,
This thread reminded me of a program I did a long time ago while
teaching an in-house course in DCL programming;
$ create tictactoe.com
$ DECK
$!
$ esc[0,8]==27
$ set term/nowrap
$!
$ start_col = 27
$ start_row = 7
$! A = +1, B = +3, C = +5
$! 1 = +3, 2 = +9, 3 = +15
$!
$ gosub draw_grid
$ gosub init_variables
$ gosub get_players
$ gosub play_game
$ gosub display_winner
$!
$ exit
$draw_grid:
$ call display -'start_row -'start_col "''esc'[J"
$ title_row = -'start_row + 2
$ title_col = -start_col + 11
$ call display 'title_row 'title_col "''esc#3DCL Tic Tac Toe"
$ title_row = -'start_row + 3
$ call display 'title_row 'title_col "''esc#4DCL Tic Tac Toe"
$ call display -1 3 "1 2 3"
$ call display 0 0 "''esc'(0lqqqqqwqqqqqwqqqqqk"
$ call display 1 -2 "A x x x x"
$ call display 2 0 "tqqqqqnqqqqqnqqqqqu"
$ call display 3 -2 "B x x x x"
$ call display 4 0 "tqqqqqnqqqqqnqqqqqu"
$ call display 5 -2 "C x x x x"
$ call display 6 0 "mqqqqqvqqqqqvqqqqqj''esc'(B"
$
$!
$return
$!
$display: subroutine
$ disp_row = start_row + 'p1
$ disp_col = start_col + 'p2
$ line = "''esc'[''disp_row';''disp_col'H''p3'"
$ read sys$command inline /prompt="''line'" /time=0/error=next
$next:
$endsubroutine
$!
$init_variables:
$!
$ have_winner = 0
$!
$ A1 = 0
$ A2 = 0
$ A3 = 0
$ B1 = 0
$ B2 = 0
$ B3 = 0
$ C1 = 0
$ C2 = 0
$ C3 = 0
$!
$ return
$!
$get_players:
$!
$ call display 10 -'start_col "Enter the first player's name:
''esc'[4m "
$ call display 10 32-'start_col ""
$ read sys$command player1 /prompt=""
$!
$ Write sys$output "''esc'[0m''player1' will be using X"
$!
$ call display 12 -'start_col "Enter the second player's name
[COMPUTER]: ''esc'[4m "
$ call display 12 44-'start_col ""
$ read sys$command player2 /prompt=""
$!
$ if player2 .eqs. "" then player2 = "Computer"
$!
$ write sys$output "''esc'[0m''Player2' will be using O"
$!
$return
$!
$play_game:
$!
$ gosub get_player1
$ gosub check_for_winner
$ if have_winner .gt. 0 then return
$ gosub get_player2
$ gosub check_for_winner
$ if have_winner .gt. 0 then return
$!
$ goto play_game
$return ! never executed, but for looks
$!
$get_player1:
$ player = "''Player1'"
$ Letter = "X"
$ Value = 1
$ gosub Play
$return
$!
$get_player2:
$ player = "''Player2'"
$ Letter = "O"
$ Value = 2
$ if player2 .eqs. "Computer"
$ then
$ gosub check_for_move
$ gosub place_mark
$ else
$ gosub Play
$ endif
$!
$return
$!
$play:
$!
$ Call Display 10 -'Start_col "''esc'[J''esc'#6''Player': ''LETTER'"
$ Call Display 11 -'Start_col "''esc'#6''Enter your position using
RowColumn: "
$ read sys$command position /prompt=""
$ position = "''f$edit(position,"Upcase")'"
$ if -
position .nes. "A1" .and. position .nes. "A2" .and.
position .nes. "A3" -
.and. position .nes. "B1" .and. position .nes. "B2" .and.
position .nes. "B3" -
.and. position .nes. "C1" .and. position .nes. "C2" .and.
position .nes. "C3"
$ Then
$ call display 12 -'Start_col -
"Invalid Response, enter A1, A2, A3, B1, B2, B3, C1 ,C2 or
C3."
$ wait 00:00:02
$ call display 12 -'Start_col "''esc'[J"
$ goto play
$ endif
$!
$ if 'position .ne. 0
$ Then
$ call display 12 -'Start_col -
"That position is already taken."
$ wait 00:00:02
$ call display 12 -'Start_col "''esc'[J"
$ goto play
$ endif
$!
$ gosub place_mark
$!
$ return
$!
$place_mark:
$!
$ 'position = 'Value
$ row = (f$cvui(0,8,f$extract(0,1,position)) -64) * 2 - 1
$ col = f$integer(f$extract(1,1,position)) * 3 + -
(f$integer(f$extract(1,1,position)) - 1) * 3
$ call display 'row 'col "''Letter'"
$!
$return
$!
$check_for_move:
$!
$ have_play = 0
$!
$ testpos = "A1"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$ testpos = "A2"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$ testpos = "A3"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$ testpos = "B1"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$ testpos = "B2"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$ testpos = "B3"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$ testpos = "C1"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$ testpos = "C2"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$ testpos = "C3"
$ gosub testpos
$ if have_play .gt. 0 then return
$!
$find_random:
$ random = f$cvtime("",,"HUNDREDTH") / 10
$ position = "''f$element(random,"-","A1-A2-A3-B1-B2-B3-C1-C2-C3-
B2")'"
$ if 'position .ne. 0 then goto find_random
$!
$return
$!
$testpos:
$!
$ if 'testpos .eq. 0
$ then
$ 'testpos = value
$ gosub check_for_winner
$ if have_winner .gt. 0
$ then
$ have_play = 1
$ else
$ 'testpos = value - 1
$ gosub check_for_winner
$ if have_winner .gt. 0
$ then
$ 'testpos = value
$ have_play = 1
$ else
$ 'testpos = 0
$ endif
$ endif
$ position = testpos
$ endif
$!
$return
$check_for_winner:
$!
$ winner = ""
$ HA = 0
$ HB = 0
$ HC = 0
$!
$ V1 = 0
$ V2 = 0
$ V3 = 0
$!
$ DA = 0
$ DC = 0
$!
$ tie_game = 0
$!
$ if a1 .eq. a2 .and. a2 .eq. a3 .and. a1 .ne. 0
$ then
$ HA = 1
$ Winner = Player'a1
$ endif
$ if b1 .eq. b2 .and. b2 .eq. b3 .and. b1 .ne. 0
$ then
$ HB = 1
$ Winner = Player'b1
$ endif
$ if c1 .eq. c2 .and. c2 .eq. c3 .and. c1 .ne. 0
$ then
$ HC = 1
$ Winner = Player'c1
$ endif
$!
$ if a1 .eq. b1 .and. b1 .eq. c1 .and. a1 .ne. 0
$ then
$ V1 = 1
$ Winner = Player'a1
$ endif
$ if a2 .eq. b2 .and. b2 .eq. c2 .and. a2 .ne. 0
$ then
$ V2 = 1
$ Winner = Player'a2
$ endif
$ if a3 .eq. b3 .and. b3 .eq. c3 .and. a3 .ne. 0
$ then
$ V3 = 1
$ Winner = Player'a3
$ endif
$!
$ if a1 .eq. b2 .and. b2 .eq. c3 .and. a1 .ne. 0
$ then
$ DA = 1
$ Winner = Player'a1
$ endif
$ if c1 .eq. b2 .and. b2 .eq. a3 .and. c1 .ne. 0
$ then
$ DC = 1
$ Winner = Player'c1
$ endif
$!
$ if Winner .eqs. "" .and. -
a1 .ne. 0 .and. a2 .ne. 0 .and. a3 .ne. 0 -
.and. b1 .ne. 0 .and. b2 .ne. 0 .and. b3 .ne. 0 -
.and. c1 .ne. 0 .and. c2 .ne. 0 .and. c3 .ne. 0 -
then tie_game = 1
$!
$ have_winner = HA + HB + HC + V1 + V2 + V3 + DA + DC + Tie_game
$
$return
$!
$display_winner:
$!
$ if tie_game .eq. 1
$ then
$ call display 10 -'Start_col "''esc'[J''esc'#3 TIE
GAME"
$ call display 11 -'Start_col "''esc'#4 TIE GAME"
$ else
$ call display 10 -'Start_col "''esc'[J''esc'#3
''Winner' Won!!!"
$ call display 11 -'Start_col "''esc'#4 ''Winner
Won!!!"
$ endif
$!
$ EOD
More information about the Info-vax
mailing list