Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pseudocode Writing Help! Working on programming a Tic Tac Toe game as a group. My contribution to the task is to determine how to approach

Pseudocode Writing Help!

Working on programming a Tic Tac Toe game as a group. My contribution to the task is to determine how to approach the player input (X's and O's) of the game. I hope to portray it as each player enters a number designated on the 'grid/gameboard' (player types number 1-9 to show their respective letter replaces that square in the grid), rather than plotting coordinates (row#, column#).

In a way I have started my portion working somewhat backward, making a semi-useable source code in C++. The assignment, however, requires that I also write the pseudo-code as well as a flowchart, which I feel, are not my strong points (pseudo much more concerning than the flowchart design). Given that my 'grid/gameboard' has been identified by 'square[#], the following C++ language is what I have so far as my contribution:

void changeSpot(int value, string letter) {

if (value == 1 && square[1] == "1") {

square[1] = letter;

}

else if (value == 2 && square[2] == "2") {

square[2] = letter;

}

else if (value == 3 && square[3] == "3") {

square[3] = letter;

}

else if (value == 4 && square[4] == "4") {

square[4] = letter;

}

else if (value == 5 && square[5] == "5") {

square[5] = letter;

}

else if (value == 6 && square[6] == "6") {

square[6] = letter;

}

else if (value == 7 && square[7] == "7") {

square[7] = letter;

}

else if (value == 8 && square[8] == "8") {

square[8] = letter;

}

else if (value == 9 && square[9] == "9") {

square[9] = letter;

}

else {

cout << "The spot you entered does not exit or already has already been taken" << endl;

playerTurn--;

}

int playGame() {

drawTable();

int p1, p2;

while (true) {

if (playerTurn % 2 == 1) {

cout << "Player 1 it's your turn" << endl;

cin >> p1;

changeSpot(p1, letter "X");

if (playerTurn % 2 == 0) {

cout << "Player 2 it's your turn" << endl;

cin >> p2;

changeSpot(p2, letter "O");

}

For the pseudocode, I know I have to find a way to declare strings for the integers, the letters being used ("X" and "O"), and I'm guessing maintaining the constant square[#], but I get lost on the IF/Else If on how to write it in pseudocode. Here Is what I have so far below:

mainFunction playerInput

Declare string integers 0,1,2,3,4,5,6,7,8,9

Declare constant letters "X", "O"

Declare constant p1, p2

Declare p1 = Player 1

Declare p2 = Player 2

Declare constant square //named grid

function changeSpot

function playerTurn

|

|

Display "Player 1. It is Your Turn: "

Enter string integer 0-9

|

|

Display "Player 2. It is Your Turn: "

Enter string integer 0-9

|

|

End mainFunction

I am more than likely overthinking this to the point I'm frying my brain pretty much every time I re-evaluate this. Not sure which loop would work in each function.

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

\f\f\f\f\f\f\f\f\f\f

Answered: 1 week ago

Question

What were the causes of the Industrial Revolution in England ?

Answered: 1 week ago