use strict; use warnings; use Switch; use vars qw(@x $end $num $nextmove); sub check { if (($x[0] == $x[1]) && ($x[1] == $x[2])) {if ($num == 0) { print "Player1 won\n"; } else { print "Player2 won\n"; $end = 0;}} elsif (($x[3] == $x[4]) && ($x[4] == $x[5])) {if ($num == 0) {print "Player1 won\n"; } else { print "Player2 won\n"; $end = 0;}} elsif (($x[6] == $x[7]) && ($x[7] == $x[8])) {if ($num == 0) {print "Player1 won\n"; } else { print "Player2 won\n"; $end = 0;}} elsif (($x[0] == $x[3]) && ($x[3] == $x[6])) {if ($num == 0) {print "Player1 won\n"; } else { print "Player2 won\n"; $end = 0;}} elsif (($x[1] == $x[4]) && ($x[4] == $x[7])) {if ($num == 0) {print "Player1 won\n"; } else { print "Player2 won\n"; $end = 0;}} elsif (($x[2] == $x[5]) && ($x[5] == $x[8])) {if ($num == 0) {print "Player1 won\n"; } else { print "Player2 won\n"; $end = 0;}} elsif (($x[0] == $x[4]) && ($x[4] == $x[8])) {if ($num == 0) {print "Player1 won\n"; } else { print "Player2 won\n"; $end = 0;}} elsif (($x[2] == $x[4]) && ($x[4] == $x[6])) {if ($num == 0) {print "Player1 won\n"; } else { print "Player2 won\n"; $end = 0;}} } sub board { system("clear"); print "-------------------------------"; print "| $x[0] | $x[1] | $x[2] |"; print "-------------------------------"; print "| $x[3] | $x[4] | $x[5] |"; print "-------------------------------"; print "| $x[6] | $x[7] | $x[8] |"; print "-------------------------------"; print"\n\n\n"; check(); if ($end == 1) { if ($num == 0) { $num = 1; print "Player 2's turn\n" } else { $num = 0; print "Player 1's turn\n" } } else { print "press Enter to exit: "; $nextmove = ; die } } print "j00 suck, el bastardo!\n"; @x = (" "," "," "," "," "," "," "," "," "); my $i = 1; my ($player1, $player2); $end=1; $num = 0; print "write the name of the players:\nPlayer1 : "; $player1 = ; print "\nPlayer2 : "; $player2 = ; print "\nPlayer1 is X and Player2 is O\n\n"; print 'when is says "which square do you want" the choices are: left, right, down, up, leftup, rightup, leftdown,rightdown'; board(); while ($i != 1) { print "insert next move:\n"; $nextmove = ; switch ($nextmove) { case "leftup" { if ($x[0] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[0] == 'X'; else $x[0] == 'O'; $i = 0 }} case "up" { if ($x[1] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[1] == 'X'; else $x[1] == 'O'; $i = 0 }} case "rightup" { if ($x[2] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[2] == 'X'; else $x[2] == 'O'; $i = 0 }} case "left" { if ($x[3] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[3] == 'X'; else $x[3] == 'O'; $i = 0 }} case "middle" { if ($x[4] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[4] == 'X'; else $x[4] == 'O'; $i = 0 }} case "right" { if ($x[5] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[5] == 'X'; else $x[5] == 'O'; $i = 0 }} case "leftdown" { if ($x[6] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[6] == 'X'; else $x[6] == 'O'; $i = 0 }} case "down" { if ($x[7] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[7] == 'X'; else $x[7] == 'O'; $i = 0 }} case "rightdown" { if ($x[8] <> " ") { print "square already taken, try another\n"; $i = 1; } elsif ($num == 0) { $x[8] == 'X'; else $x[8] == 'O'; $i = 0 }} }