Exemplo n.º 1
0
	def pvp(self):
		for i in range(9):
			TTT_graphic.clrscr()
			TTT_graphic.display(self.board)
			
			# prompt the user to place a self.mark
			# input validation: input must be a number (1 to 9)
			self.ox = input('\t' + self.turn + ' self.turn: ')
			while not self.ox.isdecimal():
				self.ox = input('\t' + self.turn + ' self.turn: ')
			# input validation: cannot overplace another self.mark
			while not TTT_logic.putOX(self.board, self.ox):
				print('\tYou cannot place your self.mark there.')
				self.ox = input('\t' + self.turn + ' self.turn: ')
			# set self.mark
			self.board[self.ox] = self.turn
			# check for wins
			if TTT_logic.win(self.board):
				TTT_graphic.clrscr()
				TTT_graphic.display(self.board)
				print('\tPlayer ' + self.turn + ' won!')
				exit()
			# alter self.turns
			self.turn = self.mark[1] if self.turn=='X' else self.mark[2]

		TTT_graphic.clrscr()
		TTT_graphic.display(self.board)
		print('\tDraw\n')
Exemplo n.º 2
0
	def pvda(self):
		for i in range(9):
			TTT_graphic.clrscr()
			TTT_graphic.display(self.board)
					
			if self.turn == 'O':
				# prompt the user to place a self.mark
				# input validation: input must be a number (1 to 9)
				self.ox = input('\t' + self.turn + ' turn: ')
				while not self.ox.isdecimal():
					self.ox = input('\t' + self.turn + ' turn: ')

				# input validation: cannot overplace another self.mark
				while not TTT_logic.putOX(self.board, self.ox):
					print('\tYou cannot place your self.mark there.')
					self.ox = input('\t' + self.turn + ' self.turn: ')

				# set self.mark
				self.board[self.ox] = self.turn

				# check for wins
				if TTT_logic.win(self.board):
					TTT_graphic.clrscr()
					TTT_graphic.display(self.board)
					print('\tPlayer ' + self.turn + ' won!')
					exit()

				# alter self.turns
				self.turn = 'X'
			else:
				# randomly pick a spot
				self.ox = str(randint(1,9))
				while not TTT_logic.putOX(self.board, self.ox):
					self.ox = str(randint(1,9))

				# set mark
				self.board[self.ox] = self.turn

				# check for AI wins
				if TTT_logic.win(self.board):
					TTT_graphic.clrscr()
					TTT_graphic.display(self.board)
					print('\tDumb AI won!')
					exit()

				# alter the turn
				self.turn = 'O'

		TTT_graphic.clrscr()
		TTT_graphic.display(self.board)
		print('\tDraw\n')
Exemplo n.º 3
0
import TTT as Game
import TTT_graphic
from sys import exit

menu = [0,1,2,3]

ttt = Game.TTT()
select = TTT_graphic.menu()

while select not in menu:
	select = int(input('> '))

if select==0:
	exit()
elif select==1:
	ttt.pvp()
elif select==2:
	ttt.pvda()
else:
	ttt.pvpa()