Shred::Shred(const int shred_x, const int shred_y, const long longi, const long lati) : longitude(longi), latitude(lati), shredX(shred_x), shredY(shred_y), type(), activeListAll(), activeListFrequent(), shiningList(), fallList(), weather(WEATHER_CLEAR) { if ( LoadShred() ) return; // successfull loading // new shred generation: Block * const null_stone = Normal(NULLSTONE); Block * const air = Normal(AIR); Block * const sky = Normal(SKY); Block * const star = Normal(STAR); SetAllLightMapNull(); for (int i=0; i<SHRED_WIDTH; ++i) for (int j=0; j<SHRED_WIDTH; ++j) { PutBlock(null_stone, i, j, 0); for (int k=1; k<HEIGHT-1; ++k) { PutBlock(air, i, j, k); } PutBlock(((qrand()%5) ? sky : star), i, j, HEIGHT-1); } switch ( type = static_cast<shred_type> (GetWorld()->GetMap()->TypeOfShred(longi, lati)) ) { case SHRED_WASTE: WasteShred(); break; case SHRED_WATER: Water(); break; case SHRED_PLAIN: Plain(); break; case SHRED_MOUNTAIN: Mountain(); break; case SHRED_DESERT: Desert(); break; case SHRED_HILL: Hill(false); break; case SHRED_DEAD_HILL: Hill(true); break; case SHRED_FOREST: Forest(false); break; case SHRED_DEAD_FOREST: Forest(true); break; case SHRED_NULLMOUNTAIN: NullMountain(); break; case SHRED_TESTSHRED: TestShred(); break; case SHRED_PYRAMID: Pyramid(); break; case SHRED_CASTLE: Castle(); break; case SHRED_CHAOS: ChaosShred(); break; case SHRED_EMPTY: break; case SHRED_ACID_LAKE: Water(ACID ); break; case SHRED_LAVA_LAKE: Water(STONE); break; case SHRED_CRATER: Water(AIR); break; case SHRED_NORMAL_UNDERGROUND: NormalUnderground(); break; } } // Shred::Shred(int shred_x, shred_y, long longi, lati, Shred * mem)
void Play() { CurrentBoardPosition=-1; MoveClassification=0; MoveAlreadyMadeFlag=0; Error=0; PieceError=0; if(MoveCycleNumber==1) { WhitePawnEnPassantFlag=0; BlackPawnEnPassantFlag=0; } while(Error==0) { PlayInputTranslate(); Castle(); Whitepawn(); ErrorSignal(); CHECKERROR BlackPawn(); ErrorSignal(); CHECKERROR PawnToQueen(); Rook(); ErrorSignal(); CHECKERROR Knight(); ErrorSignal(); CHECKERROR Bishop(); ErrorSignal(); CHECKERROR Queen(); ErrorSignal(); CHECKERROR King(); ErrorSignal(); CHECKERROR Etc(); ErrorSignal(); break; } }
void World::generateLevel() { float y = Platform::PLATFORM_HEIGHT / 2; float maxJumpHeight = Bob::BOB_JUMP_VELOCITY * Bob::BOB_JUMP_VELOCITY / (2 * -gravity.y); while(y < WORLD_HEIGHT - WORLD_WIDTH / 2) { int type = MathUtils::randomFloat() > 0.8f ? Platform::PLATFORM_TYPE_MOVING : Platform::PLATFORM_TYPE_STATIC; float x = MathUtils::randomFloat() * (WORLD_WIDTH - Platform::PLATFORM_WIDTH) + Platform::PLATFORM_WIDTH / 2; Platform platform(type, x, y); platforms.push_back(platform); if(MathUtils::randomFloat() > 0.9f && type != Platform::PLATFORM_TYPE_MOVING) { Spring spring(platform.position.x, platform.position.y + Platform::PLATFORM_HEIGHT / 2 + Spring::SPRING_HEIGHT / 2); springs.push_back(spring); } if(y > WORLD_HEIGHT / 3 && MathUtils::randomFloat() > 0.8f) { Squirrel squirrel(platform.position.x + MathUtils::randomFloat(), platform.position.y + Squirrel::SQUIRREL_HEIGHT + MathUtils::randomFloat() * 2); squirrels.push_back(squirrel); } if(MathUtils::randomFloat() > 0.6f) { Coin coin(platform.position.x + MathUtils::randomFloat(), platform.position.y + Coin::COIN_HEIGHT + MathUtils::randomFloat() * 3); coins.push_back(coin); } y += (maxJumpHeight - 0.5f); y -= MathUtils::randomFloat() * (maxJumpHeight / 3); } castle = Castle(WORLD_WIDTH / 2, y); }
/* ******************************************************************************* * * * SetBoard() is used to set up the board in any position desired. It uses * * a forsythe-like string of characters to describe the board position. * * * * The standard piece codes p,n,b,r,q,k are used to denote the type of piece * * on a square, upper/lower case are used to indicate the side (program/opp.)* * of the piece. * * * * The pieces are entered with square a8 first, then b8, ... until the full * * 8th rank is completed. A "/" terminates that rank. This is repeated for * * each of the 8 ranks, with the last (1st) rank not needing a terminating * * "/". For empty squares, a number between 1 and 8 can be used to indicate * * the number of adjacent empty squares. * * * * That board description must be followed by a "b" or "w" to indicate which * * side is on move. * * * * Next, up to 4 characters are used to indicate which side can castle and * * to which side. An uppercase K means white can castle kingside, while a * * lowercase q means black can castle queenside. * * * * Finally, if there is an enpassant capture possible (the last move was a * * double pawn move and there was an enemy pawn that could capture it. The * * square is the square the capturing pawn ends up on. * * * * K2R/PPP////q/5ppp/7k/ b - - * * * * this assumes that k represents a white king and -q represents a black * * queen. * * * * k * * r * * * * * * p p p * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -q * * * * * * * * * * * * * * -p -p -p * * * * * * * * * -k * * * ******************************************************************************* */ void SetBoard(TREE * tree, int nargs, char *args[], int special) { int twtm, i, match, num, pos, square, tboard[64]; int bcastle, ep, wcastle, error = 0; char input[80]; static const char bdinfo[] = { 'k', 'q', 'r', 'b', 'n', 'p', '*', 'P', 'N', 'B', 'R', 'Q', 'K', '*', '1', '2', '3', '4', '5', '6', '7', '8', '/' }; static const char status[13] = { 'K', 'Q', 'k', 'q', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', ' ' }; int whichsq; static const int firstsq[8] = { 56, 48, 40, 32, 24, 16, 8, 0 }; if (special) strcpy(input, initial_position); else strcpy(input, args[0]); for (i = 0; i < 64; i++) tboard[i] = 0; /* ************************************************************ * * * Scan the input string searching for pieces, numbers * * [empty squares], slashes [end-of-rank] and a blank * * [end of board, start of castle status]. * * * ************************************************************ */ whichsq = 0; square = firstsq[whichsq]; num = 0; for (pos = 0; pos < (int) strlen(args[0]); pos++) { for (match = 0; match < 23 && args[0][pos] != bdinfo[match]; match++); if (match > 22) break; /* "/" -> end of this rank. */ else if (match == 22) { num = 0; if (whichsq > 6) break; square = firstsq[++whichsq]; } /* "1-8" -> empty squares. */ else if (match >= 14) { num += match - 13; square += match - 13; if (num > 8) { printf("more than 8 squares on one rank\n"); error = 1; break; } continue; } /* piece codes. */ else { if (++num > 8) { printf("more than 8 squares on one rank\n"); error = 1; break; } tboard[square++] = match - 6; } } /* ************************************************************ * * * Now extract (a) side to move [w/b], (b) castle status * * [KkQq for white/black king-side ok, white/black queen- * * side ok], (c) enpassant target square. * * * ************************************************************ */ twtm = 0; ep = 0; wcastle = 0; bcastle = 0; /* ************************************************************ * * * Side to move. * * * ************************************************************ */ if (args[1][0] == 'w') twtm = 1; else if (args[1][0] == 'b') twtm = 0; else { printf("side to move is bad\n"); error = 1; } /* ************************************************************ * * * Castling/enpassant status. * * * ************************************************************ */ if (nargs > 2 && strlen(args[2])) { if (strcmp(args[2], "-")) { for (pos = 0; pos < (int) strlen(args[2]); pos++) { for (match = 0; (match < 13) && (args[2][pos] != status[match]); match++); if (match == 0) wcastle += 1; else if (match == 1) wcastle += 2; else if (match == 2) bcastle += 1; else if (match == 3) bcastle += 2; else if (args[2][0] != '-') { printf("castling status is bad.\n"); error = 1; } } } } if (nargs > 3 && strlen(args[3])) { if (strcmp(args[3], "-")) { if (args[3][0] >= 'a' && args[3][0] <= 'h' && args[3][1] > '0' && args[3][1] < '9') { ep = (args[3][1] - '1') * 8 + args[3][0] - 'a'; } else if (args[3][0] != '-') { printf("enpassant status is bad.\n"); error = 1; } } } for (i = 0; i < 64; i++) PcOnSq(i) = tboard[i]; Castle(0, white) = wcastle; Castle(0, black) = bcastle; EnPassant(0) = 0; if (ep) { if (Rank(ep) == RANK6) { if (PcOnSq(ep - 8) != -pawn) ep = 0; } else if (Rank(ep) == RANK3) { if (PcOnSq(ep + 8) != pawn) ep = 0; } else ep = 0; if (!ep) { printf("enpassant status is bad (must be on 3rd/6th rank only.\n"); ep = 0; error = 1; } EnPassant(0) = ep; } Rule50Moves(0) = 0; /* ************************************************************ * * * Now check the castling status and enpassant status to * * make sure that the board is in a state that matches * * these. * * * ************************************************************ */ if (((Castle(0, white) & 2) && (PcOnSq(A1) != rook)) || ((Castle(0, white) & 1) && (PcOnSq(H1) != rook)) || ((Castle(0, black) & 2) && (PcOnSq(A8) != -rook)) || ((Castle(0, black) & 1) && (PcOnSq(H8) != -rook))) { printf("ERROR-- castling status does not match board position\n"); error = 1; } /* ************************************************************ * * * Now set the bitboards so that error tests can be done. * * * ************************************************************ */ if ((twtm && EnPassant(0) && (PcOnSq(EnPassant(0) + 8) != -pawn) && (PcOnSq(EnPassant(0) - 7) != pawn) && (PcOnSq(EnPassant(0) - 9) != pawn)) || (Flip(twtm) && EnPassant(0) && (PcOnSq(EnPassant(0) - 8) != pawn) && (PcOnSq(EnPassant(0) + 7) != -pawn) && (PcOnSq(EnPassant(0) + 9) != -pawn))) { EnPassant(0) = 0; } SetChessBitBoards(tree); /* ************************************************************ * * * Now check the position for a sane position, which * * means no more than 8 pawns, no more than 10 knights, * * bishops or rooks, no more than 9 queens, no pawns on * * 1st or 8th rank, etc. * * * ************************************************************ */ wtm = twtm; error += InvalidPosition(tree); if (!error) { if (log_file) DisplayChessBoard(log_file, tree->pos); tree->rep_index[white] = 0; tree->rep_index[black] = 0; Rule50Moves(0) = 0; if (!special) { last_mate_score = 0; InitializeKillers(); last_pv.pathd = 0; last_pv.pathl = 0; tree->pv[0].pathd = 0; tree->pv[0].pathl = 0; moves_out_of_book = 0; } } else { if (special) Print(4095, "bad string = \"%s\"\n", initial_position); else Print(4095, "bad string = \"%s\"\n", args[0]); InitializeChessBoard(tree); Print(4095, "Illegal position, using normal initial chess position\n"); } }
int ChessBoard::MakeMove(const ChessMove& move) { if (move.isCastle() ) { ChessPiece* _king; ChessPiece* _rook; if (bWhiteMove) _king = GetPiece(_WhitePlayer->GetKingLocation()); else { _king = GetPiece(_BlackPlayer->GetKingLocation()); } int col; if (bWhiteMove) col = 0; else { col = 7; } if (move.isKingSideCastle() ) { _rook = GetPiece(7, col); Castle(_king, _rook, true, col); } else { _rook = GetPiece(0, col); Castle(_king, _rook, false, col); } } else if (move.isPromotion() ) { ChessPiece* _pawn = GetPiece(move.getStartingRow(), move.getStartingCol()); ChessSquare* newMove = new ChessSquare(move.getRow(), move.getCol() ); PromotePawn(dynamic_cast<Pawn*>(_pawn), newMove , move.GetPromotionChar() ); //ChessBoard::GetInstance()->PrintBoard(); delete newMove; } else if (move.IsEnPassant()) { EnPassantCapture(move.getPiece(), ChessSquare(move.getRow(), move.getCol()), move.getCapturedPiece()->GetLocation()); // to code this later } else if (move.isCapture()) { MakeCapture(move.getPiece(), ChessSquare(move.getRow(), move.getCol())); } else MovePiece(move.getPiece(), move.getRow(), move.getCol()); if (move.isPromotion()) { ResolveLineOfSight(Board[move.getRow()][move.getCol()]); } else if (!move.isCastle()) { ResolveLineOfSight(move.getPiece()); } else { ResolveCastleLineOfSight(!bWhiteMove); } //move->Delete(); //delete(move); return 0; }