diff --git a/BastetBlockChooser.hpp.orig b/BastetBlockChooser.hpp.orig new file mode 100644 index 0000000..7ee3b7c --- /dev/null +++ b/BastetBlockChooser.hpp.orig @@ -0,0 +1,111 @@ +/* + Bastet - tetris clone with embedded bastard block chooser + (c) 2005-2009 Federico Poloni minus 37 + + 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 3 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, see . + */ + +#ifndef BASTET_BLOCK_CHOOSER_HPP +#define BASTET_BLOCK_CHOOSER_HPP + +#include "BlockChooser.hpp" + +#include "Well.hpp" + +#include +#include + +namespace Bastet{ + + static const long GameOverScore=-1000; //bogus score assigned to combinations which cause game over + +// declared in Well.hpp + long Evaluate(const Well *w, int extralines=0); //assigns a score to a position w + a number of extra lines deleted while getting there + + typedef BlockPosition Vertex; + + //generic visitor that "does something" with a possible drop position + class WellVisitor{ + public: + WellVisitor(){} + virtual void Visit(BlockType b, const Well *well, Vertex v){}; + virtual ~WellVisitor(){}; + }; + + //for each block type, drops it (via a BestScoreVisitor) and sees which block reaches the best score along the drop positions + class RecursiveVisitor: public WellVisitor{ + public: + RecursiveVisitor(); + virtual ~RecursiveVisitor(); + virtual void Visit(BlockType b, const Well *well, Vertex v); + const boost::array &GetScores() const{return _scores;} + private: + typedef boost::array ScoresList; + ScoresList _scores; + }; + + //returns the max score over all drop positions + class BestScoreVisitor: public WellVisitor{ + public: + explicit BestScoreVisitor(int bonusLines=0); + virtual ~BestScoreVisitor(); + virtual void Visit(BlockType b, const Well *well, Vertex v); + long GetScore() const{return _score;} + private: + long _score; + int _bonusLines; + }; + + /** + * Tries to drop a block in all possible positions, and invokes the visitor on each one + */ + class Searcher{ + public: + Searcher(BlockType b, const Well *well, Vertex v, WellVisitor *visitor); + private: + boost::unordered_set _visited; + //std::set _visited; ^^ the above is more efficient, we need to do many inserts + BlockType _block; + const Well *_well; + WellVisitor *_visitor; + void DFSVisit(Vertex v); + }; + + class BastetBlockChooser: public BlockChooser{ + public: + BastetBlockChooser(); + virtual ~BastetBlockChooser(); + virtual Queue GetStartingQueue(); + virtual BlockType GetNext(const Well *well, const Queue &q); + /** + * computes "scores" of the candidate next blocks by dropping them in all possible positions and choosing the one that has the least max_(drop positions) Evaluate(well) + */ + boost::array ComputeMainScores(const Well *well, BlockType currentBlock); + + private: + + }; + + //block chooser similar to the older bastet versions, does not give a block preview + class NoPreviewBlockChooser:public BlockChooser{ + public: + NoPreviewBlockChooser(); + virtual ~NoPreviewBlockChooser(); + virtual Queue GetStartingQueue(); + virtual BlockType GetNext(const Well *well, const Queue &q); + }; + +} + +#endif //BASTET_BLOCK_CHOOSER_HPP diff --git a/BastetBlockChooser.hpp.rej b/BastetBlockChooser.hpp.rej new file mode 100644 index 0000000..c43b1cd --- /dev/null +++ b/BastetBlockChooser.hpp.rej @@ -0,0 +1,36 @@ +--- BastetBlockChooser.hpp 2014-05-29 13:47:50.000000000 -0500 ++++ BastetBlockChooser.hpp 2017-02-22 08:16:54.549988291 -0600 +@@ -75,7 +85,7 @@ + public: + Searcher(BlockType b, const Well *well, Vertex v, WellVisitor *visitor); + private: +- std::tr1::unordered_set _visited; ++ std::unordered_set _visited; + //std::set _visited; ^^ the above is more efficient, we need to do many inserts + BlockType _block; + const Well *_well; +--- BastetBlockChooser.hpp~ 2022-06-03 10:38:37.473244214 -0500 ++++ BastetBlockChooser.hpp 2022-06-03 10:41:11.948938690 -0500 +@@ -23,10 +23,21 @@ + + #include "Well.hpp" + +-#include ++#include + #include + #include + ++//boilerplate to use boost::hash as std::hash ++namespace std{ ++ template<> struct hash{ ++ size_t operator()(const Bastet::BlockPosition &fb) const{ ++ static boost::hash h; ++ return h(fb); ++ } ++ }; ++ } ++ ++ + namespace Bastet{ + + static const long GameOverScore=-1000; //bogus score assigned to combinations which cause game over diff --git a/Ui.cpp b/Ui.cpp index 867f33a..3ea479f 100644 --- a/Ui.cpp +++ b/Ui.cpp @@ -183,7 +183,7 @@ namespace Bastet{ BorderedWindow w(d.y,d.x); wattrset((WINDOW *)w,COLOR_PAIR(20)); - mvwprintw(w,0,0,message.c_str()); + mvwprintw(w,0,0,"%s",message.c_str()); w.RedrawBorder(); wrefresh(w); PrepareUiGetch(); @@ -200,7 +200,7 @@ namespace Bastet{ d.y+=3; BorderedWindow w(d.y,d.x); wattrset((WINDOW *)w,COLOR_PAIR(20)); - mvwprintw(w,0,0,message.c_str()); + mvwprintw(w,0,0,"%s",message.c_str()); w.RedrawBorder(); wrefresh(w); PrepareUiGetch(); @@ -221,7 +221,7 @@ namespace Bastet{ BorderedWindow w(d.y,d.x); wattrset((WINDOW *)w,COLOR_PAIR(20)); - mvwprintw(w,0,0,message.c_str()); + mvwprintw(w,0,0,"%s",message.c_str()); w.RedrawBorder(); wrefresh(w); PrepareUiGetch(); @@ -239,7 +239,7 @@ namespace Bastet{ BorderedWindow w(d.y,d.x); wattrset((WINDOW *)w,COLOR_PAIR(20)); for(size_t i=0;i