Write the following function:
const int MIN_SIZE = 2;
const int MAX_SIZE = 8;
const int UNKNOWN = 0;
const int RED = 1;
const int BLUE = 2;
const char UNKNOWN_LETTER = '-';
const char RED_LETTER = 'X';
const char BLUE_LETTER = 'O';
const string UNKNOWN_STRING = "unknown";
const string RED_STRING = "X";
const string BLUE_STRING = "O";
/**
* Requires: size <= MAX_SIZE and size is a positive even
integer,
* 0
<= row && row < size. The board must be valid.
* Modifies: board, cout
* Effects : This function writes the opposite color in UNKNOWN
squares in row:
* * on
both ends of two consecutive tiles (example 1) in row, and
* * in
the middle between two tiles of the same color in row
*
(example 2)
* If
announce is true, prints out a message for each square
* that
is modified.
*
*
Example:
----
----
*
XX-- becomes XXO-
*
-XX-
OXXO
*
--X-
--X-
*
*
Example:
----
----
*
X-X- becomes XOX-
*
----
----
*
--X-
--X-
* Note : You MUST use mark_square_as() to assign
a color to a square.
* It
will take care of printing out the appropriate message.
* Used In : solve()
*/
void solve_three_in_a_row(int board[MAX_SIZE][MAX_SIZE],
int size,
int row,
bool announce);
You are given:
void mark_square_as(int board[MAX_SIZE][MAX_SIZE],
int size,
int row,
int col,
int color,
bool announce) {
if (announce) {
cout << "marking
(" << row + 1 << ", "
<< static_cast<char>(col + 'A') << ") as ";
if (color == RED)
{
cout << RED_STRING;
} else if (color ==
BLUE) {
cout << BLUE_STRING;
} else {
cout << UNKNOWN_STRING;
}
cout <<
endl;
}
board[row][col] = color;
}
----------------------------------------------------------
I tried coding this myself and I am not sure why I am getting it wrong with mix match output. Below is my code.
void solve_three_in_a_row(int board[MAX_SIZE][MAX_SIZE],
int size,
int row,
bool announce) {
for(int j = 0; j < size; j++) {
if(board[row][j] == 1 && board[row][j+1] == 1) {
if(j - 1 >= 0 && j + 2 <= size) {
mark_square_as(board, size, row, j-1, 2, announce);
mark_square_as(board, size, row, j+2, 2, announce);
}
else if(j + 1 == size && j - 1 >= 0) {
mark_square_as(board, size, row, j-1, 2, announce);
}
else if(j == 0 && j + 2 <= size){
mark_square_as(board, size, row, j+2, 2, announce);
}
}
else if(board[row][j] == 1 && board[row][j+2] == 1) {
mark_square_as(board, size, row, j+1, 2, announce);
}
}
for(int j = 0; j < size; j++) {
if(board[row][j] == 2 && board[row][j+1] == 2) {
if(j - 1 >= 0 && j + 2 <= size) {
mark_square_as(board, size, row, j-1, 1, announce);
mark_square_as(board, size, row, j+2, 1, announce);
}
else if(j + 1 == size && j - 1 >= 0) {
mark_square_as(board, size, row, j-1, 1, announce);
}
else if(j == 0 && j + 2 <= size){
mark_square_as(board, size, row, j+2, 1, announce);
}
}
else if(board[row][j] == 2 && board[row][j+2] == 2) {
mark_square_as(board, size, row, j+1, 1, announce);
}
}
}
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Write the following function: const int MIN_SIZE = 2; const int MAX_SIZE = 8; const int...
Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...
Hello, I am trying to write this program and have received a "Segmentation Fault" error but cannot seem to figure out where. I haven't been able to find it and have been looking for quite a while. The goal is to basically create a version of Conway's Game of Life. I am able to generate a table if the input values for rows and columns are equal, but if they are not I receive a segmentation fault and cannot continue...
I just need a help in replacing player 2 and to make it
unbeatable
here is my code:
#include<iostream>
using namespace std;
const int ROWS=3;
const int COLS=3;
void fillBoard(char [][3]);
void showBoard(char [][3]);
void getChoice(char [][3],bool);
bool gameOver(char [][3]);
int main()
{
char board[ROWS][COLS];
bool playerToggle=false;
fillBoard(board);
showBoard(board);
while(!gameOver(board))
{
getChoice(board,playerToggle);
showBoard(board);
playerToggle=!playerToggle;
}
return 1;
}
void fillBoard(char board[][3])
{
for(int i=0;i<ROWS;i++)
for(int j=0;j<COLS;j++)
board[i][j]='*';
}
void showBoard(char board[][3])
{
cout<<" 1 2 3"<<endl;
for(int i=0;i<ROWS;i++)
{
cout<<(i+1)<<"...
You've been hired by Rugged Robots to complete a C++ console application that controls a robotic floor vacuum. Wayne State software engineers have already developed the following three files: File Description Lab20-01-Key.cpp This is the user application. RuggedRobotLibrary.h This is the library header file. It contains constant declarations and function prototypes. It is included by the other two files. RuggedRobotLibrary.cpp This is the library file. It contains functions that may be used in any user application. This is considered an...
howthe output of the following 4 program segments (a) const int SIZE=8; int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8}; int index; index=0; res = values[index]; for (int j=1; j<SIZE; j++) { if (values[j] > res) { res = values[j]; index = j; cout << index << res << endl; } } cout <<...
how to randomly generate moves until the whole board is filled?. If the board size is c*r, you can only call the random function rand() c*r times (excluding the random function rand() that have been used in the provided code). Below is the code I need to convert. It is manual right now (user inputs numbers until whole board filled). I also have a piece of algorithmn below..but am unsure of how I can use it in the code: //Algorithm...
I wrote program that have to block all moves for player 1, for game TicTacTOE AI, but it is not working. Can someone check what I have not eliminated? #include using namespace std; const int ROWS = 3; const int COLS = 3; int counter = 0; void aITurn(char b[][COLS]); void fillBoard(char board[ROWS][COLS]); void getChoice(char b[][COLS], bool playerToggle); bool gameOver(char b[][COLS]); void showBoard(char board[ROWS][COLS]); int main() { ///main is complete, nothing to do here char board[ROWS][COLS]; bool playerToggle =...
The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() { char board[SIZE]; int player, choice, win, count; char mark; count = 0; // number of boxes marked till now initBoard(board); // start the game player = 1; // default player mark = 'X'; // default mark do { displayBoard(board); cout << "Player " << player << "(" << mark...
Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...
Similar to the Yahtzee project you completed earlier, in order to really understand the artificial intelligence and how to improve it; you must first have a good grasp on the game, its concepts, and its rules. For your first assignment, download the linked file below. This is a .cpp file of the game Tic-Tac-Toe. Tic-Tac-Toe Unzip the file, and run the game. Play a few games and begin to analyze the artificial intelligence that is currently programmed. Then, review the...