Ejemplo n.º 1
0
		def min_val(board, node, y, z, score, depth):
			#initialize temporary board for checking the moves
			b_buf = Board()
			b_buf = board.copy_temp()
			m_buf = b_buf.empty_moves()

			all_val = [] #list of tuples: (succ, score)
			for succ in m_buf:
				b_buf.temp_move(y, succ)
				if b_buf.check_win(y):
					score = depth - 10
					val = (succ, score)
					all_val.append(val)
					b_buf.del_move(y,succ)
				elif b_buf.check_draw(y,z):					
					val =(succ, 0)
					all_val.append(val)
					b_buf.del_move(y,succ)
				else:
					depth = depth + 1
					buf = max_val(b_buf, succ, y, z, score, depth) #(succ, score)
					val = (succ, buf[1]) #succ : the next node, buf[1] : max score generated by max_val
					all_val.append(val)

			minscore = getminscore(all_val)

			return minscore #tuple with minimum score : (next node, minimum score)
Ejemplo n.º 2
0
		def max_val(board, node, y, z, score, depth):
			b_buf = Board()
			b_buf = board.copy_temp()
			m_buf = b_buf.empty_moves()

			all_val = []
			for succ in m_buf:
				b_buf.temp_move(z, succ)
				if b_buf.check_win(z):
					score = 10-depth
					val = (succ, score)
					all_val.append(val)
					b_buf.del_move(z,succ)

				elif b_buf.check_draw(y,z):
					val = (succ, 0)
					all_val.append(val)
					b_buf.del_move(z,succ)

				else:
					depth = depth + 1
					buf = min_val(b_buf, succ, y, z, score, depth)
					val = (succ, buf[1])
					all_val.append(val)
					b_buf.del_move(z,succ)

			maxscore = getmaxscore(all_val)


			return maxscore