[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] Changes to eliot/game/game.cpp [antoine-1]
From: |
eliot-dev |
Subject: |
[Eliot-dev] Changes to eliot/game/game.cpp [antoine-1] |
Date: |
Sun, 23 Oct 2005 13:16:32 -0400 |
Index: eliot/game/game.cpp
diff -u /dev/null eliot/game/game.cpp:1.15.2.1
--- /dev/null Sun Oct 23 17:16:32 2005
+++ eliot/game/game.cpp Sun Oct 23 17:16:24 2005
@@ -0,0 +1,184 @@
+/*****************************************************************************
+ * Copyright (C) 1999-2005 Eliot
+ * Authors: Antoine Fraboulet <address@hidden>
+ * Olivier Teuliere <address@hidden>
+ *
+<<<<<<< game.cpp
+=======
+ * $Id: game.cpp,v 1.15.2.1 2005/10/23 17:16:24 afrab Exp $
+ *
+>>>>>>> 1.15
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *****************************************************************************/
+
+/* $Id: game.cpp,v 1.15.2.1 2005/10/23 17:16:24 afrab Exp $ */
+
+/**
+ * \file game.cpp
+ * \brief Eliot game class
+ * \author Antoine Fraboulet & Olivier Teuliere
+ * \date 2002 - 2005
+ */
+
+#include "dic.h"
+#include "dic_search.h"
+#include "tile.h"
+#include "rack.h"
+#include "round.h"
+#include "pldrack.h"
+#include "turn.h"
+#include "results.h"
+#include "player.h"
+#include "ai_percent.h"
+#include "game.h"
+#include "game_factory.h"
+
+#include "debug.h"
+
+
+Game::Game(const Dictionary iDic)
+{
+ m_dic = iDic;
+ m_variant = kNONE;
+ m_currplayer = 0;
+}
+
+
+Game::~Game()
+{
+}
+
+const Player&
+Game::getPlayer(int num) const
+{
+ ASSERT(0 <= num && num < (int)m_players.size(),"Wrong player number");
+ return *(m_players[num]);
+}
+
+void Game::addHumanPlayer()
+{
+ m_players.push_back(new HumanPlayer());
+}
+
+void Game::addAIPlayer()
+{
+ m_players.push_back(new AIPercent(0));
+}
+
+int Game::play(int player, const std::string iCoord, const std::string iWord)
+{
+ return play(player,Coord(iCoord),iWord);
+}
+
+int Game::play(int player, const Coord& iCoord, const std::string &iWord)
+{
+ Round round;
+ checkPlayedWord(iCoord,iWord,round);
+ return play(player,round);
+}
+
+int Game::back(int n)
+{
+ int i;
+ for(i=0; i<n; i++)
+ {
+ back();
+ }
+ return 0;
+}
+
+/*
+ * This function checks whether it is legal to play the given word at the
+ * given coordinates. If so, the function fills a Round object, also given as
+ * a parameter.
+ * Possible return values:
+ * 0: correct word, the Round can be used by the caller
+ * 1: no dictionary set
+ * 2: invalid coordinates (unreadable or out of the board)
+ * 3: word not present in the dictionary
+ * 4: not enough letters in the rack to play the word
+ * 5: word is part of a longer one
+ * 6: word overwriting an existing letter
+ * 7: invalid crosscheck, or word going out of the board
+ * 8: word already present on the board (no new letter from the rack)
+ * 9: isolated word (not connected to the rest)
+ * 10: first word not horizontal
+ * 11: first word not covering the H8 square
+ */
+int Game::checkPlayedWord(Round &oRound)
+{
+ int res;
+ Tile t;
+
+ /* Check the existence of the word */
+ if (Dic_search_word(m_dic, oRound.getWord().c_str()) == 0)
+ return 3;
+
+ /* Check the word position, compute its points,
+ * and specify the origin of each letter (board or rack) */
+ res = m_board.checkRound(oRound, m_history.getSize() == 1);
+ if (res != 0)
+ return res + 4;
+
+ /* Check that the word can be formed with the tiles in the rack:
+ * we first create a copy of the rack, then we remove the tiles
+ * one by one */
+ Rack rack;
+ Player *player = m_players[m_currplayer];
+ player->getCurrentRack().getRack(rack);
+
+ for (int i = 0; i < oRound.getWordLen(); i++)
+ {
+ if (oRound.isPlayedFromRack(i))
+ {
+ if (oRound.isJoker(i))
+ t = Tile::Joker();
+ else
+ t = oRound.getTile(i);
+
+ if (!rack.in(t))
+ {
+ return 4;
+ }
+ rack.remove(t);
+ }
+ }
+ return 0;
+}
+
+int Game::checkPlayedWord(const Coord& iCoord, const std::string &iWord, Round
&oRound)
+{
+ oRound.init();
+ oRound.setCoord(iCoord);
+ oRound.setWord(iWord);
+ return checkPlayedWord(oRound);
+}
+
+int Game::setRack(int player, PlayedRack::set_rack_mode mode, bool check,
std::string rack)
+{
+ int result;
+ PlayedRack newrack;
+
+ newrack = m_players[player]->getCurrentRack();
+ result = newrack.replace(m_bag,mode,rack);
+ m_players[player]->setCurrentRack(newrack);
+ return result;
+}
+
+
+/// Local Variables:
+/// mode: hs-minor
+/// c-basic-offset: 4
+/// End:
- [Eliot-dev] Changes to eliot/game/game.cpp [antoine-1],
eliot-dev <=