comp-think / 2019-2020

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2019/2020).
Other
12 stars 3 forks source link

Bonus exercise (AtariGo) #21

Open essepuntato opened 4 years ago

essepuntato commented 4 years ago

Implement the function below in Python, that takes in input the colour of the player who has to play the turn (parameter colour), the sets of coordinates (i.e. sets of tuples) of all the black stones (parameter black) and white stones (parameter white) already positioned on the board, and returns the x, y coordinate (a tuple) of a free intersection where to place a new colour stone. The coordinates of the various positions of the board are those ones defined in "the board" as in the AlphaGo material available online.

def place_stone(colour, black, white):
    # study the board and calculate the
    # best place where to position the stone
    return x, y # the coordinates of the new stone

More info are available at https://doi.org/10.5281/zenodo.2204836.

arcangelo7 commented 4 years ago
import random

def place_stone(color, black, white):
    possible_positions = {(x, y) for x in range(7) for y in range(7)}
    positions_taken = black.union(white)
    output_possible_positions = possible_positions.difference(positions_taken)

    return f"{color}{random.sample(output_possible_positions, 1)}"

color = "black"
black_positions = {(1, 2), (4, 2)}
white_positions = {(2, 4), (4, 4)}

print(place_stone(color, black_positions, white_positions))
# It prints black[(2, 1)], for example