results.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 1999-2005 Eliot
00003  * Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
00004  *          Olivier Teuliere  <ipkiss@via.ecp.fr>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  *****************************************************************************/
00020 
00021 /**
00022  *  \file   results.cc
00023  *  \brief  Search result storage class
00024  *  \author Olivier Teulière & Antoine Fraboulet
00025  *  \date   2005
00026  */
00027 
00028 #include <algorithm>
00029 #include <functional>
00030 
00031 #include "tile.h"
00032 #include "round.h"
00033 #include "board.h"
00034 #include "results.h"
00035 #include "debug.h"
00036 
00037 
00038 struct less_points : public binary_function<const Round&,
00039                      const Round&, bool>
00040 {
00041     bool operator()(const Round &r1, const Round &r2)
00042     {
00043         // We want higher scores first, so we use '>' instead of '<'
00044         return r1.getPoints() > r2.getPoints();
00045     }
00046 };
00047 
00048 
00049 const Round & Results::get(int i) const
00050 {
00051     ASSERT(0 <= i && i < size(), "Results index out of bounds");
00052     return m_rounds[i];
00053 }
00054 
00055 
00056 void Results::search(const Dictionary &iDic, Board &iBoard,
00057                      const Rack &iRack, int iTurn)
00058 {
00059     clear();
00060 
00061     if (iTurn == 0)
00062     {
00063         iBoard.searchFirst(iDic, iRack, *this);
00064     }
00065     else
00066     {
00067         iBoard.search(iDic, iRack, *this);
00068     }
00069 
00070     sort_by_points();
00071 }
00072 
00073 
00074 void Results::sort_by_points()
00075 {
00076     less_points lp;
00077     std::sort(m_rounds.begin(), m_rounds.end(), lp);
00078 }
00079 
00080 /****************************************************************/
00081 /****************************************************************/
00082 
00083 /// Local Variables:
00084 /// mode: c++
00085 /// mode: hs-minor
00086 /// c-basic-offset: 4
00087 /// indent-tabs-mode: nil
00088 /// End:

Generated on Thu Dec 29 02:01:14 2005 for Eliot by  doxygen 1.4.5