示例#1
0
def choose(indices, originalboard, p1, p2):
    """
	Chooses the best move	

	Args:
		indices: a list of (row,col) tuples of optimal 
			empty spaces on the board
		originalboard: the 2d list of chars on which 
			the current player needs to move
		p1: player 1's mark, either 'X' or 'O'
		p2: player 2's mark, either 'O' or 'X'

	Returns:
		the only indice if indices (args) has only one 
		element, the best indice if indices (args) has 
		more than one element

	"""
    if (len(indices) == 1):
        george(9)
        return indices[0]
    elif (len(indices) > 1):
        george(8)
        stats = get_stats(indices, originalboard, p1, p2)
        return compute_stats(stats, indices, originalboard, p2)
示例#2
0
def choose(indices, originalboard, p1, p2):
    """
	Chooses the best move	

	Args:
		indices: a list of (row,col) tuples of optimal 
			empty spaces on the board
		originalboard: the 2d list of chars on which 
			the current player needs to move
		p1: player 1's mark, either 'X' or 'O'
		p2: player 2's mark, either 'O' or 'X'

	Returns:
		the only indice if indices (args) has only one 
		element, the best indice if indices (args) has 
		more than one element

	"""
    if len(indices) == 1:
        george(9)
        return indices[0]
    elif len(indices) > 1:
        george(8)
        stats = get_stats(indices, originalboard, p1, p2)
        return compute_stats(stats, indices, originalboard, p2)
示例#3
0
def get_stats(indices, originalboard, p1, p2):
    """
	Collects and organizes the win, loss, and tie counts 
	returned by the recursion 

	Args:
		indices: a list of (row,col) tuples of optimal 
			empty spaces on the board 
		originalboard: the 2d list of chars on which 
			the current player needs to move
		p1: player 1's mark, either 'X' or 'O'
		p2: player 2's mark, either 'O' or 'X'

	Returns:
		A 2d list of counts, grouping wins together, 
		losses together, and ties together

	"""
    global Owins
    global Xwins
    global ties
    stats = [[], [], []]
    boards = choices_to_boards(indices, originalboard, p1)
    for i in range(0, len(boards)):
        Owins = 0
        Xwins = 0
        ties = 0
        wins = recurse_tree(boards[i], p1, p2)
        if i == (len(boards) - 1):
            george(9)
        stats[0].append(wins[0])
        stats[2].append(wins[2])
        if (wins[1] != 0):
            stats[1].append(wins[1])
        else:
            stats[1].append(1)
    return stats
示例#4
0
def get_stats(indices, originalboard, p1, p2):
    """
	Collects and organizes the win, loss, and tie counts 
	returned by the recursion 

	Args:
		indices: a list of (row,col) tuples of optimal 
			empty spaces on the board 
		originalboard: the 2d list of chars on which 
			the current player needs to move
		p1: player 1's mark, either 'X' or 'O'
		p2: player 2's mark, either 'O' or 'X'

	Returns:
		A 2d list of counts, grouping wins together, 
		losses together, and ties together

	"""
    global Owins
    global Xwins
    global ties
    stats = [[], [], []]
    boards = choices_to_boards(indices, originalboard, p1)
    for i in range(0, len(boards)):
        Owins = 0
        Xwins = 0
        ties = 0
        wins = recurse_tree(boards[i], p1, p2)
        if i == (len(boards) - 1):
            george(9)
        stats[0].append(wins[0])
        stats[2].append(wins[2])
        if wins[1] != 0:
            stats[1].append(wins[1])
        else:
            stats[1].append(1)
    return stats