Implement some more base types, including basic units. This should be much closer to final interface

This commit is contained in:
Marc Di Luzio 2014-12-16 13:12:54 +00:00
parent 51cdda821d
commit 64f9638352
9 changed files with 174 additions and 74 deletions

View file

@ -1,7 +1,5 @@
#include "board.h"
#include <iostream> // std::cout
// ----------------------------------------------
// Default constructor for the board
@ -10,29 +8,22 @@ CBoard::CBoard( unsigned int c, unsigned int r )
, rows ( r )
, total ( rows * cols )
{
board = new square_t[total];
fill(square_invalid);
board.resize(total,square_empty);
}
CBoard::~CBoard()
{
delete[] board;
}
// Clear the board
void CBoard::clear()
// constructor
CBoard::CBoard( unsigned int c, unsigned int r, vunit_t&& b )
: cols ( c )
, rows ( r )
, total ( rows * cols )
, board ( std::move(b) )
{
fill(square_empty);
}
// Fill the board
void CBoard::fill(square_t v)
{
std::fill(board,board+total,v);
board.resize(total,square_empty);
}
// print get a slot on the board
square_t CBoard::get( unsigned int c, unsigned int r ) const
unit_t CBoard::get( const unsigned int c, const unsigned int r ) const
{
if ( (r >= rows) || (c >= cols) )
return square_invalid;
@ -40,29 +31,13 @@ square_t CBoard::get( unsigned int c, unsigned int r ) const
return board[r*c];
}
// print a board
void CBoard::debug_print() const
// Get a square on the board
unit_t CBoard::set( const unsigned int c, const unsigned int r , const unit_t n )
{
for ( unsigned int r = 0; r < rows; r++ )
{
for ( unsigned int c = 0; c < cols; c++ )
{
std::cout<<(char)board[r*c];
}
std::cout<<std::endl;
}
}
if ( (r >= rows) || (c >= cols) )
return square_invalid;
// Test the board data class
void tests::test_CBoard()
{
CBoard board = CBoard(20,10);
std::cout<<"Blank board"<<std::endl;
board.clear();
board.debug_print();
std::cout<<"Filled board"<<std::endl;
board.fill(48);
board.debug_print();
unit_t old = board[r*c];
board[r*c] = n;
return old;
}