Move the board code out to ui as it's only for board visualisation

This commit is contained in:
Marc Di Luzio 2014-12-16 13:12:58 +00:00
parent a17a9db2ad
commit 2abd4ad832
9 changed files with 39 additions and 13 deletions

43
ui/board.cpp Normal file
View file

@ -0,0 +1,43 @@
#include "board.h"
// ----------------------------------------------
// Default constructor for the board
CBoard::CBoard( unsigned int c, unsigned int r )
: cols ( c )
, rows ( r )
, total ( rows * cols )
{
board.resize(total,square_empty);
}
// constructor
CBoard::CBoard( unsigned int c, unsigned int r, vunitVis_c&& b )
: cols ( c )
, rows ( r )
, total ( rows * cols )
, board ( std::move(b) )
{
board.resize(total,square_empty);
}
// print get a slot on the board
unitVis_c CBoard::get( const unsigned int c, const unsigned int r ) const
{
if ( (r >= rows) || (c >= cols) )
return square_invalid;
return board[r*c];
}
// Get a square on the board
unitVis_c CBoard::set( const unsigned int c, const unsigned int r , const unitVis_c n )
{
if ( (r >= rows) || (c >= cols) )
return square_invalid;
unitVis_c old = board[r*c];
board[r*c] = n;
return old;
}