/*************************************************************************** * Copyright (C) 2009 by Stefan Bühler * * stbuehler@web.de * * * * 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. * ***************************************************************************/ #ifndef TORUSCHESSTORUSCHESS_H #define TORUSCHESSTORUSCHESS_H #include /** @author Stefan Bühler */ namespace toruschess { typedef enum { BLACK = -1, NOPLAYER = 0, WHITE = 1 } Player; typedef enum { NOPIECE = 0, PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6 } Piece; class Pos { public: Pos(int x, int y) : m_x(x % 8), m_y(y % 8) { } int x() const { return m_x; } int y() const { return m_y; } private: int m_x, m_y; }; class Field { public: Field(); Player player(const Pos &p) const { int pl = place(p); return (pl < 0) ? BLACK : (pl > 0) ? WHITE : NOPLAYER; } Piece piece(const Pos &p) const { return (Piece) qAbs(place(p)); } int place(const Pos &p) const { return m_places[p.y()][p.x()]; } private: int m_places[8][8]; }; class Game : public QObject { Q_OBJECT public: Game(QObject *parent = 0); virtual ~Game(); const Field* field() const { return m_field; } private: Field *m_field; }; } #endif