Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions BastetBlockChooser.hpp.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
Bastet - tetris clone with embedded bastard block chooser
(c) 2005-2009 Federico Poloni <f.polonithirtyseven@sns.it> 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 <http://www.gnu.org/licenses/>.
*/

#ifndef BASTET_BLOCK_CHOOSER_HPP
#define BASTET_BLOCK_CHOOSER_HPP

#include "BlockChooser.hpp"

#include "Well.hpp"

#include <boost/unordered_set.hpp>
#include <boost/functional/hash.hpp>

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<long,7> &GetScores() const{return _scores;}
private:
typedef boost::array<long,7> 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<Vertex> _visited;
//std::set<Vertex> _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<long,7> 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
36 changes: 36 additions & 0 deletions BastetBlockChooser.hpp.rej
Original file line number Diff line number Diff line change
@@ -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<Vertex> _visited;
+ std::unordered_set<Vertex> _visited;
//std::set<Vertex> _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 <boost/tr1/tr1/unordered_set>
+#include <unordered_set>
#include <set>
#include <boost/functional/hash.hpp>

+//boilerplate to use boost::hash as std::hash
+namespace std{
+ template<> struct hash<Bastet::BlockPosition>{
+ size_t operator()(const Bastet::BlockPosition &fb) const{
+ static boost::hash<Bastet::BlockPosition> h;
+ return h(fb);
+ }
+ };
+ }
+
+
namespace Bastet{

static const long GameOverScore=-1000; //bogus score assigned to combinations which cause game over
10 changes: 5 additions & 5 deletions Ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -239,7 +239,7 @@ namespace Bastet{
BorderedWindow w(d.y,d.x);
wattrset((WINDOW *)w,COLOR_PAIR(20));
for(size_t i=0;i<choices.size();++i){
mvwprintw(w,i,4,choices[i].c_str());
mvwprintw(w,i,4,"%s",choices[i].c_str());
}
w.RedrawBorder();
wrefresh(w);
Expand Down Expand Up @@ -290,7 +290,7 @@ namespace Bastet{
Dot d=BoundingRect(msg );
BorderedWindow w(d.y,d.x);
wattrset((WINDOW *)w,COLOR_PAIR(20));
mvwprintw(w,0,0,msg.c_str());
mvwprintw(w,0,0,"%s",msg.c_str());
w.RedrawBorder();
ch=getch();
switch(ch){
Expand Down