예제 #1
0
bool CLlinesDoc::correctMove(int x, int y)
{
        if (!(
            x >= 0 && x < WIDTH && GetSquare(x,y) == (byte) EMPTY &&
            y >= 0 && y < HEIGHT && GetSquare(x,y) == (byte) EMPTY
        ))
            return false;

        // Find a way
        return findPath(activeBallX, activeBallY, x, y);
}
void ribi::tictactoe::Board::SetSquare(
  const int x, const int y, const Square square_state) noexcept
{
  if (m_board[x][y] == square_state) return;

  m_board[x][y] = square_state;

  //Internal test
  assert(GetSquare(x,y)==square_state);

  m_signal_changed(this);
}
예제 #3
0
std::string CRectangle::GetStringRepresentation()const
{
	std::ostringstream result;
	result.setf(std::ios_base::fixed, std::ios_base::floatfield);
	result << std::setprecision(2);

	result << "Rectangle <" << m_mainCorner->m_position.x << ", "
		<< m_mainCorner->m_position.y << ">, <" << m_width << ", " << m_height << "> "
		<< GetSquare() << ", P=" << GetPerimeter() << std::endl;
	
	return result.str();
}
std::string ribi::tictactoe::Board::ToTextCanvas() const noexcept
{
  std::stringstream s;
  for (int y=0; y!=3; ++y)
  {
    for (int x=0; x!=3; ++x)
    {
      s << SquareToStr(GetSquare(x,y));
    }
    s << '\n';
  }
  std::string t{s.str()};
  assert(!t.empty());
  t.pop_back();
  return t;
}
예제 #5
0
BYTE CLlinesDoc::throwBall(int i ,BYTE x ,BYTE y)
{

   if (numFree <= 0)
        return END;

   if (GetSquare(x,y) != EMPTY)
		return 	FAIL;
	 //GetView();			//initialize pView
     //pView->drawBall(pDC,x, y);
	 m_grid[x][y] = i;
     userMove = false;
	 numBalls++;
     numFree--;
    if (checkRows(x, y) > 0) 
	 {
		removeRows(x, y);
     }
	 
	
	return SUCCESS;
}
예제 #6
0
bool CLlinesDoc::findPath(int x0, int y0, int x1, int y1)
{
        int x, y;
        int n0, n1;
        int pLen, l;
        bool found = false;
		char str[50];	
        int MAXLEN = WIDTH*HEIGHT + 1;

		
		path	= new byte[WIDTH*HEIGHT][2];
		
        for (x = 0; x < WIDTH; x++)
		{
            for (y = 0; y < HEIGHT; y++) 
			{
                paths[x][y] = (-1);
            }
        }

        paths[x0][y0] = 0;

        n0 = (-1); n1 = 0;
        while (!found && n1 > n0) 
		{
            n0 = n1;
            for (x = 0; !found && x < WIDTH; x++)
			{
               for (y = 0; !found && y < HEIGHT; y++) 
			   {
                    if (paths[x][y] >= 0 || GetSquare(x,y) != (byte) EMPTY)
                        continue;
                    // Look to neighbours
                    int xmin = 0, ymin = 0;
                    int lmin = MAXLEN;
                    if (x+1 < WIDTH && (l = paths[x+1][y]) >= 0) {
                        if (l < lmin) {
                            xmin = x+1; ymin = y; lmin = l;
                        }
                    }
                    if (y+1 < HEIGHT && (l = paths[x][y+1]) >= 0) {
                        if (l < lmin) {
                            xmin = x; ymin = y+1; lmin = l;
                        }
                    }
                    if (x-1 >= 0 && (l = paths[x-1][y]) >= 0) {
                        if (l < lmin) {
                            xmin = x-1; ymin = y; lmin = l;
                        }
                    }
                    if (y-1 >= 0 && (l = paths[x][y-1]) >= 0) {
                        if (l < lmin) {
                            xmin = x; ymin = y-1; lmin = l;
                        }
                    }

                    if (lmin < MAXLEN) {
                        n1++;
                        paths[x][y] = lmin + 1;
                    }

                    if (y == y1 && paths[x1][y1] >= 0) {
                        found = true;
                    }
                }
            }
        }

      // AfxMessageBox("Path found.");

        if (!found)
            return false;

        // Obtain a path
        pathLength = paths[x1][y1];
        pLen = pathLength;
        x = x1; y = y1;

        while (pLen > 0) {
            // Look to neighbours.
            // Find path of minimal length
            int xmin = 0, ymin = 0;
            int lmin = WIDTH*HEIGHT + 1;

            if (x+1 < WIDTH && (l = paths[x+1][y]) >= 0) {
                if (l < lmin) {
                    xmin = x+1; ymin = y;
                    lmin = l;
                }
            }
            if (y+1 < HEIGHT && (l = paths[x][y+1]) >= 0) {
                if (l < lmin) {
                    xmin = x; ymin = y+1;
                    lmin = l;
                }
            }
            if (x-1 >= 0 && (l = paths[x-1][y]) >= 0) {
                if (l < lmin) {
                    xmin = x-1; ymin = y;
                    lmin = l;
                }
            }
            if (y-1 >= 0 && (l = paths[x][y-1]) >= 0) {
                if (l < lmin) {
                    xmin = x; ymin = y-1;
                    lmin = l;
                }
            }

            pLen--;
            x = xmin; y = ymin;
            path[pLen][0] = (byte) x;
            path[pLen][1] = (byte) y;
			sprintf(str,"x = %d y=%d ",x,y);
         //   AfxMessageBox(str);
        }
        //AfxMessageBox("");

        return true;
    }
예제 #7
0
void MilitarySquares::Remove(nobBaseMilitary* const bld)
{
    RTTR_Assert(helpers::contains(GetSquare(bld->GetPos()), bld));
    GetSquare(bld->GetPos()).remove(bld);
}
예제 #8
0
void MilitarySquares::Add(nobBaseMilitary* const bld)
{
    GetSquare(bld->GetPos()).push_back(bld);
}