#! /usr/bin/env python """ A simple Monte Carlo solver for Nim http://en.wikipedia.org/wiki/Nim#The_21_game https://class.coursera.org/principlescomputing1-004/wiki/view?page=nim_mc """ import random try: import SimpleGUICS2Pygame.codeskulptor as codeskulptor except ImportError: import codeskulptor codeskulptor.set_timeout(20) MAX_REMOVE = 3 TRIALS = 10000 def evaluate_position(num_items): """ Monte Carlo evalation method for Nim """ return 0 def play_game(start_items): """ Play game of Nim against Monte Carlo bot
""" Mini-max Tic-Tac-Toe Player """ import poc_ttt_gui import poc_ttt_provided as provided # Set timeout, as mini-max can take a long time import SimpleGUICS2Pygame.codeskulptor as codeskulptor codeskulptor.set_timeout(60) # SCORING VALUES - DO NOT MODIFY SCORES = {provided.PLAYERX: 1, provided.DRAW: 0, provided.PLAYERO: -1} def mm_move(board, player): """ Make a move on the board. Returns a tuple with two elements. The first element is the score of the given board and the second element is the desired move as a tuple, (row, col). """ winner = board.check_win() if not winner is None: return SCORES[winner], (-1, -1) best_score, best_move = -2 * SCORES[player], None emty_squares = board.get_empty_squares()