Esempio n. 1
0
class play:
	p1 = 1
	p2 = -1
	current = p1
	win = 0
	userInput = humanInput()
	b = board(7, 6)

	def __init__(self):
		self.current = self.p1
		self.win = 0

	def begin(self, whoGoesFirst):
		#print "Would you like to go first? Enter: [y/n]"

		#note that if user enters anything other than "n", user goes first
		if (whoGoesFirst == 1):
			valid = True
			self.current = self.p2

		ai = True
		if (ai == True):
			opp = minimaxAI64() #1
			opp2 = miniAIb64() #-1
			depth = 4
			depth2 = 5
		
		while(self.win == 0):
			self.b.update()
			if self.b.boardFull() == True:
				break

			if (ai == True):
				if (self.current < 0):
					#print "--------AI 2's Move-------"
					# 1
					self.b.move(self.current, opp2.chooseMove(self.b, self.current, depth2))
				elif (self.current > 0):

					self.b.move(self.current, opp.chooseMove(self.b, self.current, depth))
					valid = True
					#print "------AI 1's Move------"
					# -1
			elif not ai:
				valid = True

			self.win = self.b.winner(self.current)
			if (valid == False):
				continue
			else:
				self.current = self.current * -1

		self.b.update()
		# update print statement to print ai/user won
		
		#print opp.uctTree
		#opp.writeTree()
		#print"The winner is "
		print self.win
Esempio n. 2
0
class play:
	p1 = 1
	p2 = -1
	current = p1
	win = 0
	userInput = humanInput()
	b = board(7, 6)

	def __init__(self):
		self.current = self.p1
		self.win = 0

	def begin(self):
		print "Would you like to go first? Enter: [y/n]"

		#note that if user enters anything other than "n", user goes first
		if (raw_input() == "n"):
			valid = True
			self.current = self.p2

		ai = True
		if (ai == True):
			opp = uctAI()
			depth = 3
			
		draw = 0	
		while(self.win == 0):
			self.b.update()
			if self.b.boardFull() == True:
				draw = 1
				break
			
			if (ai == True):
				if (self.current < 0):
					print "--------AI's Move-------"
					#print "sdfsfsf"
					self.b.move(self.current, opp.chooseMove(self.b, self.current, depth))
				elif (self.current > 0):
					valid = self.userInput.move(self.b, self.current)
					print "------Human's Move------"
			elif not ai:
				valid = self.userInput.move(self.b, self.current)

			self.win = self.b.winner(self.current)
			if (valid == False):
				continue
			else:
				self.current = self.current * -1

		self.b.update()
		# update print statement to print ai/user won
		
		#print opp.uctTree
		#opp.writeTree()
		if draw == 1:
			print "Draw - No Winner"
		else:	
			print"The winner is "
			print self.win