Beispiel #1
0
bool Game::can_place(block b, Point p)
{
  bool onAbsCorner = false;
  bool onRelCorner = false;
  int N = dimension - 1;

  Point corners[4] = { Point(0,0), Point(N, 0), Point(0, N), Point(N, N) };
  Point corner = corners[my_number];
  for(int i = 0; i < b.size(); i++){
    Point q = b[i].add(p);
    int x = q.x;
    int y = q.y;
    if (x > N || x < 0 || y < 0 || y > N || grid[x][y] >= 0
        || grid[x][y] == -2
        || (x > 0 && grid[x-1][y] == my_number)
        || (y > 0 && grid[x][y-1] == my_number)
        || (x < N && grid[x+1][y] == my_number)
        || (y < N && grid[x][y+1] == my_number)) {
      return false;
    }

    onAbsCorner = onAbsCorner || q.eq(corner);
    onRelCorner = onRelCorner
      || (x > 0 && y > 0 && grid[x-1][y-1] == my_number)
      || (x < N && y > 0 && grid[x+1][y-1] == my_number)
      || (x > 0 && y < N && grid[x-1][y+1] == my_number)
      || (x < N && y < N && grid[x+1][y+1] == my_number);
  }

  return grid[corner.x][corner.y] < 0 ? onAbsCorner : onRelCorner;
}
Beispiel #2
0
block Game::rotate_block(block b, int num_rotations)
{
  block newBlock;
  for(int i = 0; i < b.size(); i++){
    newBlock.push_back(b[i].rotate(num_rotations));
  }
  return newBlock;
}
void bGroup::resetUsed(block & t)
{
	//-------- resets the log of what blocks have been used in the last print stage
	used[""]=false;
	used[t.title]=false;
	for (unsigned int i=0; i<t.numInside(); i++) {
		resetUsed(t.blocksIn[i]);
	}
	for (unsigned int i=0; i<t.size(); i++) {
		resetUsed(t.blocksOn[i]);
	}
}
void resetList(block & t, map<string,bool> & used)
{
	//-------- resets the log of what blocks have been used in the last print stage
	used[""]=false;
	used[t.title]=false;
	for (unsigned int i=0; i<t.numInside(); i++) {
		resetList(t.blocksIn[i],used);
	}
	for (unsigned int i=0; i<t.size(); i++) {
		resetList(t.blocksOn[i],used);
	}
}
Beispiel #5
0
int bGroup::heightUpdate(block & grab, block & comp)
{
	int ret=0;
	for (unsigned int i=0; i<comp.numInside(); i++) {
		heightUpdate(grab, comp.blocksIn[i]);
	}
	for (unsigned int i=0; i<comp.size(); i++) {
		heightUpdate(grab, comp.blocksOn[i]);
	}
	if(comp.blockIsInside(grab)&&!comp.bSeq&&!grab.numBlock){
		if(!comp.inBlockIn(grab.x,grab.y)) comp.h=grab.heightOnlyOn(true)+comp.heightInside()+grab.h+65-((!comp.numInside())?40:0);
		else comp.h=comp.heightInside()+65-((!comp.numInside())?40:0);
		comp.updatePositions(grab);
	}
	return ret;
}
Beispiel #6
0
//Currently returns 0, you might want to modify this yourself!
int Game::score_move(block b, Point p)
{
  int score = 0;
  int blockSize = b.size();
  int bonus_points = 0;
  int N = dimension;

  for(int i = 0; i < blockSize; i++){
    Point s = b[i].add(p);
    for(int j = 0; j < bonus_squares.size(); j++){
      if(s.eq(bonus_squares[j])){
        bonus_points += 2;
      }
      area_enclosed = max(area_enclosed, -1 * (s.distance(Point(N/2, N/2))));
    }
  }

  return score;
}