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