コード例 #1
0
ファイル: mmkeyosd.c プロジェクト: dapus/mmkeyosd
void 
text_with_bar(struct config *c, char *in, int error) {
	int nww, twb;

	/* If there was an error, display it instead of drawing a bar */
	if(error) {
		text_with_text(c, in, error);
		return;
	}

	/* Calculate window size */
	twb = text_width(&fontbig, c->text);
	nww = MAX(ww, twb + 30);

	XRectangle r = { CENTER(nww, barw), (wh/2), barw, barh };

	moveresizeclear(nww, wh);

	draw_text(&fontbig, &fgcol, c->text, CENTER(nww, text_width(&fontbig, c->text)),
			CENTER(wh/2, fontbig.h)+fontbig.h);

	XSetForeground(dpy, gc, fgcol.pixel);
	/* border */
	XDrawRectangles(dpy, win, gc, &r, 1);

	/* and bar */
	r.width = (float)atoi(in)/100.0*(float)barw;
	XFillRectangles(dpy, win, gc, &r, 1);
}
コード例 #2
0
ファイル: mmkeyosd.c プロジェクト: dapus/mmkeyosd
void
moveresizeclear(int ww, int wh) {
	XMoveResizeWindow(dpy, win, CENTER(sw, ww)+xoff, CENTER(sh, wh)+yoff, ww, wh);

	/* Clear window */
	XSetForeground(dpy, gc, bgcol.pixel);
	XFillRectangle(dpy, win, gc, 0, 0, ww, wh);
}
コード例 #3
0
ファイル: game.c プロジェクト: Slaiiz/rush_2048
void		update_score(t_context *gamestate)
{
	WINDOW	*window;
	char	*s;

	window = gamestate->windows[SCORE];
	s = "Points:";
	mvwaddstr(window, CENTER(WINC_Y, 1), 2, s);
	s = ft_itoa(gamestate->points);
	mvwaddstr(window, CENTER(WINC_Y, 1), WINC_X - ft_strlen(s) - 2, s);
	wrefresh(window);
	free(s);
}
コード例 #4
0
ファイル: mmkeyosd.c プロジェクト: dapus/mmkeyosd
void 
text_with_text(struct config *c, char *in, int error) {
	int nww, tws, twb;

	/* Calculate window size */
	tws = text_width(&fontsmall, in);
	twb = text_width(&fontbig, c->text);
	nww = MAX(ww, MAX(tws, twb) + 20);

	moveresizeclear(nww, wh);

	draw_text(&fontbig, &fgcol, c->text, CENTER(nww, text_width(&fontbig, c->text)),
			CENTER(wh/2, fontbig.h)+fontbig.h);
	draw_text(&fontsmall, error ? &errcol : &fgcol, in, CENTER(nww, text_width(&fontsmall, in)), (wh/2)+fontsmall.h);
}
コード例 #5
0
ファイル: BarShader.cpp プロジェクト: strogo/StrongDC
double OperaColors::RGB2HUE(double r, double g, double b) {
	double H;
	double m2 = MAX3(r, g, b);
	double m1 = CENTER(r, g, b);
	double m0 = MIN3(r, g, b);

	if (m2 == m1) {
		if (r == g) {
			H = 60;
			goto _RGB2HUE_END;
		}
		if (g == b) {
			H = 180;
			goto _RGB2HUE_END;
		}
		H = 60;
		goto _RGB2HUE_END;
	}
	double F = 60 * (m1 - m0) / (m2 - m0);
	if (r == m2) {
		H = 0 + F * (g - b);
		goto _RGB2HUE_END;
	}
	if (g == m2) {
		H = 120 + F * (b - r);
		goto _RGB2HUE_END;
	}
	H = 240 + F * (r - g);

_RGB2HUE_END:
	if (H < 0)
		H = H + 360;
	return H;
}
コード例 #6
0
ファイル: ParserPrinter.cpp プロジェクト: jaydee-io/bnf2c
std::ostream & operator <<(std::ostream & os, const Parser & parser)
{
    // Header
    std::string strTerminals = concatenateStrings(parser.getGrammar().terminals) + parser.getOptions().endOfInputToken + '|';
    std::string strIntermediates = concatenateStrings(parser.getGrammar().intermediates, parser.getGrammar().START_RULE);

    os << "     |" << CENTER("Actions", std::max(strTerminals.length(), 7u)) << '|';
    os <<             CENTER("Branchs", std::max(strIntermediates.length(), 7u)) << '|' << std::endl;
    os << "State|" << strTerminals << strIntermediates << std::endl;
    os << std::setfill('-') << std::setw(strTerminals.length() + strIntermediates.length() + 6) << '-' << std::setfill(' ') << std::endl;

    // Table
    auto maxSizeIntermediate = std::to_string(parser.getStates().size()).length();
    auto eoit = parser.getOptions().endOfInputToken;
    for(const auto & state : parser.getStates())
    {
        os << std::left << std::setw(5) << state->numState << '|';

        // Action
        for(const auto & terminal : parser.getGrammar().terminals)
            printStateActions(os, state->getAction(terminal, eoit), terminal.length());
        printStateActions(os, state->getAction(eoit, eoit), eoit.length());

        // Goto
        for(const auto & intermediate : parser.getGrammar().intermediates)
            if(intermediate != parser.getGrammar().START_RULE)
                printStateBranches(os, state->getGoto(intermediate), std::max(intermediate.length(), maxSizeIntermediate));

        os << std::endl;
    }
    os << std::endl;

    // Print items sets
    for(const auto & state : parser.getStates())
        os << *state << std::endl;

    return os;
}
コード例 #7
0
ファイル: game.c プロジェクト: Slaiiz/rush_2048
static void	new_game(t_context *gamestate)
{
	WINDOW	**windows;

	windows = gamestate->windows;
	if (ft_bitscan(WIN_VALUE) != 1 || WIN_VALUE == 1)
	{
		mvwaddstr(windows[SCORE], CENTER(WINC_Y, 1), 2, "I AIN'T RUNNIN' THAT");
		wrefresh(windows[SCORE]);
		gamestate->is_running = 0;
		return ;
	}
	gamestate->is_running = 1;
	mvwhline(windows[HIGHSCORES], WINA_Y - 2, 1, ' ', WINA_X - 2);
	wrefresh(windows[HIGHSCORES]);
	update_score(gamestate);
	gamestate->grid = new_grid();
	add_number(gamestate);
	add_number(gamestate);
	draw_grid(gamestate);
}
コード例 #8
0
ファイル: mPCA.cpp プロジェクト: TheProjecter/surfacetoar
 int
Tracker::arMatrixPCA(ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean)
{
    ARMat     *work;
    ARFloat  srow, sum;
    int     row, clm;
    int     check, rval;
    int     i;

    row = input->row;
    clm = input->clm;
    check = (row < clm)? row: clm;
    if( row < 2 || clm < 2 ) return(-1);
    if( evec->clm != input->clm || evec->row != check ) return(-1);
    if( ev->clm   != check )      return(-1);
    if( mean->clm != input->clm ) return(-1);

    work = Matrix::allocDup( input );
    if( work == NULL ) return -1;

    srow = (ARFloat)sqrt((ARFloat)row);
    if( EX( work, mean ) < 0 ) {
        Matrix::free( work );
        return(-1);
    }
    if( CENTER( work, mean ) < 0 ) {
        Matrix::free( work );
        return(-1);
    }
    for(i=0; i<row*clm; i++) work->m[i] /= srow;

    rval = PCA( work, evec, ev );
    Matrix::free( work );

    sum = 0.0;
    for( i = 0; i < ev->clm; i++ ) sum += ev->v[i];
    for( i = 0; i < ev->clm; i++ ) ev->v[i] /= sum;

    return( rval );
}
コード例 #9
0
ファイル: matrix.c プロジェクト: freeboy1015/ginrou-private
int matrixPCA( Mat input, Mat evec, Vec ev, Vec mean )
{
    Mat     work;
    double  srow, sum;
    int     row, clm;
    int     check, rval;
    int     i;

    row = input.row;
    clm = input.clm;
    check = (row < clm)? row: clm;
    if( row < 2 || clm < 2 ) return(-1);
    if( evec.clm != input.clm || evec.row != check ) return(-1);
    if( ev.clm   != check )     return(-1);
    if( mean.clm != input.clm ) return(-1);

    work = matrixAllocDup( input );
    if( work.row != row || work.clm != clm ) return(-1);

    srow = sqrt((double)row);
    if( EX( work, mean ) < 0 ) {
        matrixFree( work );
        return(-1);
    }
    if( CENTER( work, mean ) < 0 ) {
        matrixFree( work );
        return(-1);
    }
    for(i=0; i<row*clm; i++) work.m[i] /= srow;

    rval = PCA( work, evec, ev );
    matrixFree( work );

    sum = 0.0;
    for( i = 0; i < ev.clm; i++ ) sum += ev.v[i];
    for( i = 0; i < ev.clm; i++ ) ev.v[i] /= sum;

    return( rval );
}
コード例 #10
0
ファイル: MatGenFD.c プロジェクト: tpatki/rapl-old-data
void generateBlocked(MatGenFD mg, HYPRE_Int *rp, HYPRE_Int *cval, double *aval, Mat_dh A, Vec_dh b)
{
  START_FUNC_DH
  bool applyBdry = true;
  double *stencil = mg->stencil;
  HYPRE_Int id = mg->id;
  bool threeD = mg->threeD;
  HYPRE_Int px = mg->px, py = mg->py, pz = mg->pz; /* processor grid dimensions */
  HYPRE_Int p, q, r; /* this proc's position in processor grid */
  HYPRE_Int cc = mg->cc; /* local grid dimension (grid of unknowns) */
  HYPRE_Int nx = cc, ny = cc, nz = cc;
  HYPRE_Int lowerx, upperx, lowery, uppery, lowerz, upperz;
  HYPRE_Int startRow;
  HYPRE_Int x, y, z;
  bool debug = false;
  HYPRE_Int idx = 0, localRow = 0; /* nabor; */
  HYPRE_Int naborx1, naborx2, nabory1, nabory2, naborz1, naborz2;
  double *rhs;

  double hhalf = 0.5 * mg->hh;
  double bcx1 = mg->bcX1;
  double bcx2 = mg->bcX2;
  double bcy1 = mg->bcY1;
  double bcy2 = mg->bcY2;
  /* double bcz1 = mg->bcZ1; */
  /* double bcz2 = mg->bcZ2; */

  Vec_dhInit(b, A->m); CHECK_V_ERROR;
  rhs = b->vals;

  if (mg->debug && logFile != NULL) debug = true;
  if (! threeD) nz = 1;

  /* compute p,q,r from P,Q,R and myid */
  p = id % px;
  q = (( id - p)/px) % py;
  r = ( id - p - px*q)/( px*py );

  if (debug) {
    hypre_sprintf(msgBuf_dh, "this proc's position in subdomain grid: p= %i  q= %i  r= %i", p,q,r);
    SET_INFO(msgBuf_dh);
  }

   /* compute ilower and iupper from p,q,r and nx,ny,nz */
   /* zero-based */

   lowerx = nx*p;
   upperx = lowerx + nx;
   lowery = ny*q;
   uppery = lowery + ny;
   lowerz = nz*r;
   upperz = lowerz + nz;

  if (debug) {
    hypre_sprintf(msgBuf_dh, "local grid parameters: lowerx= %i  upperx= %i", lowerx, upperx);
    SET_INFO(msgBuf_dh);
    hypre_sprintf(msgBuf_dh, "local grid parameters: lowery= %i  uppery= %i", lowery, uppery);
    SET_INFO(msgBuf_dh);
    hypre_sprintf(msgBuf_dh, "local grid parameters: lowerz= %i  upperz= %i", lowerz, upperz);
    SET_INFO(msgBuf_dh);
  }

  startRow = mg->first;
  rp[0] = 0;

  for (z=lowerz; z<upperz; z++) {
    for (y=lowery; y<uppery; y++) {
      for (x=lowerx; x<upperx; x++) {

        if (debug) {
          hypre_fprintf(logFile, "row= %i  x= %i  y= %i  z= %i\n", localRow+startRow+1, x, y, z);
        }

        /* compute row values and rhs, at the current node */
        getstencil(mg,x,y,z);

        /* down plane */
        if (threeD) {
          if (z > 0) {
            naborz1 = rownum(threeD, x,y,z-1,nx,ny,nz,px,py);
            cval[idx]   = naborz1;
            aval[idx++] = FRONT(stencil);
          }
        }

        /* south */
        if (y > 0) {
          nabory1 = rownum(threeD, x,y-1,z,nx,ny,nz,px,py);
          cval[idx]   = nabory1;
          aval[idx++] = SOUTH(stencil);
        }

        /* west */
        if (x > 0) {
          naborx1 = rownum(threeD, x-1,y,z,nx,ny,nz,px,py);
          cval[idx]   = naborx1;
          aval[idx++] = WEST(stencil);
/*hypre_fprintf(logFile, "--- row: %i;  naborx1= %i\n", localRow+startRow+1, 1+naborx1);
*/
        }
/*
else {
hypre_fprintf(logFile, "--- row: %i;  x >= nx*px-1; naborx1 has old value: %i\n", localRow+startRow+1,1+naborx1);
}
*/

        /* center node */
        cval[idx]   = localRow+startRow;
        aval[idx++] = CENTER(stencil);


        /* east */
        if (x < nx*px-1) {
          naborx2 = rownum(threeD,x+1,y,z,nx,ny,nz,px,py);
          cval[idx]   = naborx2;
          aval[idx++] = EAST(stencil);
        }
/*
else {
hypre_fprintf(logFile, "--- row: %i;  x >= nx*px-1; nobors2 has old value: %i\n", localRow+startRow,1+naborx2);
}
*/

        /* north */
        if (y < ny*py-1) {
          nabory2 = rownum(threeD,x,y+1,z,nx,ny,nz,px,py);
          cval[idx]   = nabory2;
          aval[idx++] = NORTH(stencil);
        }

        /* up plane */
        if (threeD) {
          if (z < nz*pz-1) {
            naborz2 = rownum(threeD,x,y,z+1,nx,ny,nz,px,py);
            cval[idx]   = naborz2;
            aval[idx++] = BACK(stencil);
          }
        }

       /* rhs[rhsIdx++] = RHS(stencil); */
       rhs[localRow] = 0.0;

       ++localRow;
       rp[localRow] = idx; 

       /* apply boundary conditions; only for 2D! */
       if (!threeD && applyBdry) {
         HYPRE_Int globalRow = localRow+startRow-1;
         HYPRE_Int offset = rp[localRow-1];
         HYPRE_Int len = rp[localRow] - rp[localRow-1];
         double ctr, coeff;

/* hypre_fprintf(logFile, "globalRow = %i; naborx2 = %i\n", globalRow+1, naborx2+1); */

         if (x == 0) {         /* if x1 */
           coeff = mg->A(mg->a, x+hhalf,y,z);
           ctr   = mg->A(mg->a, x-hhalf,y,z);
           setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcx1, coeff, ctr, naborx2);
         } else if (x == nx*px-1) {  /* if x2 */
           coeff = mg->A(mg->a, x-hhalf,y,z);
           ctr   = mg->A(mg->a, x+hhalf,y,z);
           setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcx2, coeff, ctr, naborx1);
         } else if (y == 0) {  /* if y1 */
           coeff = mg->B(mg->b, x, y+hhalf,z);
           ctr   = mg->B(mg->b, x, y-hhalf,z);
           setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy1, coeff, ctr, nabory2);
         } else if (y == ny*py-1) {        /* if y2 */
           coeff = mg->B(mg->b, x, y-hhalf,z);
           ctr   = mg->B(mg->b, x, y+hhalf,z);
           setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy2, coeff, ctr, nabory1);
         } else if (threeD) {
           if (z == 0) {
             coeff = mg->B(mg->b, x, y, z+hhalf);
             ctr   = mg->B(mg->b, x, y, z-hhalf);
             setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy1, coeff, ctr, naborz2);
           } else if (z == nz*nx-1) {
             coeff = mg->B(mg->b, x, y, z-hhalf);
             ctr   = mg->B(mg->b, x, y, z+hhalf);
             setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy1, coeff, ctr, naborz1);
           }
         }
       }
      }
    }
  }
  END_FUNC_DH
}
コード例 #11
0
ファイル: MatGenFD.c プロジェクト: tpatki/rapl-old-data
void getstencil(MatGenFD g, HYPRE_Int ix, HYPRE_Int iy, HYPRE_Int iz)
{
  HYPRE_Int k; 
  double h = g->hh;
  double hhalf = h*0.5;
  double x = h*ix;
  double y = h*iy;
  double z = h*iz;
  double cntr = 0.0;
  double *stencil = g->stencil;
  double coeff;
  bool threeD = g->threeD;

  for (k=0; k<8; ++k) stencil[k] = 0.0;

  /* differentiation wrt x */
  coeff = g->A(g->a, x+hhalf,y,z);
  EAST(stencil) += coeff;
  cntr += coeff;

  coeff = g->A(g->a, x-hhalf,y,z);
  WEST(stencil) += coeff;
  cntr += coeff;

  coeff = g->D(g->d, x,y,z)*hhalf;
  EAST(stencil) += coeff;
  WEST(stencil) -= coeff;

  /* differentiation wrt y */
  coeff = g->B(g->b,x,y+hhalf,z);
  NORTH(stencil) += coeff;
  cntr += coeff;

  coeff = g->B(g->b,x,y-hhalf,z);
  SOUTH(stencil) += coeff;
  cntr += coeff;

  coeff = g->E(g->e,x,y,z)*hhalf;
  NORTH(stencil) += coeff;
  SOUTH(stencil) -= coeff;

  /* differentiation wrt z */
  if (threeD) {
    coeff = g->C(g->c,x,y,z+hhalf);
    BACK(stencil) += coeff;
    cntr += coeff;

    coeff = g->C(g->c,x,y,z-hhalf);
    FRONT(stencil) += coeff;
    cntr += coeff;

    coeff = g->F(g->f,x,y,z)*hhalf;
    BACK(stencil) += coeff;
    FRONT(stencil) -= coeff;
  }

  /* contribution from function G: */
  coeff = g->G(g->g,x,y,z);
  CENTER(stencil) = h*h*coeff - cntr;

  RHS(stencil) = h*h*g->H(g->h,x,y,z);
}
コード例 #12
0
ファイル: MatGenFD.c プロジェクト: tpatki/rapl-old-data
void generateStriped(MatGenFD mg, HYPRE_Int *rp, HYPRE_Int *cval, double *aval, Mat_dh A, Vec_dh b)
{
  START_FUNC_DH
  HYPRE_Int mGlobal;
  HYPRE_Int m = mg->m;
  HYPRE_Int beg_row, end_row;
  HYPRE_Int i, j, k, row;
  bool threeD = mg->threeD;
  HYPRE_Int idx = 0;
  double *stencil = mg->stencil;
  bool debug = false;
  HYPRE_Int plane, nodeRemainder;
  HYPRE_Int naborx1, naborx2, nabory1, nabory2;
  double *rhs;

  bool applyBdry = true;
  double hhalf;
  double bcx1 = mg->bcX1;
  double bcx2 = mg->bcX2;
  double bcy1 = mg->bcY1;
  double bcy2 = mg->bcY2;
  /* double bcz1 = mg->bcZ1; */
  /* double bcz2 = mg->bcZ2; */
  HYPRE_Int nx, ny;

  printf_dh("@@@ using striped partitioning\n");

  if (mg->debug && logFile != NULL) debug = true;

  /* recompute values (yuck!) */
  m = 9;
  Parser_dhReadInt(parser_dh,"-m", &m);  /* global grid dimension */
  mGlobal = m*m;                         /* global unkknowns */
  if (threeD) mGlobal *= m;
  i = mGlobal/mg->np;                    /* unknowns per processor */
  beg_row = i*mg->id;                    /* global number of 1st local row */
  end_row = beg_row + i;
  if (mg->id == mg->np-1) end_row = mGlobal;
  nx = ny = m;

  mg->hh = 1.0/(m-1);
  hhalf = 0.5 * mg->hh;

  A->n = m*m;
  A->m = end_row - beg_row;
  A->beg_row = beg_row;

  Vec_dhInit(b, A->m); CHECK_V_ERROR;
  rhs = b->vals;

  plane = m*m;

  if (debug) {
    hypre_fprintf(logFile, "generateStriped: beg_row= %i; end_row= %i; m= %i\n", beg_row+1, end_row+1, m);
  }

  for (row = beg_row; row<end_row; ++row) {
        HYPRE_Int localRow = row-beg_row;

        /* compute current node's position in grid */
        k = (row / plane);      
        nodeRemainder = row - (k*plane); /* map row to 1st plane */
        j = nodeRemainder / m;
        i = nodeRemainder % m;

        if (debug) {
          hypre_fprintf(logFile, "row= %i  x= %i  y= %i  z= %i\n", row+1, i,j,k);
        }

        /* compute column values and rhs entry for the current node */
        getstencil(mg,i,j,k);

        /* only homogenous Dirichlet boundary conditions presently supported */

        /* down plane */
        if (threeD) {
          if (k > 0) {
            cval[idx]   = row - plane;
            aval[idx++] = BACK(stencil);
          }
        }

        /* south */
        if (j > 0) {
          nabory1 = cval[idx] = row - m;
          aval[idx++] = SOUTH(stencil);
        }

        /* west */
        if (i > 0) {
          naborx1 = cval[idx] = row - 1;
          aval[idx++] = WEST(stencil);
        }

        /* center node */
        cval[idx]   = row;
        aval[idx++] = CENTER(stencil);

        /* east */
        if (i < m-1) {
          naborx2 = cval[idx] = row + 1;
          aval[idx++] = EAST(stencil);
        }

        /* north */
        if (j < m-1) {
          nabory2 = cval[idx] = row + m;
          aval[idx++] = NORTH(stencil);
        }

        /* up plane */
        if (threeD) {
          if (k < m-1) {
            cval[idx]   = row + plane;
            aval[idx++] = FRONT(stencil);
          }
        }
       rhs[localRow] = 0.0;
       ++localRow;
       rp[localRow] = idx; 

       /* apply boundary conditions; only for 2D! */
       if (!threeD && applyBdry) {
         HYPRE_Int offset = rp[localRow-1];
         HYPRE_Int len = rp[localRow] - rp[localRow-1];
         double ctr, coeff;

/* hypre_fprintf(logFile, "globalRow = %i; naborx2 = %i\n", row+1, row); */

         if (i == 0) {         /* if x1 */
           coeff = mg->A(mg->a, i+hhalf,j,k);
           ctr   = mg->A(mg->a, i-hhalf,j,k);
           setBoundary_private(row, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcx1, coeff, ctr, naborx2);
         } else if (i == nx-1) {  /* if x2 */
           coeff = mg->A(mg->a, i-hhalf,j,k);
           ctr   = mg->A(mg->a, i+hhalf,j,k);
           setBoundary_private(row, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcx2, coeff, ctr, naborx1);
         } else if (j == 0) {  /* if y1 */
           coeff = mg->B(mg->b, i, j+hhalf,k);
           ctr   = mg->B(mg->b, i, j-hhalf,k);
           setBoundary_private(row, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy1, coeff, ctr, nabory2);
         } else if (j == ny-1) {        /* if y2 */
           coeff = mg->B(mg->b, i, j-hhalf,k);
           ctr   = mg->B(mg->b, i, j+hhalf,k);
           setBoundary_private(row, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy2, coeff, ctr, nabory1);
         }
       }
  }
  END_FUNC_DH
}
コード例 #13
0
ファイル: chess.c プロジェクト: yrchen/Athena
int chc_canmove(board_t board, rc_t from, rc_t to) {
    int i;
    int rd, cd, turn;

    rd = dist(from, to, 0);
    cd = dist(from, to, 1);
    turn = CHE_O(board[from.r][from.c]);

    /* general check */
    if(board[to.r][to.c] && CHE_O(board[to.r][to.c]) == turn)
        return 0;

    /* individual check */
    switch(CHE_P(board[from.r][from.c])) {
    case 1: /* 將 帥 */
        if(!(rd == 1 && cd == 0) &&
           !(rd == 0 && cd == 1))
            return 0;
        if((turn == (chc_my ^ 1) && to.r > 2) ||
           (turn == chc_my && to.r < 7) ||
            to.c < 3 || to.c > 5)
                return 0;
        break;
    case 2: /* 士 仕 */
        if(!(rd == 1 && cd == 1))
            return 0;
        if((turn == (chc_my ^ 1) && to.r > 2) ||
           (turn == chc_my && to.r < 7) ||
            to.c < 3 || to.c > 5)
                return 0;
        break;
    case 3: /* 象 相 */
        if(!(rd == 2 && cd == 2))
            return 0;
        if((turn == (chc_my ^ 1) && to.r > 4) ||
           (turn == chc_my && to.r < 5))
            return 0;
        /* 拐象腿 */
        if(board[CENTER(from.r, to.r)][CENTER(from.c, to.c)])
            return 0;
        break;
    case 4: /* 車 */
        if(!(rd > 0 && cd == 0) &&
           !(rd == 0 && cd > 0))
            return 0;
        if(between(board, from, to, rd == 0))
            return 0;
        break;
    case 5: /* 馬 傌 */
        if(!(rd == 2 && cd == 1) &&
           !(rd == 1 && cd == 2))
            return 0;
        /* 拐馬腳 */
        if(rd == 2) {
            if(board[CENTER(from.r, to.r)][from.c])
                return 0;
        } else {
            if(board[from.r][CENTER(from.c, to.c)])
                return 0;
        }
        break;
    case 6: /* 包 炮 */
        if(!(rd > 0 && cd == 0) &&
           !(rd == 0 && cd > 0))
            return 0;
        i = between(board, from, to, rd == 0);
        if((i > 1) ||
           (i == 1 && !board[to.r][to.c]) ||
           (i == 0 && board[to.r][to.c]))
           return 0;
        break;
    case 7: /* 卒 兵 */
        if(!(rd == 1 && cd == 0) &&
           !(rd == 0 && cd == 1))
            return 0;
        if(((turn == (chc_my ^ 1) && to.r < 5) ||
            (turn == chc_my && to.r > 4)) &&
            cd != 0)
            return 0;
        if((turn == (chc_my ^ 1) && to.r < from.r) ||
           (turn == chc_my && to.r > from.r))
            return 0;
        break;
    }
    return 1;
}
コード例 #14
0
ファイル: lgn_armia.cpp プロジェクト: boskee/lamos
void _ARMIA(aint A) {
	//	Procedure ARMIA[A]

	aint AX=0,AY=0,PL=0,KONIEC=0,TEREN=0,I=0,DANE=0;
	aint STREFA=0,KONIEC2=0,STREFA2=0,TER2=0;

	_rysuj_armia_nr = A;

	AX=ARMIA[A][0][TX];											//	   AX=ARMIA(A,0,TX)
	AY=ARMIA[A][0][TY];											//	   AY=ARMIA(A,0,TY)
	PL=ARMIA[A][0][TMAG];										//	   PL=ARMIA(A,0,TMAG)
	if( PREFS[5]==1 ) {
		WJAZD(AX,AY,80,80,150,100,4);					//	   If PREFS(5)=1 : WJAZD[AX,AY,80,80,150,100,4] : End If
	}

	if( A<20 ) {
		DANE=-1;
	} else {
		if( ARMIA[A][0][TMAGMA]==0 || ARMIA[A][0][TMAGMA]==100 ) {
			DANE=-1;
		}
	}

	if( DANE!=0 ) {
		TEREN=ARMIA[A][0][TNOGI];
		AX=ARMIA[A][0][TX];
		AY=ARMIA[A][0][TY];
	}

	rysuj();
	_ARMIA_RYSUJ_INFO(A);

	void *sb=0, *sb2=0;
	sb = StoreBuffer(OKX-1,OKY-1,150+2,100+2);

	do {																		//	   Repeat
		rysuj();
		RestoreBuffer(sb);
		WaitVbl();
		if( MouseClick() ) {									//	      If Mouse Click=1
			STREFA=MouseZone();									//	         STREFA=Mouse Zone
			if( STREFA==1 || STREFA==0 ) {			//	         If STREFA=1 or STREFA=0
				KONIEC=-1;												//	            KONIEC=True
				ZOKNO();													//	            ZOKNO
			}																		//	         End If
			if( STREFA==11 ) {									//	         If STREFA=11
				//WPISZ(OKX+50,OKY+15,1,30,14,0);			//	            WPISZ[OKX+50,OKY+15,1,30,14]

				_rysuj_tlo_armia = rysuj_ekran_ptr;
				rysuj_ekran_ptr = _rysuj_armia;
				WPISZ_PC(OKX+50,OKY+15-TextBase(),100,10,14,ARMIA_S[A][0],2);	//rysuj tylko tlo i kursor
				rysuj_ekran_ptr = _rysuj_tlo_armia;
				sb = StoreBuffer(OKX-1,OKY-1,150+2,100+2);

				ARMIA_S[A][0]=WPI_S;							//	            ARMIA$(A,0)=WPI$
			}																		//	         End If
			if( STREFA==10 && A<20 ) {					//	         If STREFA=10 and A<20
				ZOKNO();													//	            ZOKNO
				KONIEC=-1;												//	            KONIEC=True
				rysuj();
				_ARMIA_RYSUJ_ROZKAZY(A);					//	            Gosub RYSUJ_ROZKAZY
				sb2 = StoreBuffer(OKX-1,OKY-1,80+2,150+2);
				KONIEC2=0;												//	            KONIEC2=False
				do {															//	            Repeat
					rysuj();
					RestoreBuffer(sb2);
					WaitVbl();
					if( MouseClick() ) {						//	               If Mouse Click=1
						STREFA2=MouseZone();					//	                  STREFA2=Mouse Zone
						if( STREFA2>0 && STREFA2<4 ) {//	                  If STREFA2>0 and STREFA2<4
							ZOKNO();										//	                     ZOKNO
							M_RUCH(A,STREFA2);					//	                     M_RUCH[A,STREFA2]
							KONIEC2=-1; KONIEC=-1;			//	                     KONIEC2=True : KONIEC=True
						}															//	                  End If
						if( STREFA2==4 && TEREN<70 ) {//	                  If STREFA2=4 and TEREN<70
							ZOKNO();										//	                     ZOKNO
							ARMIA[A][0][TTRYB]=4;				//	                     ARMIA(A,0,TTRYB)=4
							KONIEC2=-1; KONIEC=-1;			//	                     KONIEC=True : KONIEC2=True
						}															//	                  End If
						if( STREFA2==4 && TEREN>69 ) {//	                  If STREFA2=4 and TEREN>69
							if( MIASTA[TEREN-70][0][M_CZYJE]==1 ) {//	                     If MIASTA(TEREN-70,0,M_CZYJE)=1
								ZOKNO();									//	                        ZOKNO
								ARMIA[A][0][TTRYB]=0;			//	                        ARMIA(A,0,TTRYB)=0
								REKRUTACJA(10,TEREN-70,A);//	                        REKRUTACJA[10,TEREN-70,A]
								_ARMIA_RYSUJ_ROZKAZY(A);		//	                        Gosub RYSUJ_ROZKAZY
							}														//	                     End If
						}															//	                  End If
																					//
						if( STREFA2==6 ) {						//	                  If STREFA2=6
							ZOKNO();										//	                     ZOKNO
							SpriteOnOff(2,false);				//	                     Sprite Off 2
																					//	                     'Auto View Off
							_LOAD(KAT_S+"dane/gad","dane:gad","Dane",1);	//	                     _LOAD[KAT$+"dane/gad","dane:gad","Dane",1]
							ScreenOpen(1,320,160,32,LOWRES);//	                     Screen Open 1,320,160,32,Lowres
							Screen(1);									//	                     Screen 1
																					//	                     Curs Off : Flash Off
							ReserveZone(60);						//	                     Reserve Zone 60 : Get Bob Palette : Set Font FON1
							SetFont(FON1);
							GOBY=44;										//	                     GOBY=44
																					//	                     'Auto View On
							ARM=A;											//	                     ARM=A
							for(I=1;I<=10;++I) {				//	                     For I=1 To 10
								if( ARMIA[A][I][TE]>0 ) {	//	                        If ARMIA(A,I,TE)>0
									NUMER=I;								//	                           NUMER=I
									I=10;										//	                           I=10
								}													//	                        End If
							}														//	                     Next
							WYBOR(1);										//	                     WYBOR[1]
							ScreenClose(1);							//	                     Screen Close 1
							for(I=1;I<=50;++I) {				//	                     For I=1 To 50
								DelBob(GOBY+1);						//	                        Del Bob GOBY+1
							}														//	                     Next
							Screen(0);									//	                     Screen 0
							Sprite(2,SPX,SPY,1);				//	                     Sprite 2,SPX,SPY,1
							_ARMIA_RYSUJ_ROZKAZY(A);			//	                     Gosub RYSUJ_ROZKAZY
						}															//	                  End If
																					//
						if( STREFA2==8 ) {						//	                  If STREFA2=8
							KONIEC=-1;KONIEC2=-1;				//	                     KONIEC=True : KONIEC2=True
							ARMIA[A][0][TWAGA]=1;				//	                     ARMIA(A,0,TWAGA)=1
							ARM=A; WRG=40;							//	                     ARM=A : WRG=40
							SpriteOnOff(2,false);				//	                     Sprite Off 2
							SETUP(GS("070"),GS("071"),GS("072"));			//	                     SETUP["","Action",""]
							if( TEREN>69 ) {						//	                     If TEREN>69
								TER2=MIASTA[TEREN-70][1][M_X];//	                        TER2=MIASTA(TEREN-70,1,M_X)
								RYSUJ_SCENERIE(TER2,TEREN-70);//	                        RYSUJ_SCENERIE[TER2,TEREN-70]
								WRG=40;										//	                        WRG=40
																					//	                        'ustaw wieôniaków
								for(I=1;I<=7;++I) {				//	                        For I=1 To 7 : NOWA_POSTAC[40,I,9] : Next I
									NOWA_POSTAC(40,I,9);
								}
								for(I=8;I<=10;++I) {			//	                        For I=8 To 10 : NOWA_POSTAC[40,I,Rnd(8)] : Next I
									NOWA_POSTAC(40,I,Rnd(8));
								}
								for(I=1;I<=7;++I) {				//	                        For I=1 To 7 : ARMIA(40,I,TKORP)=20 : Next I
									ARMIA[40][I][TKORP]=20;
								}
								for(I=8;I<=10;++I) {			//	                        For I=8 To 10 : ARMIA(WRG,I,TKORP)=40 : Next I
									ARMIA[WRG][I][TKORP]=40;
								}
								ARMIA[40][0][TE]=10;			//	                        ARMIA(40,0,TE)=10
								USTAW_WOJSKO(WRG,1,1,1);	//	                        USTAW_WOJSKO[WRG,1,1,1]
							} else {										//	                     Else
								ARMIA[WRG][0][TE]=0;			//	                        ARMIA(WRG,0,TE)=0
								RYSUJ_SCENERIE(TEREN,-1);	//	                        RYSUJ_SCENERIE[TEREN,-1]
							}														//	                     End If
							USTAW_WOJSKO(ARM,1,1,0);		//	                     USTAW_WOJSKO[ARM,1,1,0]
							MAIN_ACTION();							//	                     MAIN_ACTION
																					//	                     'skasuj wieôniaków
							for(I=0;I<=10;++I) {				//	                     For I=0 To 10 : ARMIA(40,I,TE)=0 : Next I
								ARMIA[40][I][TE]=0;
							}
							SETUP0();										//	                     SETUP0
							VISUAL_OBJECTS();						//	                     VISUAL_OBJECTS
							CENTER(AX,AY,0);						//	                     CENTER[AX,AY,0]
							Sprite(2,SPX,SPY,1);				//	                     Sprite 2,SPX,SPY,1
						}															//	                  End If
																					//
						if( STREFA2==5 ) {						//	                  If STREFA2=5
							ZOKNO();										//	                     ZOKNO
							ARMIA[A][0][TTRYB]=0;				//	                     ARMIA(A,0,TTRYB)=0
							KONIEC=-1;KONIEC2=-1;				//	                     KONIEC=True : KONIEC2=True
						}															//	                  End If
						if( STREFA2==7 ) {						//	                  If STREFA2=7
							ZOKNO();										//	                     ZOKNO
							KONIEC2=-1;									//	                     KONIEC2=True
						}															//	                  End If
					}																//	               End If
				} while( 0==KONIEC2 );						//	            Until KONIEC2
			}																		//	         End If
			if( STREFA==10 && A>19 ) {					//	         If STREFA=10 and A>19
				if( ARMIA[A][0][TMAGMA]==0 ) {		//	            If ARMIA(A,0,TMAGMA)=0
					gad_text(1.0);									//	               Ink 31,6 : Text OKX+48,OKY+89,"@"
					Text(OKX+48,OKY+89,"@");
					ARMIA[A][0][TMAGMA]=100;				//	               ARMIA(A,0,TMAGMA)=100
					goto SKIP;											//	               Goto SKIP
				}																	//	            End If
				if( ARMIA[A][0][TMAGMA]==100 ) {	//	            If ARMIA(A,0,TMAGMA)=100
					gad_text(1.0);									//	               Gr Writing 1 : Ink 6,6
					Text(OKX+47,OKY+89,"  ");				//	               Text OKX+47,OKY+89,"  "
					ARMIA[A][0][TMAGMA]=0;					//	               ARMIA(A,0,TMAGMA)=0
				}																	//	            End If
				if( ARMIA[A][0][TMAGMA]>0 && ARMIA[A][0][TMAGMA]<100 ) {//	            If ARMIA(A,0,TMAGMA)>0 and ARMIA(A,0,TMAGMA)<100
					ZOKNO();												//	               ZOKNO
					KONIEC=-1;											//	               KONIEC=True
					SZPIEGUJ(A,1);									//	               SZPIEGUJ[A,1]
				}																	//	            End If
				SKIP:															//	            SKIP:
					;
			}																		//	         End If
		}																			//	      End If
	} while( KONIEC==0 );										//	   Until KONIEC

	FreeBuffer(sb);
	FreeBuffer(sb2);
																					//	   Goto OVER
																					//	   OVER:
																					//	End Proc
}