Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab program, need help (Write sepreate scripts to answer all of the following questions. Tic-tac-toe. Write a program to play tic-tac-toe. For now, the interface

Matlab program, need help (Write sepreate scripts to answer all of the following questions.

image text in transcribed

Tic-tac-toe. Write a program to play tic-tac-toe. For now, the interface will be minimal: you will ask the user for a number (a square) between 1 and 9, and pick one in return. You must make a legal move, and detect when one of you wins. Your gamestate data structure (the way you internally represent the board) should be a nine-element array with empty squares as zero, X (human player) spaces are marked with +1, O (computer) with -1. a. Write a function that asks the user for a move and makes sure it is legal. The input and output should be the gamestate. Show 3 test runs. b. Write a function that determines if either the computer or player has won (return 1 for player, 0 for no winner, -1 for computer). Show 3 test runs. c. Write a function that detects if any valid moves remain. Show 3 test runs. d. Write a function that supplies a computer guess. It can be random or sophisticated - your choice. Show 3 test runs. e. (optional) Write a script that initializes the board and uses a while loop to string together your functions until the game has been won or drawn. Play

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions