#!/usr/bin/perl -w # ticTacToe.pl use warnings; use strict; my @pieces = (" ") x 9; # value of square. NULL if empty x for x and o for o. my $input; my $outcome; # 1 for win, 2 for loss. 3 for Tie. my $playerPiece; my $aiPiece; my @markers = ("o", "x"); my $totalMarkers = @markers; sub updateScreen{ # To update screen after each move. print " $pieces[6] | $pieces[7] | $pieces[8]\n"; print "-----------\n"; print " $pieces[3] | $pieces[4] | $pieces[5]\n"; print "-----------\n"; print " $pieces[0] | $pieces[1] | $pieces[2]\n"; } sub helpGame{ } system("reset"); # reset screen. print "Welcome to my Tic Tac Toe Game!\n"; print "I hope you like it and have fun\n"; print "BTW, you can't choose who you are...\n"; print "Type quit to quit program. Help for help.\n"; $playerPiece = $markers[rand $totalMarkers]# randomly choose x or o for player. if($playerPiece eq "x"){ $aiPiece = "o"; } else { $aiPiece = "x"; }; print "The player is = $playerPiece\n"; print "the Ai is = $aiPiece\n"; while($outcome == 0){ # main processing loop print "\n"; &updateScreen; print "\n"; $input = ; if($input =~ /[^1-9]/){ # Used to check for input words. if($input eq("quit" || "exit")){ # Checks what word is. print "\n"; print "Bye! Hope you liked it!\n"; print "\n"; exit; } else if($input eq "help") { &helpGame; redo; } else { print "\n"; print "That is invalid input...\n"; redo; } } if($input =~ /[1-9]/){ print "\n"; } }