Ejemplo n.º 1
0
		virtual ~ItemGroup()
		{
			for(items_t::iterator it = items.begin(); it != items.end(); ++it)
			{
				delete (*it);
			}
		}
Ejemplo n.º 2
0
void state_t::print(ostream& os) {
  const char names[] = "QRBKN";
  vector<string> b(height, string(width, '.'));
  for (vector<item_t>::iterator i = board.begin(); i != board.end(); ++i) {
    b[i->y][i->x] = names[i->type];
  }
  copy(b.begin(), b.end(), ostream_iterator<string>(os, "\n"));
  os << "\n";
}
Ejemplo n.º 3
0
		virtual std::basic_ofstream<Char> &Serialize(std::basic_ofstream<Char> &to) const
		{
			items_t::size_type size = items.size();
			Item::Serialize(to).write((Char*)&size, sizeof(size)/sizeof(Char));
			for(items_t::const_iterator it = items.begin(); it != items.end(); ++it)
			{
				(*it)->Serialize(to);
			}
			return to;
		}
Ejemplo n.º 4
0
		virtual HANDLE Serialize(HANDLE File) const
		{
			if(!Item::Serialize(File)) return 0;
			unsigned long written;
			items_t::size_type size = items.size();
			if(!WriteFile(File, &size, sizeof(size), &written, 0) || written != sizeof(size)) return 0;
			for(items_t::const_iterator it = items.begin(); it != items.end(); ++it)
			{
				if(!((*it)->Serialize(File))) return 0;
			}
			return File;
		}
Ejemplo n.º 5
0
bool state_t::is_attacking(int y, int x, int type) {
  for (vector<item_t>::iterator i = board.begin(); i != board.end(); ++i) {
    int cy = i->y, cx = i->x;

    if (type == kQueen || type == kRook)
      if (cy == y || cx == x) 
        return true;
    
    if (type == kQueen || type == kBishop)
      if (cy + cx == y + x || cy - cx == y - x) 
        return true;

    if (type == kKing || type == kKnight) {
      const delta_t* delta = type == kKing ? king_rules : knight_rules;
      for (int i = 0; i < 8; ++i)
        if (cy == y + delta[i].dy && cx == x + delta[i].dx) 
          return true;
    }
  }
  return false;
}