Question
c++ the code wont compile please help 5 (**). Hitori is a simple puzzle game played on an N N grid of positive integers. The
c++ the code wont compile please help
5 (**). Hitori is a simple puzzle game played on an N N grid of positive integers. The idea is simply to cross out integers in the grid (as few as possible) so that: Any given number appears at most once in any given column or row; COSC 2436 S20 7 The remaining (unerased) numbers form a single connected group of squares, so that any unerased square is reachable from any other unerased square by a path of unerased squares that are adjacent horizontally or vertically; If a square is erased, its adjacent horizontal and vertical neighbors are not erased. So, given the initial grid (1), below, grid (2)is a solution. The other grids are not solutions for various reasons: (3)has two adjacent squares erased, (4)erases more squares than needed, and (5)breaks the unerased squares into unconnected groups. Of course, (1)itself is not a solution because it has duplicate numbers in several rows and columns. 1 2 5 3 1 2 5 3 1 2 5 3 1 2 5 3 1 2 5 3 4 2 2 2 4 2 2 2 4 2 2 2 4 2 2 2 4 2 2 2 3 6 3 5 3 6 3 5 3 6 3 5 3 6 3 5 3 6 3 5 2 4 5 1 2 4 5 1 2 4 5 1 2 4 5 1 2 4 5 1 (1) (2) (3) (4) (5) Write a program that, given such a grid, finds a solution satisfying the stated criteria. The input will come from the keyboard. Error check for positive board sizes from 4 to 15 only and check for a square matrix on input. Assume only one solution to a board. Let the user have the option of running the program as many times if desired (check input). Output the solved grid with the erased cells with @'s and two spaces between each value. Use any data structure of your choice. Refer to the sample output below. Sample Run: Enter the board size: 8 Enter a Hitori puzzle: 4 8 1 6 3 2 5 7 3 6 7 2 1 6 5 4 2 3 4 8 2 8 6 1 4 1 6 5 7 7 3 5 7 2 3 1 8 5 1 2 3 5 6 7 3 1 8 4 6 4 2 3 5 4 7 8 8 7 1 4 2 3 5 6 Enter the board size: 4 Enter a Hitori puzzle: 1 2 5 3 4 2 2 2 3 6 3 5 2 4 5 1 Solved board: @ 8 @ 6 3 2 @ 7 3 6 7 2 1 @ 5 4 @ 3 4 @ 2 8 6 1 4 1 @ 5 7 @ 3 @ 7 @ 3 @ 8 5 1 2 @ 5 6 7 @ 1 8 @ 6 @ 2 3 5 4 7 8 8 7 1 4 @ 3 @ 6 Run again (Y/N)? y Solved board: 1 2 5 3 4 @ 2 @ @ 6 3 5 2 4 @ 1 Run again (Y/N)? N Name the program: HitoriXX.java or HitoriXX.cpp, where XX are your initials
#include
#include
#include
#include
#include
#include
#include "hitori.h"
using namespace std;
ostream& operator
switch(d) {
case Cell::none:
return os
case Cell::black:
return os
case Cell::white:
return os
default:
return os
}
}
void Cell::print() {
string separator = ", ";
cout number
state
}
void Action::print() {
string separator = ", ";
cout x
"y " y
"state " state
}
//////////////////////////////////////////////////
Matrix::Matrix(int n) {
this->n = n;
data.resize(n*n);
for(size_t i = 1; i n; ++i)
{
this->data[i].setNumber(0);
}
}
void Matrix::print() {
for(size_t i = 0; i n; ++i)
this->data[i].print();
}
Cell::State Matrix::getState(size_t x, size_t y) {
size_t index = x * this->n + y;
return this->data[index].getState();
}
void Matrix::setState( size_t x, size_t y, Cell::State newState) {
size_t index = x * this->n + y;
this->data[index].setState(newState);
}
int Matrix::getNumber(size_t x, size_t y) {
size_t index = x * this->n + y;
return this->data[index].getNumber();
}
void Matrix::setNumber( size_t x, size_t y, int newValue) {
size_t index = x * this->n + y;
this->data[index].setNumber(newValue);
}
bool Matrix::repeatedInColumn(size_t col, int value) {
size_t count = 0;
assert( col n );
for(size_t i = 0; i n; ++i)
if (this->getNumber(i, col))
count++;
return count > 1;
}
bool Matrix::repeatedInRow( size_t row, int value) {
size_t count = 0;
assert( row n );
for(size_t j = 0; j n; ++j)
if (this->getNumber( row, j))
count++;
return count > 1;
}
// TODO: Check the functioning of the stream classes
// change the signature of the method, so that it gets an input stream
Matrix Matrix::newFromStream(std::istream &ist) {
string s;
int n = 0;
int k = 0;
int j = 0;
// read first line and determine how many numbers there are
getline( ist, s );
istringstream iss( s, istringstream::in);
while ( iss >> k)
n++;
// initialize m
Matrix m( n );
do {
istringstream iss( s, istringstream::in);
for( size_t i = 0; i
iss >> k;
m.setNumber(j,i,k);
}
getline( ist, s );
} while ( (++j)
return m;
}
/*
*
*/
int main() {
// Matrix *x = Matrix::newFromStream(cin);
Matrix m = Matrix::newFromStream(cin);
m.print();
// x->print();
//
// cout repeatedInRow(0,2)
// cout repeatedInColumn(0,2)
// solve the puzzle
}
5 (**). Hitori is a simple puzzle game played on an N * N grid of positive integers. The idea is simply to cross out integers in the grid (as few as possible) so that: Any given number appears at most once in any given column or row; COSC 2436 S20 The remaining (unerased) numbers form a single connected group of squares, so that any unerased square is reachable from any other unerased square by a path of unerased squares that are adjacent horizontally or vertically, If a square is erased, its adjacent horizontal and vertical neighbors are not erased. So, given the initial grid (1), below, grid (2)is a solution. The other grids are not solutions for various reasons: (3)has two adjacent squares erased, (4)erases more squares than needed, and (5)breaks the unerased squares into unconnected groups. Of course, (1)itself is not a solution because it has duplicate numbers in several rows and columns. 1 2 5 3 4 2 2 2 36 35 24 51 (1) 1 2 5 3 1 2 5 3 1 2 5 3 1 2 5 3 4 3 23 4 2 2 2 4 3 23 43 23 36 35 36 35 36 35 36 35 2 4 5 1 2 4 5 1 2 4 5 1 2 4 5 1 (2) (3) (4) (5) Write a program that given such a grid, finds a solution satisfying the stated criteria. The input will come from the keyboard. Error check for positive board sizes from 4 to 15 only and check for a square matrix on input. Assume only one solution to a board. Let the user have the option of running the program as many times if desired (check input). Output the solved grid with the erased cells with e's and two spaces between each value. Use any data structure of your choice. Refer to the sample output below. Sample Run: Solved board: Enter the board size: 8 Enter a Hitori puzzle: 2 4 8 1 6 3 2 5 7 36 7 2 1 6 5 4 2 3 4 8 2 8 6 1 4 1 6 5 7 7 3 5 72 31 8 5 1 2 3 5 6 7 31 84 6 4 2 3 5 4 7 8 8 7 1 4 2 3 5 6 @ 3 @ 4 7 @ 6 8 8 6 3 1 @ 5 @ 7 7 4 @ 3 6 2 1 6 2 @ 5 @ 7 3 4 3 1 2 7 8 @ 5 @ 8 @ 5 1 4 3 @ 5 6 3 1 8 7 @ 7 4 1 @ 2 @ 8 6 Run again (Y/N)? y Enter the board size: 4 Enter a Hitori puzzle: Solved board: 1 2 5 3 4 2 2 2 36 35 2 4 5 1 1 4 @ 2 2 @ 6 4 5 2 3 @ 3 @ 5 1 Run again (Y/N)? N Name the program: Hitorixx.java or Hitorixx.cpp, where XX are your initials 5 (**). Hitori is a simple puzzle game played on an N * N grid of positive integers. The idea is simply to cross out integers in the grid (as few as possible) so that: Any given number appears at most once in any given column or row; COSC 2436 S20 The remaining (unerased) numbers form a single connected group of squares, so that any unerased square is reachable from any other unerased square by a path of unerased squares that are adjacent horizontally or vertically, If a square is erased, its adjacent horizontal and vertical neighbors are not erased. So, given the initial grid (1), below, grid (2)is a solution. The other grids are not solutions for various reasons: (3)has two adjacent squares erased, (4)erases more squares than needed, and (5)breaks the unerased squares into unconnected groups. Of course, (1)itself is not a solution because it has duplicate numbers in several rows and columns. 1 2 5 3 4 2 2 2 36 35 24 51 (1) 1 2 5 3 1 2 5 3 1 2 5 3 1 2 5 3 4 3 23 4 2 2 2 4 3 23 43 23 36 35 36 35 36 35 36 35 2 4 5 1 2 4 5 1 2 4 5 1 2 4 5 1 (2) (3) (4) (5) Write a program that given such a grid, finds a solution satisfying the stated criteria. The input will come from the keyboard. Error check for positive board sizes from 4 to 15 only and check for a square matrix on input. Assume only one solution to a board. Let the user have the option of running the program as many times if desired (check input). Output the solved grid with the erased cells with e's and two spaces between each value. Use any data structure of your choice. Refer to the sample output below. Sample Run: Solved board: Enter the board size: 8 Enter a Hitori puzzle: 2 4 8 1 6 3 2 5 7 36 7 2 1 6 5 4 2 3 4 8 2 8 6 1 4 1 6 5 7 7 3 5 72 31 8 5 1 2 3 5 6 7 31 84 6 4 2 3 5 4 7 8 8 7 1 4 2 3 5 6 @ 3 @ 4 7 @ 6 8 8 6 3 1 @ 5 @ 7 7 4 @ 3 6 2 1 6 2 @ 5 @ 7 3 4 3 1 2 7 8 @ 5 @ 8 @ 5 1 4 3 @ 5 6 3 1 8 7 @ 7 4 1 @ 2 @ 8 6 Run again (Y/N)? y Enter the board size: 4 Enter a Hitori puzzle: Solved board: 1 2 5 3 4 2 2 2 36 35 2 4 5 1 1 4 @ 2 2 @ 6 4 5 2 3 @ 3 @ 5 1 Run again (Y/N)? N Name the program: Hitorixx.java or Hitorixx.cpp, where XX are your initials
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started