Slitherlink Class Reference

Models a slitherlink puzzle and allows an easy manipulation of it (input, output, etc). More...

#include <slitherlink.h>

List of all members.

Public Member Functions

 Slitherlink ()
 Initialises all the attributes to empty/zero values.
void parseInput (std::istream *input)
 Reads a slitherlink grid from the input and assigns all the attributes accordingly.
void setVertex (bool horizontal, unsigned int i, unsigned int j, bool value)
 Assigns a new value to the vertex at coordinate (i,j). The horizontal vertex is assigned if the boolean is true, the vertical one is otherwise.
int getHint (unsigned int i, unsigned int j)
 Returns the hint of coordinates (i,j). If there is no hint at this point, returns -1.
unsigned int getWidth ()
unsigned int getHeight ()
void printNonHintLine (unsigned int i)
 Prints on standard output the line on top of the one containing the hints at line i.
void printSolution ()
 Prints on standard output the solution of the grid according to the content of the nodes attributes.

Private Attributes

std::vector< std::vector< bool > > hVertices
 The horizontal vertices of the grid take value 1 if they are part of the loop, 0 otherwise.
std::vector< std::vector< bool > > vVertices
 The vertical vertices of the grid take value 1 if they are part of the loop, 0 otherwise.
unsigned int width
 The width of the grid containing the hints.
unsigned int height
 The height of the grid containing the hints.
std::vector< std::vector< int > > hints
 The hints contained in the grid.

Detailed Description

Models a slitherlink puzzle and allows an easy manipulation of it (input, output, etc).

See wikipedia for a detailed description of this puzzle.

Definition at line 25 of file slitherlink.h.


Constructor & Destructor Documentation

Slitherlink::Slitherlink ( )

Initialises all the attributes to empty/zero values.

Definition at line 14 of file slitherlink.cpp.


Member Function Documentation

unsigned int Slitherlink::getHeight ( )

Definition at line 92 of file slitherlink.cpp.

int Slitherlink::getHint ( unsigned int  i,
unsigned int  j 
)

Returns the hint of coordinates (i,j). If there is no hint at this point, returns -1.

Parameters:
iThe index of the line.
jThe index of the column.
Returns:
The value of the hint.

Definition at line 72 of file slitherlink.cpp.

unsigned int Slitherlink::getWidth ( )

Definition at line 86 of file slitherlink.cpp.

void Slitherlink::parseInput ( std::istream *  input)

Reads a slitherlink grid from the input and assigns all the attributes accordingly.

Parameters:
inputThe stream where the information must be read.

Definition at line 21 of file slitherlink.cpp.

void Slitherlink::printNonHintLine ( unsigned int  i)

Prints on standard output the line on top of the one containing the hints at line i.

Deals with both horizontal vertices and the vertical ones that cross it.

Parameters:
iThe line we want to print.

Definition at line 101 of file slitherlink.cpp.

void Slitherlink::printSolution ( )

Prints on standard output the solution of the grid according to the content of the nodes attributes.

Definition at line 144 of file slitherlink.cpp.

void Slitherlink::setVertex ( bool  horizontal,
unsigned int  i,
unsigned int  j,
bool  value 
)

Assigns a new value to the vertex at coordinate (i,j). The horizontal vertex is assigned if the boolean is true, the vertical one is otherwise.

Parameters:
horizontalWhich type of vertex should we consider.
iThe index of the line of the node.
jThe index of the column of the node.
valueThe value to give to the node.

Definition at line 51 of file slitherlink.cpp.


Member Data Documentation

unsigned int Slitherlink::height [private]

The height of the grid containing the hints.

For instance if the grid with the hints contains 4 lines, then height=5.

Definition at line 55 of file slitherlink.h.

std::vector<std::vector<int> > Slitherlink::hints [private]

The hints contained in the grid.

If no hints where given for a cell, then it will contain -1.

Definition at line 63 of file slitherlink.h.

std::vector<std::vector<bool> > Slitherlink::hVertices [private]

The horizontal vertices of the grid take value 1 if they are part of the loop, 0 otherwise.

It has one more line than the hints grid.

Definition at line 34 of file slitherlink.h.

std::vector<std::vector<bool> > Slitherlink::vVertices [private]

The vertical vertices of the grid take value 1 if they are part of the loop, 0 otherwise.

It has one more column than the hints grid.

Definition at line 42 of file slitherlink.h.

unsigned int Slitherlink::width [private]

The width of the grid containing the hints.

Definition at line 47 of file slitherlink.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines