Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Summary - Write a C program that allows two people to play a game of Tic-Tac-Toe. The rules are as follows The game is played

Summary - Write a C program that allows two people to play a game of Tic-Tac-Toe. The rules are as follows

The game is played on a 3x3 grid There are two players, each player is assigned either an X or O token

Players take turns placing their tokens into empty squares The first player to get 3 tokens in a row (horizontally, vertically, or diagonally) is the winner

If no player gets 3 tokens in a row, the match is a draw

Required functionality: 1. All the rules listed above must be implemented. 2. If a player selects a square which is already occupied, the program should inform them the

space is filled and require that they indicate a new space. 3. As soon as a player gets 3 tokens in a row, they should be declared the winner and the game should end. In other words, dont wait until all nine moves have been made to determine the winner. 4. The program should operate in a loop, asking the users if they would like to play again after the game is over 5. Any accesses to arrays should be done with pointers and pointer arithmetic ONLY. a. There should be NO square brackets used when indexing into any arrays b. No counters should be used for looping over arrays. You should loop by using pointer arithmetic (see slide 21 of Week 4_ch12_2 powerpoint as example). 6. You must modularize your program by breaking it up into functions. Some example function names are

a. playGame b. printBoard c. checkForWinner

Extra credit functionality: 1. (2pts) If the users decides to play another game, the loser of the previous game should be the first to move. However, if a draw was reached, the first player to move should be the player

who moved second in the previous game

2. (8pts) Generalize the size of the board to be NxN. In order to win, a player must get N tokens in a row. The board size should be set with a #define N at the top of your file. Your source files should also have the name tictactoe_n.c

Input/Output Requirements: 1. Input of player moves (i.e. choosing where to put a token) should follow the row and column format shown in the example above. The user should input them one at a time. Rows and columns should be zero ordered; for a standard 3x3 board, this means valid inputs are [0,1,2].

2. The outcome of the game should be printed exactly as shown in the example. The printf format strings for these are

a. " **** Player %d wins! **** " b." **** The game has ended in a draw **** "

Valid player numbers are 1 and 2

3. When asking the user if they would like to play again, the only options should be y and n 4. You must display the current player to move, and do so exactly as shown in the example. The

printf format string for this is

" Current move: Player %d "

This is important for validating an implementation of extra credit feature #1

5. If implementing extra credit feature #2

a. You must define the board size at the top of your file with #define N b. You must name your source file tictactoe_n.c so that we know you have implemented it

please do it with the extra credit please

thank you

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

2. I appreciate a wide variety of music.

Answered: 1 week ago