def play_game(): board, winner = create_board(), 0 while winner == 0: for player in [1, 2]: random_place(board, player) winner = evaluate(board) if winner != 0: break return winner
def play_strategic_game(): board, winner = create_board(), 0 board[1, 1] = 1 while winner == 0: for player in [2, 1]: # use `random_place` to play a game, and store as `board`. # use `evaluate(board)`, and store as `winner`. random_place(board, player) winner = evaluate(board) if winner != 0: break return winner
# Now that players may place their pieces, how will they know they've won? Make a function row_win(board, player) that takes the player (integer), and determines if any row consists of only their marker. Have it return True of this condition is met, and False otherwise. # board is already defined from previous exercises. Call row_win to check if Player 1 has a complete row. # Ex6 import numpy as np from Week2_PythonLibsanConceptsUsedInResearch.ex.ex2 import create_board, place # from Week2_PythonLibsanConceptsUsedInResearch.ex.ex3 import possibilities # from Week2_PythonLibsanConceptsUsedInResearch.ex.ex4 import random_place board = create_board() def row_win(brd, player): winner = False if np.any(np.all(brd == player, axis=1)): return True else: return False if __name__ == '__main__': print(row_win(board, 1))