/*
  crossword -- a crossword game
  Copyright (C) 2000 Falk Hueffner

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the Free
  Software Foundation; either version 2 of the License, or (at your option)
  any later version.
  
  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.
  
  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  Place, Suite 330, Boston, MA 02111-1307 USA

  $Id: Board.hh,v 1.6 2000/11/21 20:07:48 falk Exp $
*/

#ifndef BOARD_HH
#define BOARD_HH

#include <assert.h>
#include <iostream>
#include <vector>

#include "Rules.hh"
#include "Pos.hh"
#include "Move.hh"

class Board {
    friend ostream& operator<<(ostream& out, const Board& b);

public:
    Board() : tiles(vector<Tile>(Rules::numFields())), _empty(true) { }
    Board(istream& in);

    // layout s starting at p in direction d
    void put(const string& s, Pos p, Dir d);
    void apply(const Move& move);

    Tile at(Pos p) const {
	assert(unsigned(p) < tiles.size());
	return tiles[p];
    }
    bool isStartPos(Pos p) const { return _empty && p == Rules::startPos(); }
    bool empty(Pos p) const { return at(p) == EMPTY; }
    void set(Pos p, Tile t) { assert(unsigned(p) < tiles.size()); tiles[p] = t; }

private:
    vector<Tile> tiles;
    bool _empty;
};

#endif

