Move Notation::parseCastling( const Board &b, ColorType color, const string &moveStr) { // repair brain-dead variants of castling like "O-O-0" string castle(moveStr); replace(castle.begin(), castle.end(), '0', 'O'); size_t check = castle.find('+'); if (check != string::npos) castle.erase(check,1); size_t mate = castle.find('#'); if (mate != string::npos) castle.erase(mate,1); transform(castle.begin(), castle.end(), castle.begin(), ::toupper); if (castle == "O-O") { if (color == White) return CreateMove(E1,G1,King,Empty,Empty,KCastle); else return CreateMove(E8,G8,King,Empty,Empty,KCastle); } else if (castle == "O-O-O") { if (color == White) return CreateMove(E1,C1,King,Empty,Empty,QCastle); else return CreateMove(E8,C8,King,Empty,Empty,QCastle); } else { return NullMove; } }
void drawScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); glRotatef(0.0, 0.0, 1.0, 0.0); glRotatef(0.0, 1.0, 0.0, 0.0); glEnd(); castle(); glutSwapBuffers(); }
void castle(double h, double r) { int i; double angle, tx, ty; diff(); cylinder(h, r, r * 0.8); cylinder(h, 0.5 * r, 0.4 * r); enddiff(); for (i = 0; i < 5; i++) { angle = (PI / 180 * 360.0 / 5.0 * i); tx = r * cos(angle); ty = r * sin(angle); if ((r / 2.2) >= 3.0) { xlate(tx, ty, 0); castle(h * 1.3, r / 2.2); endxlate(); } } }
BOOL BOARD::userCanCastle ( MOVETYPE whichCastle, PIECECOLOR color ) { BOARDMETRIC metric; MOVEUNDODATA undoData; if (!canCastle(whichCastle, color)) return(FALSE); castle(whichCastle, color, undoData); // make sure king is not in check in final position findBestMoves(1, OtherColor(color), metric, (BESTMOVES *) 0); undoCastle(whichCastle, color, undoData); return(metric.kingSituation[color] == KINGOK); }
void specialKeys(int key, int x, int y){ castle(key); }
int main (int argc, char **argv) { #ifdef __linux__ XInitThreads(); #endif char move=0; sf::Vector2f finish; Shared shared; Object player(ObjectType::Player), castle(ObjectType::Castle); shared.win = shared.game_over = false; shared.objects.push_back(&player); if(!loadMap(player, castle, shared)) return 1; shared.bg_objects.push_back(&castle); shared.game_state = 1; // start screen - main menu or game ThreadWindow window(WIDTH, HEIGHT, "oiraM", &shared); while(!window.isOpen()); player.startFalling(); while(window.isOpen()){ if(!shared.win && shared.game_state == 1) { //game if (((move & 1) == 0) && sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){ move |= 1; player.startMoving(Left); }else if(!sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){ move &= ~1; } if (((move & 2) == 0) && sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){ move |= 2; player.startMoving(Right); }else if(!sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){ move &= ~2; } if((move & 3) ==0){ player.stopMoving(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)){ move |= 4; player.jump(); }else{ player.enableJump(); } if(player.execute()) shared.game_over = true; int i=0; for(Object *enemy : shared.enemies){ enemy->execute(); enemy->update(); for(Object *object : shared.objects){ if(enemy->colision(*object) & 7){ //any vertical collision (right or left), or bottom if(object->type==ObjectType::Player){ shared.game_over = true; } enemy->reverseDirection(); } if(enemy->colision(*object) & 8){ shared.enemies.erase(shared.enemies.begin()+i, shared.enemies.begin()+i+1); } } i++; } if(!shared.game_over && player.getPosition().x < window.getViewCenter().x - window.view.getSize().x/4 && fabs(player.getPosition().x - castle.getPosition().x) > 100.0f){ window.setViewCenter(player.getPosition().x + window.view.getSize().x/4 ,300); player.right_limit = window.getViewCenter().x + window.view.getSize().x/2 - 20; player.left_limit = window.getViewCenter().x - window.view.getSize().x/2 + 20; } bool on_floor = false; for(Object *o : shared.objects){ if(o!=&player){ if((player.colision(*o) & 4) !=0) on_floor = true; } } if(on_floor) player.enableJump(); else player.disableJump(); player.update(); if(!shared.game_over && fabs(player.getPosition().x - castle.getPosition().x) < 3.0f && fabs(player.getPosition().y - castle.getPosition().y) < 3.0f) shared.win = true; }else if(shared.game_state == 2) { // main menu screen if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){ sf::Vector2i clickPosition = sf::Mouse::getPosition(*window.getWindow()); if(clickPosition.x > 10 && clickPosition.x < 100 && // start button clickPosition.y > 10 && clickPosition.y < 100){ shared.game_state = 1; } } } } return 0; }
void MoveList (short int side, register short int ply) /* * Fill the array Tree[] with all available moves for side to play. Array * TrPnt[ply] contains the index into Tree[] of the first move at a ply. */ { register short i, xside, f; xside = side ^ 1; TrP = &TrPnt[ply + 1]; *TrP = TrPnt[ply]; if (!PV) Swag0 = killr0[ply]; else Swag0 = PV; Swag1 = killr1[ply]; Swag2 = killr2[ply]; Swag3 = killr3[ply]; if (ply > 2) Swag4 = killr1[ply - 2]; else Swag4 = 0; #ifdef KILLT sidebit = ((side == white) ? 0 : 0x80); killt[SwagHt | sidebit] += 5000; killt[Swag0 | sidebit] += 2000; killt[Swag1 | sidebit] += 60; killt[Swag2 | sidebit] += 50; killt[Swag3 | sidebit] += 40; killt[Swag4 | sidebit] += 30; #endif #ifdef HISTORY i = (side == black)?0x4000:0; history[SwagHt | i] += 5000; history[Swag0 | i] += 2000; history[Swag1 | i] += 60; history[Swag2 | i] += 50; history[Swag3 | i] += 40; history[Swag4 | i] += 30; #endif for (i = PieceCnt[side]; i >= 0; i--) GenMoves (ply, PieceList[side][i], side, xside); if (!castld[side]) { f = PieceList[side][0]; if (castle (side, f, f + 2, 0)) { LinkMove (ply, f, f + 2, cstlmask, xside); } if (castle (side, f, f - 2, 0)) { LinkMove (ply, f, f - 2, cstlmask, xside); } } if (epsquare > 0) { f = epmove1[epsquare]; if (color[f] == side && board[f] == pawn) LinkMove (ply, f, epsquare, capture | epmask, xside); f = epmove2[epsquare]; if (color[f] == side && board[f] == pawn) LinkMove (ply, f, epsquare, capture | epmask, xside); } #ifdef KILLT killt[SwagHt | sidebit] -= 5000; killt[Swag0 | sidebit] -= 2000; killt[Swag1 | sidebit] -= 60; killt[Swag2 | sidebit] -= 50; killt[Swag3 | sidebit] -= 40; killt[Swag4 | sidebit] -= 30; #endif #ifdef HISTORY i = (side == black)?0x4000:0; history[SwagHt | i] -= 5000; history[Swag0 | i] -= 2000; history[Swag1 | i] -= 60; history[Swag2 | i] -= 50; history[Swag3 | i] -= 40; history[Swag4 | i] -= 30; #endif SwagHt = 0; /* SwagHt is only used once */ GenCnt += (TrPnt[ply+1] - TrPnt[ply]); }
int main(int argc, char *argv[]) { castle(30, 70); }
void BOARD::helpFindBestMoves ( int lookAhead, PIECECOLOR moveColor, BOARDMETRIC &metric, BESTMOVES *bestMoves ) { POSITION where; POSITIONLIST moves; BOARDMETRIC testMetric; BOOL metricSet = FALSE; MOVEUNDODATA undoData; int m, compareResult; int origMaterialDiff = metric.materialDiff; MOVETYPE castleType; testMetric.kingSituation[WHITE] = KINGOK; testMetric.kingSituation[BLACK] = KINGOK; // try all possible moves for the given color for (where.row = 0; where.row < NUMROWS; where.row++) for (where.col = 0; where.col < NUMCOLS; where.col++) { if (whatPiece(where)) if (whatPiece(where)->whatColor() == moveColor) { whatPiece(where)->legalMoves(where, *this, moves); for (m = 0; m < moves.nMoves; m++) { testMetric.materialDiff = origMaterialDiff; doMove ( where, moves.end[m], undoData ); if (undoData.capturedPiece) { if (undoData.capturedPiece->whatType() == TYPEKING) { undoMove ( moves.end[m], where, undoData ); metric.kingSituation[OtherColor(moveColor)] = KINGLOST; if (bestMoves) { bestMoves->nMoves = 0; bestMoves->move[0] = PIECEMOVE ( NORMALMOVE, where, moves.end[m] ); } return; } testMetric.materialDiff -= undoData.capturedPiece->signedValue(); } if (canPromote(moves.end[m])) { testMetric.materialDiff -= whatPiece(moves.end[m])->signedValue(); promote(moves.end[m], TYPEQUEEN); testMetric.materialDiff += whatPiece(moves.end[m])->signedValue(); if (lookAhead > 1) helpFindBestMoves ( lookAhead - 1, OtherColor(moveColor), testMetric, (BESTMOVES *) 0 ); compareResult = compareMetric ( testMetric, metric, metricSet, moveColor ); if (compareResult >= 0) { if (compareResult > 0) { metric = testMetric; metricSet = TRUE; if (bestMoves) bestMoves->nMoves = 0; } if (bestMoves) bestMoves->move[bestMoves->nMoves++] = PIECEMOVE ( NORMALMOVE, where, moves.end[m], TYPEQUEEN ); } testMetric.materialDiff -= whatPiece(moves.end[m])->signedValue(); restorePawn(moves.end[m]); promote(moves.end[m], TYPEKNIGHT); testMetric.materialDiff += whatPiece(moves.end[m])->signedValue(); if (lookAhead > 1) helpFindBestMoves ( lookAhead - 1, OtherColor(moveColor), testMetric, (BESTMOVES *) 0 ); compareResult = compareMetric ( testMetric, metric, metricSet, moveColor ); if (compareResult >= 0) { if (compareResult > 0) { metric = testMetric; metricSet = TRUE; if (bestMoves) bestMoves->nMoves = 0; } if (bestMoves) bestMoves->move[bestMoves->nMoves++] = PIECEMOVE ( NORMALMOVE, where, moves.end[m], TYPEKNIGHT ); } restorePawn(moves.end[m]); } else // no promotion { if (lookAhead > 1) helpFindBestMoves ( lookAhead - 1, OtherColor(moveColor), testMetric, (BESTMOVES *) 0 ); compareResult = compareMetric ( testMetric, metric, metricSet, moveColor ); if (compareResult >= 0) { if (compareResult > 0) { metric = testMetric; metricSet = TRUE; if (bestMoves) bestMoves->nMoves = 0; } if (bestMoves) bestMoves->move[bestMoves->nMoves++] = PIECEMOVE ( NORMALMOVE, where, moves.end[m] ); } } undoMove ( moves.end[m], where, undoData ); } // end of for loop over each legal move for piece } } // end of double for loop over each board position // only try castling moves if look ahead move than one, since // nothing can be captured by doing a castling move if (lookAhead > 1) { castleType = QUEENSIDECASTLE; for ( ; ; ) { if (canCastle(castleType, moveColor)) { testMetric.materialDiff = origMaterialDiff; castle(castleType, moveColor, undoData); helpFindBestMoves ( lookAhead - 1, OtherColor(moveColor), testMetric, (BESTMOVES *) 0 ); compareResult = compareMetric ( testMetric, metric, metricSet, moveColor ); if (compareResult >= 0) { if (compareResult > 0) { metric = testMetric; metricSet = TRUE; if (bestMoves) bestMoves->nMoves = 0; } if (bestMoves) bestMoves->move[bestMoves->nMoves++] = PIECEMOVE(castleType); } undoCastle(castleType, moveColor, undoData); } if (castleType == KINGSIDECASTLE) break; castleType = KINGSIDECASTLE; } // see if the loss of the king is the result of a stalemate // instead of check mate if (metric.kingSituation[moveColor] == KINGLOST) { helpFindBestMoves ( 1, OtherColor(moveColor), testMetric, (BESTMOVES *) 0 ); if (testMetric.kingSituation[moveColor] != KINGLOST) // king will be lost on next move, but is not in check metric.kingSituation[moveColor] = STALEMATE; } } return; }