/// operators bool operator==(const DirectPoint& point){ return (getX()==point.getX())&&(getY()==point.getY()); }
void adjust(Move m, int val) { data[getX(m)][getY(m)] += val; }
Move generateMove(Player p, Move lastMove) { MoveList legalMoves = game.getLegalMoves(p); MoveList localMoves = game.getLocalMoves(lastMove); // Pass if every move is either into your own eye, a suicide, or places // a chain into atari bool playPass = true; for (unsigned int n = 0; n < legalMoves.size(); n++) { Board copy = Board(game); Move m = legalMoves.get(n); if (!copy.isMoveValid(otherPlayer(p), m) && copy.isEye(p, m)) continue; if (!copy.isMoveValid(p, m)) continue; copy.doMove(p, m); if (copy.isInAtari(m)) continue; playPass = false; break; } if (playPass) return MOVE_PASS; MCTree searchTree; float komiAdjustment = 0.0; Move captureLastStone = game.getPotentialCapture(lastMove); Move potentialEscape = game.getPotentialEscape(p, lastMove); // Add all first-level moves for (unsigned int n = 0; n < legalMoves.size(); n++) { Board copy = Board(game); Player genPlayer = p; Move next = legalMoves.get(n); // Check legality of moves (suicide) if (!copy.isMoveValid(genPlayer, next)) continue; copy.doMove(genPlayer, next); // Never place own chain in atari if (copy.isInAtari(next)) continue; // Check for ko rule violation bool koViolation = false; if (next != MOVE_PASS) { uint64_t newKey = copy.getZobristKey(); for (int i = keyStackSize-1; i >= 0; i--) { if (newKey == keyStack[i]) { koViolation = true; break; } } } if (koViolation) continue; // First level moves are added to the root MCNode *leaf = searchTree.root; MCNode *addition = new MCNode(); addition->parent = leaf; addition->m = next; // Play out a random game. The final board state will be stored in copy. playRandomGame(otherPlayer(genPlayer), copy); // Score the game float myScore = 0.0, oppScore = 0.0; scoreGame(genPlayer, copy, myScore, oppScore); if (myScore > oppScore) addition->numerator++; addition->scoreDiff = ((int) myScore) - ((int) oppScore); komiAdjustment += myScore - oppScore; // Add the new node to the tree leaf->children[leaf->size] = addition; leaf->size++; // Backpropagate the results searchTree.backPropagate(addition); // Do priors, if any // Own eye and opening priors inspired by Pachi, // written by Petr Baudis and Jean-loup Gailly int basePrior = boardSize * boardSize / 8; // Discourage playing into own eyes if (game.isEye(genPlayer, next)) { addition->denominator += basePrior; // If this eye is not ko-related we almost certainly should not play // in it if (!game.isMoveValid(otherPlayer(genPlayer), next)) { addition->denominator += 10 * basePrior; addition->scoreDiff -= 10 * 360; } } // Discourage playing onto edges and encourage playing onto the 4th line // in 13x13 and 19x19 openings unsigned int openingMoves = boardSize * boardSize - boardSize; if ((boardSize == 13 || boardSize == 19) && legalMoves.size() > openingMoves) { int x = getX(next); int y = getY(next); if (x == 1 || x == 19 || y == 1 || y == 19) { addition->denominator += 2 * basePrior; } else { int taperedPrior = basePrior * (legalMoves.size() - openingMoves) / boardSize; if (x == 4 || x == boardSize-3) { addition->numerator += 2 * taperedPrior; addition->denominator += 2 * taperedPrior; } if (y == 4 || y == boardSize-3) { addition->numerator += 2 * taperedPrior; addition->denominator += 2 * taperedPrior; } if (x == 3 || x == boardSize-2 || y == 3 || y == boardSize-2) { addition->numerator += taperedPrior; addition->denominator += taperedPrior; } } } // And the same for 9x9 else if (boardSize == 9 && legalMoves.size() > openingMoves) { int x = getX(next); int y = getY(next); if (x == 1 || x == boardSize || y == 1 || y == boardSize) { addition->denominator += 2 * basePrior; } else { int taperedPrior = basePrior * (legalMoves.size() - openingMoves) / boardSize; if (x == 3 || x == boardSize-2) { addition->numerator += 2 * taperedPrior; addition->denominator += 2 * taperedPrior; } if (y == 3 || y == boardSize-2) { addition->numerator += 2 * taperedPrior; addition->denominator += 2 * taperedPrior; } } } // Add a bonus for capturing a chain that the opponent placed // into atari on the previous move if (next == captureLastStone) { addition->numerator += 5 * basePrior; addition->denominator += 5 * basePrior; } // Add a bonus for escaping when the opponent's last move // placed our chain into atari if (next == potentialEscape) { addition->numerator += 5 * basePrior; addition->denominator += 5 * basePrior; } // Add a bonus to local moves if (legalMoves.size() < openingMoves) { int li = localMoves.find(next); if (li != -1) { localMoves.removeFast(li); } else { addition->numerator += basePrior; addition->denominator += 2 * basePrior; } } } // If we have no moves that are ko-legal, pass. if (searchTree.root->size == 0) return MOVE_PASS; // Calculate an estimate of a komi adjustment komiAdjustment /= legalMoves.size(); // Expand the MC tree iteratively for (int n = 0; n < playouts; n++) { Board copy = Board(game); Player genPlayer = p; // Find a node in the tree to add a child to int depth = -1; MCNode *leaf = searchTree.findLeaf(genPlayer, copy, depth); MCNode *addition = new MCNode(); addition->parent = leaf; MoveList candidates = copy.getLegalMoves(genPlayer); candidates.add(MOVE_PASS); // Set up a permutation matrix int *permutation = new int[candidates.size()]; // Fisher-Yates shuffle for (unsigned int i = 0; i < candidates.size(); i++) { std::uniform_int_distribution<int> distribution(0, i); int j = distribution(rng); permutation[i] = permutation[j]; permutation[j] = i; } // Find a random move that has not been explored yet Move next = 0; for (unsigned int i = 0; i < candidates.size(); i++) { next = candidates.get(permutation[i]); bool used = false; for (int j = 0; j < leaf->size; j++) { if (next == leaf->children[j]->m) { used = true; break; } } if (!used && copy.isMoveValid(genPlayer, next)) break; } delete[] permutation; addition->m = next; copy.doMove(genPlayer, next); // Play out a random game. The final board state will be stored in copy. playRandomGame(otherPlayer(genPlayer), copy); // Score the game... somehow... float myScore = 0.0, oppScore = 0.0; scoreGame(genPlayer, copy, myScore, oppScore); myScore += (genPlayer == p) ? -komiAdjustment : komiAdjustment; if (myScore > oppScore) { addition->numerator++; // If the node is not a child of root if (depth) raveTable.inc(next, depth); } else { if (depth) raveTable.dec(next, depth); } addition->scoreDiff = ((int) myScore) - ((int) oppScore); // Add the new node to the tree leaf->children[leaf->size] = addition; leaf->size++; // Backpropagate the results searchTree.backPropagate(addition); } // Find the highest scoring move Move bestMove = searchTree.root->children[0]->m; double bestScore = 0.0; int64_t diff = -(1 << 30); int maxRAVE = raveTable.max(); for (int i = 0; i < searchTree.root->size; i++) { double candidateScore = (double) searchTree.root->children[i]->numerator / (double) searchTree.root->children[i]->denominator; // + (double) raveTable.score(searchTree.root->children[i]->m) // / ((double) maxRAVE) // / (16 + std::sqrt(searchTree.root->children[i]->denominator)) // + (double) searchTree.root->children[i]->scoreDiff // / (double) (360 * 32); // if (candidateScore > bestScore) { // bestScore = candidateScore; // bestMove = searchTree.root->children[i]->m; // } if (debugOutput) { std::cerr << "(" << getX(searchTree.root->children[i]->m) << ", " << getY(searchTree.root->children[i]->m) << "): " << searchTree.root->children[i]->numerator << " / " << searchTree.root->children[i]->denominator << std::endl; } if (candidateScore > bestScore || (candidateScore == bestScore && searchTree.root->children[i]->scoreDiff > diff)) { bestScore = candidateScore; bestMove = searchTree.root->children[i]->m; diff = searchTree.root->children[i]->scoreDiff; } } raveTable.age(); return bestMove; }
void Ponto::imprime() { qDebug() << "X:" << getX() << "Y:" << getY(); }
int main(void) { // seed pseudorandom number generator srand48(time(NULL)); // instantiate window GWindow window = newGWindow(WIDTH, HEIGHT); // instantiate bricks initBricks(window); // instantiate ball, centered in middle of window GOval ball = initBall(window); // instantiate paddle, centered at bottom of window GRect paddle = initPaddle(window); // instantiate scoreboard, centered in middle of window, just above ball GLabel label = initScoreboard(window); // number of bricks initially int bricks = COLS * ROWS; // number of lives initially int lives = LIVES; // number of points initially int points = 0; double velocity = drand48()*5; double velocityX = drand48()*5; // keep playing until game over while (lives > 0 && bricks > 0) { move(ball, velocityX, velocity); pause(10); // check for mouse event GEvent event = getNextEvent(MOUSE_EVENT); // if we heard one if (event != NULL) { // if the event was movement if (getEventType(event) == MOUSE_MOVED) { // ensure follows cursor double x = getX(event); if(x <= 350&&velocityX!=0) setLocation(paddle, x, 550); } } GObject object = detectCollision(window, ball); if(object != NULL) { if (object == paddle) { velocity = -velocity; updateScoreboard(window,label, points); } else if (strcmp(getType(object), "GRect") == 0) { velocity = -velocity; points++; updateScoreboard(window,label, points); bricks--; removeGWindow(window, object); } } // bounce off bottom edge of window if (getY(ball) + getHeight(ball) >= getHeight(window)) { velocity = 0; velocityX = 0; lives--; } // bounce off up edge of window else if (getY(ball) <= 0) { velocity = -velocity; } if (getX(ball) + getWidth(ball) >= getWidth(window)) { velocityX = -velocityX; } // bounce off bottom edge of window else if (getX(ball) <= 0) { velocityX = -velocityX; } // linger before moving again pause(10); } if(points==50) { GLabel label = newGLabel("You bricked out the breakout!"); setFont(label, "SansSerif-36"); add(window, label); setLocation(label, 100, 200); pause(10); } else if(points<50) { GLabel label = newGLabel("Try again!"); setFont(label, "SansSerif-36"); add(window, label); setLocation(label, 100, 200); pause(10); } // wait for click before exiting if(bricks==0) { waitForClick(); // game over closeGWindow(window); } if(lives==0) { waitForClick(); // game over closeGWindow(window); } waitForClick(); // game over closeGWindow(window); return 0; }
void Platform::hit(EventCollision *p_c) { if (((p_c->getObject1()->getType()) == "Hero") || ((p_c->getObject2()->getType()) == "Hero")) { auto heroPtr = (Object*)nullptr; auto platformPtr = (Object*)nullptr; if ((p_c->getObject1()->getType()) == "Hero") { heroPtr = p_c->getObject1(); platformPtr = p_c->getObject2(); } else { heroPtr = p_c->getObject2(); platformPtr = p_c->getObject1(); } WorldManager &world_manager = WorldManager::getInstance(); auto heroPos = heroPtr->getPosition(); auto platformPos = platformPtr->getPosition(); int xOffset = 0; int yOffset = 0; if (heroPtr->getPosition().getY() <= (this->getPosition().getY() + this->getHeight())) { if (getXVelocity() > 0) { xOffset = this->lastXDisplacement; } else if (getXVelocity() < 0) { xOffset = this->lastXDisplacement; } } if (getYVelocity() > 0) { //only adjust hero position when platform goes up //yOffset = 1; } else if (getYVelocity() < 0) { yOffset = this->lastYDisplacement; } float xCD; float yCD; bool xChanged; if (xOffset || yOffset) { heroPos = Position(heroPos.getX(), heroPos.getY()); platformPos = Position(platformPos.getX(), platformPos.getY()); xCD = platformPtr->getXVelocityCountdown(); xChanged = xCD > prevXCD; yCD = platformPtr->getYVelocityCountdown(); heroPos.setX(heroPos.getX() + xOffset); platformPos.setX(platformPos.getX()); if (!xChanged) { heroPos.setX(heroPos.getX() - xOffset); //platformPos.setX(platformPos.getX() - xOffset); } prevXCD = xCD; if (yCD <= 0) { heroPos.setY(heroPos.getY() + yOffset); platformPos.setY(platformPos.getY() + yOffset); } } if (yOffset > 0) { world_manager.moveObject(platformPtr, platformPos); world_manager.moveObject(heroPtr, heroPos); } else if (yOffset < 0) { ObjectList list = world_manager.isCollision(heroPtr, heroPos); if (!list.isEmpty()) { world_manager.markForDelete(heroPtr); } else { world_manager.moveObject(heroPtr, heroPos); world_manager.moveObject(platformPtr, platformPos); } } if (xOffset) { ObjectList list = world_manager.isCollision(heroPtr, heroPos); if (list.isEmpty()) { world_manager.moveObject(heroPtr, heroPos); world_manager.moveObject(platformPtr, platformPos); } else { world_manager.moveObject(platformPtr, platformPos); list = world_manager.isCollision(heroPtr, heroPos); if (list.isEmpty()) { world_manager.moveObject(heroPtr, heroPos); } else { //world_manager.markForDelete(heroPtr); } } } } else { // monster, trap, etc. will stop the platform completely //setXVelocityCountdown(getXVelocityCountdown() + fabs(getXVelocity())); //setYVelocityCountdown(getYVelocityCountdown() + fabs(getYVelocity())); } }
/************************************************************************* * Function name: moveBy * The Input: x and y coordinates to move by * The output: none * The Function operation: moves the block x cells down and y cells right *************************************************************************/ void Block::moveBy(const int x, const int y) { setX(getX() + x); setY(getY() + y); }
bool UINode::checkBounds (int x, int y) const { const float _x = x / static_cast<float>(_frontend->getWidth()); const float _y = y / static_cast<float>(_frontend->getHeight()); return checkAABB(_x, _y, getX(), getY(), getWidth(), getHeight()); }
//-------------------------------------------------------------- ofRectangle LayerTransform::getRectangle() const { return ofRectangle(getX(),getY(),getWidth(),getHeight()); }
Vector3f FeaturePoint::getPoint3D() const { return Vector3f( getX(), getY(), getZ() ); }
// -- widget ops void GuiTable::draw(gcn::Graphics* graphics) { if (!mModel) return; if (config.getFloatValue("guialpha") != mAlpha) mAlpha = config.getFloatValue("guialpha"); if (mOpaque) { graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, (int)(mAlpha * 255.0f))); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } // First, determine how many rows we need to draw, and where we should start. int first_row = -(getY() / getRowHeight()); if (first_row < 0) first_row = 0; int rows_nr = 1 + (getHeight() / getRowHeight()); // May overestimate by one. int max_rows_nr = mModel->getRows() - first_row; // clip if neccessary: if (max_rows_nr < rows_nr) rows_nr = max_rows_nr; // Now determine the first and last column // Take the easy way out; these are usually bounded and all visible. int first_column = 0; int last_column = mModel->getColumns() - 1; // Set up everything for drawing int height = getRowHeight(); int y_offset = first_row * height; for (int r = first_row; r < first_row + rows_nr; ++r) { int x_offset = 0; for (int c = first_column; c <= last_column; ++c) { gcn::Widget *widget = mModel->getElementAt(r, c); int width = getColumnWidth(c); if (widget) { gcn::Rectangle bounds(x_offset, y_offset, width, height); if (widget == mTopWidget) { bounds.height = widget->getHeight(); bounds.width = widget->getWidth(); } widget->setDimension(bounds); graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, (int)(mAlpha * 255.0f))); if (mLinewiseMode && r == mSelectedRow && c == 0) { graphics->fillRectangle(gcn::Rectangle(0, y_offset, getWidth(), height)); } else if (!mLinewiseMode && c == mSelectedColumn && r == mSelectedRow) { graphics->fillRectangle(gcn::Rectangle(x_offset, y_offset, width, height)); } graphics->pushClipArea(bounds); widget->draw(graphics); graphics->popClipArea(); } x_offset += width; } y_offset += height; } if (mTopWidget) { gcn::Rectangle bounds = mTopWidget->getDimension(); graphics->pushClipArea(bounds); mTopWidget->draw(graphics); graphics->popClipArea(); } }
int main(void) { // seed pseudorandom number generator srand48(time(NULL)); // instantiate window GWindow window = newGWindow(WIDTH, HEIGHT); // instantiate bricks initBricks(window); // instantiate ball, centered in middle of window GOval ball = initBall(window); // instantiate paddle, centered at bottom of window GRect paddle = initPaddle(window); // instantiate scoreboard, centered in middle of window, just above ball GLabel label = initScoreboard(window); // number of bricks initially int bricks = COLS * ROWS; // number of lives initially int lives = LIVES; // number of points initially int points = 0; // keep playing until game over double velocity= 2.0 + drand48() ; double vely = 2.0; updateScoreboard(window, label, points); waitForClick(); while (lives > 0 && bricks > 0) { updateScoreboard(window, label, points); GEvent event = getNextEvent(MOUSE_EVENT); if (event != NULL) { if (getEventType(event) == MOUSE_MOVED) { double x = getX(event) - getWidth(paddle) / 2; setLocation(paddle, x, getY(paddle)); } } move(ball, velocity, vely); if (getX(ball) + getWidth(ball) >= getWidth(window)) { velocity = -velocity; } else if (getX(ball) <= 0) { velocity = -velocity; } if( getY(ball) <= 0) { vely = -vely; } else if (getY(ball)+getWidth(ball) >= HEIGHT) { lives--; setLocation(ball, (WIDTH/2)-10, HEIGHT/2); waitForClick(); } GObject obj = detectCollision(window, ball); if(obj != NULL) { if(strcmp(getType(obj), "GRect")==0) { vely = -vely; if(obj != paddle) { removeGWindow(window, obj); bricks--; points++; } } } pause(10); } // wait for click before exiting waitForClick(); // game over closeGWindow(window); return 0; }
DirectPoint& operator*=(float mult){ setX(getX()*mult); setY(getY()*mult); return *this; }
DirectPoint& operator-=(const DirectPoint& point){ setX(getX()-point.getX()); setY(getY()-point.getY()); return *this; }
int Q5CG = Q4FU + 0x01; loc Q5C0 = loc( Q4FS, Q4FT, Q5CG ); loc trapLocation = loc( 0x14CB, 0x023C, 0x00 ); list Q5DQ; if(!hasObjVar(this, "working")) { bark(this, "SOUND EFFECT"); callback(this, 0x05, 0x01); int Q64U = teleport(this, Q5C0); messageToRange(trapLocation, 0x0A, "disarm", Q5DQ); setObjVar(this, "working", 0x01); } return(0x01); } TRIGGER( callback , 0x01 )() { int Q4FS = getX(getLocation(this)); int Q4FT = getY(getLocation(this)); int Q4FU = getZ(getLocation(this)); int Q5CG = Q4FU - 0x01; loc Q5C0 = loc( Q4FS, Q4FT, Q5CG ); bark(this, "SOUND EFFECT"); bark(this, "returning"); if(hasObjVar(this, "working")) { removeObjVar(this, "working"); } int Q64U = teleport(this, Q5C0); return(0x01); }
void PluginWindow::moved() { owner->properties.set ("uiLastX", getX()); owner->properties.set ("uiLastY", getY()); }
Point3D Point3D::operator- ( Point3D rhs ) const { return Point3D( getX() - rhs.getX(), getY() - rhs.getY(), getZ() - rhs.getZ() ); }
double cal_WHDNode::getH() { return getY(); }
Angle Vector2d::getAngle() const { return Angle::arcTangent2(getY(), getX()); }
/** * Called whenever an action occurs, and processes it to * check if it's relevant to the surface and convert it * into a meaningful interaction like a "click", calling * the respective handlers. * @param action Pointer to an action. * @param state State that the action handlers belong to. */ void InteractiveSurface::handle(Action *action, State *state) { if (!_visible || _hidden) return; action->setSender(this); if (action->getDetails()->type == SDL_MOUSEBUTTONUP || action->getDetails()->type == SDL_MOUSEBUTTONDOWN) { action->setMouseAction(action->getDetails()->button.x, action->getDetails()->button.y, getX(), getY()); } else if (action->getDetails()->type == SDL_MOUSEMOTION) { action->setMouseAction(action->getDetails()->motion.x, action->getDetails()->motion.y, getX(), getY()); } if (action->isMouseAction()) { if ((action->getAbsoluteXMouse() >= getX() && action->getAbsoluteXMouse() < getX() + getWidth()) && (action->getAbsoluteYMouse() >= getY() && action->getAbsoluteYMouse() < getY() + getHeight())) { if (!_isHovered) { _isHovered = true; mouseIn(action, state); } if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION) { _buttonsPressed = SDL_GetMouseState(0, 0); for (Uint8 i = 1; i <= NUM_BUTTONS; ++i) { if (isButtonPressed(i)) { action->getDetails()->button.button = i; mousePress(action, state); } } } mouseOver(action, state); } else { if (_isHovered) { _isHovered = false; mouseOut(action, state); if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION) { for (Uint8 i = 1; i <= NUM_BUTTONS; ++i) { if (isButtonPressed(i)) { setButtonPressed(i, false); } action->getDetails()->button.button = i; mouseRelease(action, state); } } } } } if (action->getDetails()->type == SDL_MOUSEBUTTONDOWN) { if (_isHovered && !isButtonPressed(action->getDetails()->button.button)) { setButtonPressed(action->getDetails()->button.button, true); mousePress(action, state); } } else if (action->getDetails()->type == SDL_MOUSEBUTTONUP) { if (isButtonPressed(action->getDetails()->button.button)) { setButtonPressed(action->getDetails()->button.button, false); mouseRelease(action, state); if (_isHovered) { mouseClick(action, state); } } } if (_isFocused) { if (action->getDetails()->type == SDL_KEYDOWN) { keyboardPress(action, state); } else if (action->getDetails()->type == SDL_KEYUP) { keyboardRelease(action, state); } } }
void King::moveIsPossible(const desk&, const int x, const int y) const { if(!((abs(getX()-x)==1 && getY()==y) || (abs(getY()-y)==1 && getX()==x) || (abs(getX()-x)==1 && abs(getY()-y)==1))) throw error("Tagavory chi karox mek vandakic avel trnel"); }
int main(void) { // seed pseudorandom number generator srand48(time(NULL)); // instantiate window GWindow window = newGWindow(WIDTH, HEIGHT); // instantiate bricks initBricks(window); // instantiate ball, centered in middle of window GOval ball = initBall(window); // instantiate paddle, centered at bottom of window GRect paddle = initPaddle(window); // instantiate scoreboard, centered in middle of window, just above ball GLabel label = initScoreboard(window); // number of bricks initially int bricks = COLS * ROWS; // number of lives initially int lives = LIVES; // number of points initially int points = 0; // velocity of ball double vX = drand48(); double vY = 2; // keep playing until game over while (lives > 0 && points<50) { move(ball,vX,vY); GEvent mouse = getNextEvent(MOUSE_EVENT); if(mouse!=NULL) { if(getEventType(mouse) == MOUSE_MOVED) { int y = 500; double x = getX(mouse) - getWidth(paddle)/2; setLocation(paddle,x,y); } } if(getX(ball) + getWidth(ball) >= getWidth(window)) { vX = -vX; } else if(getY(ball) <=0) { vY = -vY; } else if(getX(ball)<=0) { vX = -vX; } else if(getY(ball) + getHeight(ball) >= getHeight(window)) { lives--; waitForClick(); setLocation(ball, 190, 290); setLocation(paddle, 150, 480); } GObject obj = detectCollision(window,ball); if(obj!=NULL) { if(obj == paddle) { vY = -vY; } else if (strcmp(getType(obj),"GRect")==0) { removeGWindow(window,obj); points++; vY = -vY; updateScoreboard(window, label, points); } } pause(10); } // wait for click before exiting waitForClick(); // game over closeGWindow(window); return 0; }
void play(int mode, GWindow window) { /* Initialize the Game */ //create the game-board G3DRect board = newG3DRect(BOARD_X, BOARD_Y, 3*BOX, 3*BOX, true); setColor(board, "LIGHT_GRAY"); setFilled(board, true); add(window, board); //creates the array of small rects GRect rect[9]; int k = 0; for(int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { rect[k] = newGRect(BOX*j + BOARD_X, BOX*i + BOARD_Y, BOX, BOX); setColor(rect[k], "#0000FF"); add(window, rect[k]); k++; } } GLabel status = newGLabel("Player 1"); setFont(status, "SansSerif-26"); setLabel(status, "Player 1"); add(window, status); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); A[0][0] = -1; A[0][0] = -1; A[0][0] = -1; A[0][0] = -1; A[0][0] = -1; A[0][0] = -1; A[0][0] = -1; A[0][0] = -1; A[0][0] = -1; int i = 0, player = 0, flag = -1; // if 2 player is seleceted if (mode == 2) { while( i <= 8) { player = i%2; if (player == 0) { setLabel(status, "Player 1"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } else { setLabel(status, "Player 2"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } printf("Player %d move....\n", player + 1); // wait for click while (true) { GEvent event = getNextEvent(MOUSE_EVENT); // check for mouse event if (event != NULL) // if we heard one { if (getEventType(event) == MOUSE_CLICKED) // if the event was movement { GObject object = getGObjectAt(window, getX(event), getY(event)); if(object != NULL) { int j; int rightClick = 0; for(j = 0; j < 9; j++) { if (object == rect[j]) { //remove the rect and add appropriate image int x = getX(object); int y = getY(object); printf("Rect[%d] clicked by player %d\n", j, player); removeGWindow(window, object); updateArray(player, j); if(player == 0) { GImage cross = newGImage("cross.png"); addAt(window, cross, x, y); } else { GImage circle = newGImage("circle.png"); addAt(window, circle, x, y); } rightClick = 1; } } if(rightClick == 1) break; } } } }// end of a click operation // check Status if (checkStatus()) { printf("Player %d won\n", player); flag = player; break; } i++; }// end of i = 0 to 8 loop }// if mode == 2 else // if mode == 1 { while( i <= 8) { player = i%2; if (player == 0) { setLabel(status, "Player 1"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } else { setLabel(status, "Player 2"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } printf("Player %d move....\n", player + 1); //showPlayer(player, mode); if (player == 0) // aka human being { // wait for click while (true) { GEvent event = getNextEvent(MOUSE_EVENT); // check for mouse event if (event != NULL) // if we heard one { if (getEventType(event) == MOUSE_CLICKED) // if the event was movement { GObject object = getGObjectAt(window, getX(event), getY(event)); if(object != NULL) { int j; int rightClick = 0; for(j = 0; j < 9; j++) { if (object == rect[j]) { //remove the rect and add appropriate image int x = getX(object); int y = getY(object); printf("Rect[%d] clicked by player %d\n", j, player); removeGWindow(window, object); updateArray(player, j); GImage cross = newGImage("cross.png"); addAt(window, cross, x, y); rightClick = 1; } } if(rightClick == 1) break; } } } }// end of a click operation }// end if player == 0 aka human being else // if player is computer { pause(750); // find the position int pos; if(check(59) >= 0) pos = check(59); else if (check(5) >= 0) pos = check(5); else pos = any(); updateArray(player, pos); //remove the rect and add appropriate image int x = getX(rect[pos]); int y = getY(rect[pos]); printf("Rect[%d] clicked by player %d\n", pos, player); removeGWindow(window, rect[pos]); GImage circle = newGImage("circle.png"); addAt(window, circle, x, y); }// end if player is computer // check Status if (checkStatus()) { printf("Player %d won\n", player); flag = player; break; } i++; }// end of i = 0 to 8 loop }// end if mode == 1 if (flag == 0 && mode == 2) { setLabel(status, "Player 1 Wins!!!"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } else if (flag == 1 && mode == 2) { setLabel(status, "Player 2 Wins!!!"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } else if (flag == 0 && mode == 1) { setLabel(status, "You Win !!!"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } else if (flag == 1 && mode == 1) { setLabel(status, "You Lose !!!"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } else if (flag == -1) { setLabel(status, "Game Draws !!!"); double x = WIDTH/2 - getWidth(status)/2; double y = HEIGHT/2 + 200; setLocation(status, x, y); } printf("flag = %d\n", flag); waitForClick(); }
void Player::render() { graphicsComp->render(getX(), getY(), getZ(), 1.0, 0.0); meleeWeapon->render(); }
void dec(Move m, int depth) { if (m == MOVE_PASS) return; data[getX(m)][getY(m)] -= std::max(0, 150 - 5*depth - depth*depth); }
char *SFRotation::getValue(char *buffer, int bufferLen) { sprintf(buffer, "%g %g %g %g", getX(), getY(), getZ(), getAngle()); return buffer; }
int score(Move m) { if (m == MOVE_PASS) return 0; return data[getX(m)][getY(m)]; }
void CharacterEquipmentPanel::render(Renderer &renderer) { assert(this->getGameState()->gameDataIsActive()); // Clear full screen. renderer.clearNative(); renderer.clearOriginal(); // Set palette. auto &textureManager = this->getGameState()->getTextureManager(); textureManager.setPalette(PaletteFile::fromName(PaletteName::CharSheet)); // Get a reference to the active player data. const auto &player = this->getGameState()->getGameData()->getPlayer(); // Get the filenames for the portrait and clothes. const std::string &headsFilename = PortraitFile::getHeads( player.getGenderName(), player.getRaceName(), false); const std::string &bodyFilename = PortraitFile::getBody( player.getGenderName(), player.getRaceName()); const std::string &shirtFilename = PortraitFile::getShirt( player.getGenderName(), player.getCharacterClass().canCastMagic()); const std::string &pantsFilename = PortraitFile::getPants(player.getGenderName()); // Get pixel offsets for each clothes texture. const Int2 &shirtOffset = PortraitFile::getShirtOffset( player.getGenderName(), player.getCharacterClass().canCastMagic()); const Int2 &pantsOffset = PortraitFile::getPantsOffset(player.getGenderName()); // Draw the current portrait and clothes. const Int2 &headOffset = this->headOffsets.at(player.getPortraitID()); const auto &head = textureManager.getTextures(headsFilename, PaletteFile::fromName(PaletteName::CharSheet)).at(player.getPortraitID()); const auto &body = textureManager.getTexture(bodyFilename); const auto &shirt = textureManager.getTexture(shirtFilename); const auto &pants = textureManager.getTexture(pantsFilename); renderer.drawToOriginal(body.get(), Renderer::ORIGINAL_WIDTH - body.getWidth(), 0); renderer.drawToOriginal(pants.get(), pantsOffset.getX(), pantsOffset.getY()); renderer.drawToOriginal(head.get(), headOffset.getX(), headOffset.getY()); renderer.drawToOriginal(shirt.get(), shirtOffset.getX(), shirtOffset.getY()); // Draw character equipment background. const auto &equipmentBackground = textureManager.getTexture( TextureFile::fromName(TextureName::CharacterEquipment)); renderer.drawToOriginal(equipmentBackground.get()); // Draw text boxes: player name, race, class. renderer.drawToOriginal(this->playerNameTextBox->getTexture(), this->playerNameTextBox->getX(), this->playerNameTextBox->getY()); renderer.drawToOriginal(this->playerRaceTextBox->getTexture(), this->playerRaceTextBox->getX(), this->playerRaceTextBox->getY()); renderer.drawToOriginal(this->playerClassTextBox->getTexture(), this->playerClassTextBox->getX(), this->playerClassTextBox->getY()); // Scale the original frame buffer onto the native one. renderer.drawOriginalToNative(); // Draw cursor. const auto &cursor = textureManager.getTexture( TextureFile::fromName(TextureName::SwordCursor)); const auto mousePosition = this->getMousePosition(); renderer.drawToNative(cursor.get(), mousePosition.getX(), mousePosition.getY(), static_cast<int>(cursor.getWidth() * this->getCursorScale()), static_cast<int>(cursor.getHeight() * this->getCursorScale())); }
QRect CMeteorite::getBoundsT() { QPolygon m_tmp_bd( m_body ); m_tmp_bd.translate( getX(), getY() ); return m_tmp_bd.boundingRect(); }
///getAngle-reurns the angle between this and point float getAngle(const DirectPoint& point) const { float dx = point.getX() - getX(); float dy = point.getY() - getY(); return atan2(dy,dx); }