/*************************************************************************** * Copyright (C) 1980-2005 Artur Wiebe * * artur@wiebenet.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. * ***************************************************************************/ #include "humanplayer.h" #include "networkplayer.h" myHumanPlayer::myHumanPlayer(bool white, int rules, const QString& name, bool second_player) : myPlayer(white, rules) { selected = false; undoBoard[0] = -1; m_second = second_player; setName(name); } myHumanPlayer::~myHumanPlayer() { } void myHumanPlayer::yourTurn(Checkers* g) { game = g; } bool myHumanPlayer::fieldClicked(int field_num, bool* select, QString& errmsg) { if(m_second) { if(!m_move.isEmpty()) game->fromString(m_move); field_num = 31 - field_num; } switch(game->item(field_num)) { case MAN1: case KING1: if(!game->canCapture1(field_num) && !game->canMove1(field_num)) { errmsg = tr("Unmovable."); return false; } if(game->checkCapture1() && !game->canCapture1(field_num)) { errmsg = tr("You must capture."); return false; } // Player (re)selects from = field_num; fromField = field_num; selected = true; *select = true; return true; break; case FREE: if(!selected) return true; if(!go(field_num)) return false; // incorrect course // move done - unselect if(selected) *select = false; selected = false; // restore if(m_second) game->fromString(game->toString(true)); emit moveDone(game->toString(true)); break; default: break; } return true; } bool myHumanPlayer::go(int to) { for(int i=0; i<32; i++) undoBoard[i] = game->item(i); return game->go1(from, to); } void myHumanPlayer::undo() { game->setup(undoBoard); } void myHumanPlayer::sendMove(const QString& str) { if(m_second) m_move = str; }