In: Computer Science
.
Working code implemented in Python.
Source Code:
from random import *
def list_valid_moves(pos_list, player):
if player == 1:
pos_options = ["12","32","02"]
if player == 2:
pos_options = ["00"]
pos_options.clear()
return pos_options
def suggest_valid_move(pos_list, player):
output = "00"
randomised_list_of_strings = list_valid_moves(pos_list,
player)
if (len(randomised_list_of_strings) == 0 or
randomised_list_of_strings == None):
return output
else:
shuffle(randomised_list_of_strings)
return (randomised_list_of_strings[0])
if __name__ == "__main__":
get_move = suggest_valid_move([1, 1, 0, 1, 2, 2, 1, 2, 2], 2)
print(get_move)
Code & Output Screenshots: