tetris: fix up PieceStuck() #421

pull/426/head
nick black 4 years ago
parent 91f907a184
commit 5b7e2f574c
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -2,6 +2,7 @@
#include <atomic>
#include <thread>
#include <chrono>
#include <vector>
#include <cstdlib>
#include <clocale>
#include <ncpp/NotCurses.hh>

@ -4,6 +4,7 @@ void RotateCcw() {
if(!PrepForMove(&y, &x)){
return;
}
// FIXME need to check game board for validity of rotation in both of these
if(!curpiece_->rotate_ccw() || !nc_.render()){
throw TetrisNotcursesErr("rotate_ccw() or render()");
}

@ -3,29 +3,40 @@ bool PieceStuck() {
// check for impact. iterate over bottom row of piece's plane, checking for
// presence of glyph. if there, check row below. if row below is occupied,
// we're stuck.
int y, x;
curpiece_->get_dim(&y, &x);
while(x--){
ncpp::Cell piecec;
if(curpiece_->get_at(y - 1, x, &piecec) < 0){
throw TetrisNotcursesErr("get_at()");
}
if(!piecec.get().gcluster || piecec.get().gcluster == ' '){
continue;
}
const char* egc = curpiece_->get_extended_gcluster(piecec);
if(strcmp(egc, "")){
continue;
}
int cmpy = y, cmpx = x; // need game area coordinates via translation
curpiece_->translate(*board_, &cmpy, &cmpx);
ncpp::Cell c;
if(board_->get_at(cmpy, cmpx, &c) < 0){
throw TetrisNotcursesErr("get_at()");
}
if(c.get().gcluster){
if(c.get().gcluster != ' '){
return true;
int y, dimx, x;
curpiece_->get_dim(&y, &dimx);
std::vector<bool> columns(dimx, false); // bitmap for column verification
int checked = 0;
while(y--){
x = dimx;
while(x--){
if(!columns[x]){
ncpp::Cell piecec;
if(curpiece_->get_at(y, x, &piecec) < 0){
throw TetrisNotcursesErr("get_at()");
}
if(piecec.is_simple()){
continue;
}
///*
const char* egc = curpiece_->get_extended_gcluster(piecec);
if(strcmp(egc, "")){
continue;
}
//*/
int cmpy = y + 1, cmpx = x; // need game area coordinates via translation
curpiece_->translate(*board_, &cmpy, &cmpx);
ncpp::Cell c;
if(board_->get_at(cmpy, cmpx, &c) < 0){
throw TetrisNotcursesErr("get_at()");
}
if(!c.is_simple()){
return true;
}
columns[x] = true;
if(++checked == dimx){
return false;
}
}
}
}

Loading…
Cancel
Save