Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

DS2501: Lab - Let’s play tic-tac-toe. Profs. Rachlin & Park Fall 2021 Deadline: September 23 @ 11:59pm ET/Boston Work on the problems described below, and instructors/TAs will be around for help and...

1 answer below »
DS2501: Lab - Let’s play tic-tac-toe.
Profs. Rachlin & Park
Fall 2021
Deadline: September 23 @ 11:59pm ET/Boston
Work on the problems described below, and instructors/TAs will be around fo
help and questions.
Labs are graded on a 0–5 scale. Full credit is given for demonstration of partic-
ipation and effort on the lab assignment. Submit your work on Gradescope by
11:59pm EST on Thursday.
Lab Problem: Tic-Tac-Toe
Create a 3x3 tic-tac-toe board using a NumPy a
ay. Every cell should be
claimed by player X, player O, or still be blank (you can represent these values
as numbers instead of strings... see the hint below).
Implement a function that takes a board as a parameter and tests whether the
winner is X, O, or DRAW. A player wins when they have 3-in-a-row vertically,
diagonally, or horizontally. Your main should simply test your function by
calling it with a few different boards.
Hint: You can apply some clever shortcuts if you represent X, O, and Blank
with numeric values. The NumPy methods min, max and sum can come in
handy here. Think about summing by column or row.
Too easy? Keep going...
If you found the problem too easy, try a few tic-tac-toe variants on this problem.
Here are some ideas to get you started:
• Modify your code to generate random board positions.
• If there are blank spaces in the board, count up the number of ways that
X or O could win.
• Modify your function to work on any n× n board
• create an AI that plays tic-tac-toe. That’s an automatic 5!
1
Answered Same Day Sep 22, 2021

Solution

Neha answered on Sep 23 2021
152 Votes
91790 - tic tac python/game.py
import numpy as np
import random
# in the following code, I have created a Tic Tac Toe game.
#in this game computer is one of the player.
#the user needs to enter the location where he wants to mark
def initialize():
global board_a
ay
global tutorial_a
ay
global user_numbe
global computer_numbe

# 0's will be used for O's
# 1's will be used for X's
# 3's will be used for placeholders for blank spots
board_a
ay = np.a
ay([[3, 3, 3],
[3, 3, 3],
[3, 3, 3]])
tutorial_a
ay = np.a
ay([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# random number generator to see who goes first with X's
toss = np.random.randint(0, 2)
if toss == 0:
user_number = 0
computer_number = 1
print("Computer goes first. Your letter is O.")
comp_turn()

elif toss == 1:
user_number = 1
computer_number = 0
print("You go first. Your letter is X.")
user_turn()

# the following method will be used to convert numpy a
ay into a visual ASCII board.
def display_board():
board_list = []

internal_a
ay =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here