void KeyEvent(unsigned char key,int x,int y){ if(key==0x1b) CleanUp(),exit(0); if(key=='a') MovePiece(2,f,p); if(key=='d') MovePiece(4,f,p); if(key==' ') RolePiece(0,f,p); if(key=='s') MovePiece(3,f,p); }
void Board::UndoMove(const Move& inputMove, Players player){ _moveFinder->Invalidate(); Move move = ShiftMoveBack(inputMove); Vector2D from = _converter->ToAbsolute(move.GetFromCell()); Vector2D to = _converter->ToAbsolute(move.GetToCell()); Vector2D used; if(move.HasUsedCell()){ used = _converter->ToAbsolute(move.GetUsedCell()); } switch(move.GetMoveType()){ case INSERT: DeletePiece(*_grid->GetCellAt(to)); return; case STEP: if(move.HasUsedCell()){ MovePiece( *_grid->GetCellAt(to), *_grid->GetCellAt(from), player ); MoveTile(*_grid->GetCellAt(to), *_grid->GetCellAt(used)); return; } MovePiece( *_grid->GetCellAt(to), *_grid->GetCellAt(from), player ); return; case JUMP: if(move.HasUsedCell()){ JumpPiece( *_grid->GetCellAt(to), *_grid->GetCellAt(from), player ); MoveTile(*_grid->GetCellAt(to), *_grid->GetCellAt(used)); return; } JumpPiece( *_grid->GetCellAt(to), *_grid->GetCellAt(from), player ); return; } }
void Board::ExecuteMove(const Move& move, Players player) { _moveFinder->Invalidate(); Vector2D from = _converter->ToAbsolute(move.GetFromCell()); Vector2D to = _converter->ToAbsolute(move.GetToCell()); Vector2D used; if(move.HasUsedCell()){ used = _converter->ToAbsolute(move.GetUsedCell()); } switch(move.GetMoveType()){ case INSERT: InsertPiece(*_grid->GetCellAt(to), player); return; case STEP: if(move.HasUsedCell()){ MovePiece( *_grid->GetCellAt(from), *_grid->GetCellAt(to), player, *_grid->GetCellAt(used) ); return; } MovePiece( *_grid->GetCellAt(from), *_grid->GetCellAt(to), player ); return; case JUMP: if(move.HasUsedCell()){ JumpPiece( *_grid->GetCellAt(from), *_grid->GetCellAt(to), player, *_grid->GetCellAt(used) ); return; } JumpPiece( *_grid->GetCellAt(from), *_grid->GetCellAt(to), player ); return; } }
Move GetMove(Dudes *Board[8][8]) { Move move; Coordinates FromCoords = GetFromCoords(Board); Coordinates ToCoords= GetToCoords(Board); move.To = ToCoords; move.From = FromCoords; MovePiece(&move, Board); }
void Gamekeys(void) { char *charptr; /* Set up a pointer to the variable we want to change * (either the box or the ball) */ charptr = PieceIsBall ? &BoxOffset : &BallOffset; switch(getk()) { case K_DOWN: MovePiece(charptr,0,+1); break; case K_UP: MovePiece(charptr,0,-1); break; case K_RIGHT: MovePiece(charptr,+1,0); break; case K_LEFT: MovePiece(charptr,-1,0); break; case K_SWITCH: PieceIsBall^=1; /* Toggle ball/box */ break; case K_EXIT: exit(0); case K_NEXTLEV: /* Okay this IS cheating... */ if(++Level==MAXLEVEL) { --Level; break; } SetupLevel(); break; case K_PREVLEV: if(--Level==-1) { ++Level; break; } /* fall thrue */ case K_CLEAR: SetupLevel(); } }
BOOL _PositionStruct::IsMate(void) { int i, nGenMoveNum, pcCaptured; int mvs[MAX_GEN_MOVES]; nGenMoveNum = GenerateMoves(mvs); for (i = 0; i < nGenMoveNum; i ++) { pcCaptured = MovePiece(mvs[i]); if (!Checked()) { UndoMovePiece(mvs[i], pcCaptured); return FALSE; } else { UndoMovePiece(mvs[i], pcCaptured); } } return TRUE; }
BOOL _PositionStruct::MakeMove(int mv, int* ppcCaptured /*= NULL*/) { int pcCaptured; DWORD dwKey; dwKey = zobr.dwKey; pcCaptured = MovePiece(mv); if (Checked()) { UndoMovePiece(mv, pcCaptured); return FALSE; } ChangeSide(); mvsList[nMoveNum].Set(mv, pcCaptured, Checked(), dwKey); nMoveNum ++; nDistance ++; // (HPHAN) Return the captured piece as well. if ( ppcCaptured != NULL ) { *ppcCaptured = pcCaptured; } return TRUE; }
int state_see(state_t *state, int move) { uint64_t attackers = util_attacks_to(state, MoveFrom(move)) & ~(1ull << MoveFrom(move)); int attacked = eval_piece_values[MovePiece(move)]; int color = Flip(state->turn); int ply = 1; int attacker; int swapstack[64]; swapstack[0] = eval_real_pvalues[MoveCapture(move)]; while (attackers) { uint64_t hits; for (attacker = PAWN; attacker <= KING; ++attacker) { hits = state->pieces[color][attacker] & attackers; if (hits) { break; } } if (attacker > KING) break; attackers ^= hits & -hits; swapstack[ply] = -swapstack[ply - 1] + attacked; attacked = eval_real_pvalues[attacker]; color = Flip(color); ply += 1; } while (--ply) swapstack[ply - 1] = -Max(-swapstack[ply - 1], swapstack[ply]); return swapstack[0]; }
void Board::MakeCastleMove(int piece, int destPiece, int source, int destination) { // Handle castling if (Pieces::GetPieceTypeFromPiece(piece) == PieceTypes::King) { int delta = destination - source; if(delta == 2 || delta == -2) { int rookOrigin = destination + delta / 2; if(delta < 0) { rookOrigin--; } int rookDestination = destination - delta / 2; int rook = Pieces::GetPiece(PieceTypes::Rook, turn); MovePiece(rookOrigin, rookDestination, rook); ulong oldKey = TranspositionTable::GetPositionKey(rookOrigin, rook); ulong newKey = TranspositionTable::GetPositionKey(rookDestination, rook); zobristKey ^= oldKey; zobristKey ^= newKey; positionalScore -= Evaluation::PieceSquareValue(rook, rookOrigin); positionalScore += Evaluation::PieceSquareValue(rook, rookDestination); endgamePositionalScore -= Evaluation::EndgamePieceSquareValue(rook, rookOrigin); endgamePositionalScore += Evaluation::EndgamePieceSquareValue(rook, rookDestination); } } if(castleRights.HasRights()) { CastleRights newCastleRights = castleRights; // Update castle rights if (piece == Pieces::WhiteKing) { newCastleRights.ClearWhiteKing(); newCastleRights.ClearWhiteQueen(); } else if(piece == Pieces::BlackKing) { newCastleRights.ClearBlackKing(); newCastleRights.ClearBlackQueen(); } else if (piece == Pieces::WhiteRook) { if (source == MoveGenerator::whiteKingsideRook) { newCastleRights.ClearWhiteKing(); } else if (source == MoveGenerator::whiteQueensideRook) { newCastleRights.ClearWhiteQueen(); } } else if (piece == Pieces::BlackRook) { if (source == MoveGenerator::blackKingsideRook) { newCastleRights.ClearBlackKing(); } else if (source == MoveGenerator::blackQueensideRook) { newCastleRights.ClearBlackQueen(); } } // did we capture a rook? if (destPiece == Pieces::BlackRook) { if (destination == MoveGenerator::blackKingsideRook) { newCastleRights.ClearBlackKing(); } else if (destination == MoveGenerator::blackQueensideRook) { newCastleRights.ClearBlackQueen(); } } else if(destPiece == Pieces::WhiteRook) { if (destination == MoveGenerator::whiteKingsideRook) { newCastleRights.ClearWhiteKing(); } else if (destination == MoveGenerator::whiteQueensideRook) { newCastleRights.ClearWhiteQueen(); } } if(newCastleRights.GetRights() != castleRights.GetRights()) { zobristKey ^= TranspositionTable::GetCastleKey(castleRights); castleRights = newCastleRights; zobristKey ^= TranspositionTable::GetCastleKey(castleRights); } } }
void Board::UndoMove(int move, bool updateDrawState, const BoardState& undoState) { updateDrawState = true; isInCheck = undoState.isInCheck; castleRights = undoState.castleRights; enPassantRights = undoState.enPassantRights; drawMoveCount = undoState.drawMoveCount; materialScore = undoState.materialScore; positionalScore = undoState.positionalScore; endgamePositionalScore = undoState.endgamePositionalScore; if (move != NullMove) { turnsPlayed--; UndoMoveDrawState(updateDrawState); int source = GetSourceFromMove(move); int dest = GetDestFromMove(move); int piece = GetPiece(dest); MovePiece(dest, source, piece); if (GetPromoFromMove(move) != PieceTypes::None) { RemovePiece(source, piece); int oldPiece = Pieces::GetPiece(PieceTypes::Pawn, OtherColor(turn)); AddPiece(source, oldPiece); } if (capturedPiece != PieceTypes::None) { int capture = Pieces::GetPiece(capturedPiece, turn); // was this an en passant capture? if (enPassantRights.HasEnPassant() && dest == enPassantRights.CaptureSquare() && Pieces::GetPieceTypeFromPiece(piece) == PieceTypes::Pawn) { AddPiece(enPassantRights.PawnSquare(), capture); } else { AddPiece(dest, capture); } } // if this was a castle move, restore the rook if (Pieces::GetPieceTypeFromPiece(piece) == PieceTypes::King) { int delta = dest - source; if(delta == 2 || delta == -2) { int rookOrigin = dest + delta / 2; if(delta < 0) { rookOrigin--; } int rookDestination = dest - delta / 2; int rook = Pieces::GetPiece(PieceTypes::Rook, OtherColor(turn)); MovePiece(rookDestination, rookOrigin, rook); } } capturedPiece = undoState.capturedPiece; } turn = OtherColor(turn); zobristKey = undoState.zobristKey; pawnZobristKey = undoState.pawnZobristKey; }
void Board::MovePiece(Cell<int>& from, Cell<int>& to, Players owner, Cell<int>& tileUsed){ // convertions already happend save to update converter _moveFinder->Invalidate(); MoveTile(tileUsed, to); MovePiece(from, to, owner); }
void Board::MakeMove(int move, bool updateDrawState, BoardState& undoState) { updateDrawState = true; undoState.isInCheck = isInCheck; undoState.capturedPiece = capturedPiece; undoState.castleRights = castleRights; undoState.enPassantRights = enPassantRights; undoState.drawMoveCount = drawMoveCount; undoState.zobristKey = zobristKey; undoState.pawnZobristKey = pawnZobristKey; undoState.materialScore = materialScore; undoState.positionalScore = positionalScore; undoState.endgamePositionalScore = endgamePositionalScore; if (move != NullMove) { drawMoveCount++; int source = GetSourceFromMove(move); int destination = GetDestFromMove(move); int piece = GetPiece(source); int destPiece = GetPiece(destination); MakeCaptureMove(destination, destPiece); MovePiece(source, destination, piece); MakePromotionMove(move, source, destination, piece); MakeCastleMove(piece, destPiece, source, destination); bool isPawn = Pieces::GetPieceTypeFromPiece(piece) == PieceTypes::Pawn; MakeEnPassantMove(isPawn, source, destination); turn = OtherColor(turn); zobristKey ^= TranspositionTable::GetTurnKey(); //assert(!IsKingInCheck(OtherColor(turn))); ulong oldKey = TranspositionTable::GetPositionKey(source, piece); ulong newKey = TranspositionTable::GetPositionKey(destination, piece); ulong diff = oldKey ^ newKey; zobristKey ^= diff; if (isPawn) { pawnZobristKey ^= diff; drawMoveCount = 0; } positionalScore -= Evaluation::PieceSquareValue(piece, source); positionalScore += Evaluation::PieceSquareValue(piece, destination); endgamePositionalScore -= Evaluation::EndgamePieceSquareValue(piece, source); endgamePositionalScore += Evaluation::EndgamePieceSquareValue(piece, destination); MakeMoveDrawState(updateDrawState); turnsPlayed++; isInCheck = IsKingInCheck(turn); } else { // don't allow a null move when in check. assert(!GetIsInCheck()); zobristKey ^= TranspositionTable::GetEnPassantKey(enPassantRights); enPassantRights = EnPassantRights::NoEnPassant; zobristKey ^= TranspositionTable::GetEnPassantKey(enPassantRights); turn = OtherColor(turn); zobristKey ^= TranspositionTable::GetTurnKey(); } }
void MakeMove(int mv) { // 走一步棋 MovePiece(mv); ChangeSide(); }
void Board::JumpPiece(Cell<int>& from, Cell<int>& to, Players owner){ _moveFinder->Invalidate(); Flip(from); MovePiece(from, to, owner); }
int main() { LoadAssets(); ClearObjects(); InitialiseStage(); uint16_t oldKeys = REG_P1; Cursor cursor = Cursor(0); bool pieceSelected = false; int currentPiece = 0; int* moves = new int[28]; int* takingMoves = new int[16]; int currentTurnColor = WHITE; for(int i = 0; i < 2; i++) for(int j = 0; j < 16; j++) _lostPieces[i][j] = -1; while (true) { if(!(REG_P1 & KEY_RIGHT) && (oldKeys & KEY_RIGHT)) cursor.Move(1, 0); if(!(REG_P1 & KEY_LEFT) && (oldKeys & KEY_LEFT)) cursor.Move(-1, 0); if(!(REG_P1 & KEY_DOWN) && (oldKeys & KEY_DOWN)) cursor.Move(0, 1); if(!(REG_P1 & KEY_UP) && (oldKeys & KEY_UP)) cursor.Move(0, -1); if(!(REG_P1 & KEY_A) && (oldKeys & KEY_A)) { if(PieceAt(cursor.X(), cursor.Y())) { pieceSelected = true; for(int i = 0; i < 16 && takingMoves[i] >= 0; i++) if(takingMoves[i] % 8 == cursor.X() && takingMoves[i] / 8 == cursor.Y()) { TakePiece(currentPiece % 8, currentPiece / 8, cursor.X(), cursor.Y()); currentTurnColor = (currentTurnColor == WHITE ? BLACK : WHITE); pieceSelected = false; ClearHighlights(); takingMoves[0] = -1; break; } if(pieceSelected && PieceColor(cursor.X(), cursor.Y()) == currentTurnColor) { ClearHighlights(); AvailableMoves(cursor.X(), cursor.Y(), moves, takingMoves); currentPiece = cursor.Y() * 8 + cursor.X(); for(int i = 0; i < 28 && moves[i] >= 0; i++) Highlight(moves[i] % 8, moves[i] / 8, GREEN); for(int i = 0; i < 16 && takingMoves[i] >= 0; i++) Highlight(takingMoves[i] % 8, takingMoves[i] / 8, RED); } } else if(pieceSelected) { ClearHighlights(); if(!PieceAt(cursor.X(), cursor.Y())) { for(int i = 0; i < 28 && moves[i] >= 0; i++) if(moves[i] % 8 == cursor.X() && moves[i] / 8 == cursor.Y()) { MovePiece(currentPiece % 8, currentPiece / 8, cursor.X(), cursor.Y()); currentTurnColor = (currentTurnColor == WHITE ? BLACK : WHITE); pieceSelected = false; break; } } } } oldKeys = REG_P1; if(currentTurnColor == WHITE) DrawString(20, 1, "WHITE", 5); else DrawString(20, 1, "BLACK", 5); WaitVSync(); UpdateObjects(); } return 0; }
void TakePiece(int cx, int cy, int nx, int ny) { MovePiece(cx, cy, nx, ny); }
void Gamekeys(void) { char *charptr; /* Set up a pointer to the variable we want to change * (either the box or the ball) */ charptr = PieceIsBall ? &BoxOffset : &BallOffset; switch(fgetc_cons()) { #ifndef DKTRONICS #ifndef __ZX80__ case '0': #asm ld a,$1e ld i,a #endasm break; case '1': #asm ld a,$2e ld i,a #endasm break; case '2': #asm ld a,$84 ld i,a #endasm break; case '3': #asm ld a,$8e ld i,a #endasm break; case '4': #asm ld a,$9e ld i,a #endasm break; case '5': #asm ld a,$30 ld i,a #endasm break; case '6': #asm ld a,$32 ld i,a #endasm break; #endif #endif case K_DOWN: MovePiece(charptr,0,+1); break; case K_UP: MovePiece(charptr,0,-1); break; case K_RIGHT: MovePiece(charptr,+1,0); break; case K_LEFT: MovePiece(charptr,-1,0); break; case K_SWITCH: PieceIsBall^=1; /* Toggle ball/box */ #ifdef SOUND bit_fx4 (5); #endif //while (getk() == K_SWITCH) {} #ifdef __ZX80__ // make the display 'hop' to notify that we're switching gen_tv_field(); #endif break; case K_EXIT: exit(0); case K_NEXTLEV: /* Okay this IS cheating... */ if(++Level==MAXLEVEL) { --Level; break; } SetupLevel(); break; case K_PREVLEV: if(--Level==-1) { ++Level; break; } /* fall thrue */ case K_CLEAR: #ifdef SOUND bit_fx4 (3); #endif SetupLevel(); break; } }
// On effectue un coup dans l'echiquier. On mettera a jour tout // les structures necessaire. void MakeMove(int ply, TMove& move, int wtm) { // Pour le defaire. cb.Regle50CoupStore[cb.NoCoups] = cb.Regle50Coup; cb.Regle50Coup++; cb.Positions[cb.NoCoups] = cb.CleHachage; // Les coups joues. cb.ListeRoque[cb.NoCoups] = cb.Roque; cb.ListeMove[ cb.NoCoups ] = move; // Effectuer les changements pour toutes les pieces. MovePiece( cb.piece, move ); MovePieceR90L( cb.pieceR90L, move ); MovePieceR45L( cb.pieceR45L, move ); MovePieceR45R( cb.pieceR45R, move ); if ( wtm ) { MovePiece( cb.pieceb, move ); // Si il y avait une piece noire, elle a ete capture. ClearBit( cb.piecen, move.To ); cb.EnPassantB[ply+1] = -1; } else { MovePiece( cb.piecen, move ); // Si il y avait une piece blanche, elle a ete capture. ClearBit( cb.pieceb, move.To ); cb.EnPassantN[ply+1] = -1; } cb.board[move.From] = 0; switch( move.Piece ) { case pion : // On bouge un pion. // 1- On avance d'une ou deux case. // 3- On a une promotion. cb.Regle50Coup=0; if ( wtm ) { MovePiece( cb.pionb, move ); cb.board[move.To] = pion; // On calcul le positonnel. cb.CleHachage ^= ClePionB[move.From]; cb.CleHachage ^= ClePionB[move.To]; if (move.Promotion) { // On enlève un pion. ClearBit( cb.pionb, move.To ); cb.CleHachage ^= ClePionB[move.From]; cb.TotalPionBlanc--; cb.NbWhitePieces++; cb.board[move.To] = move.Promotion; switch( move.Promotion ) { case dame: SetBit( cb.dameb, move.To ); cb.CleHachage ^= CleDameB[move.To]; // Blanc gagne une dame. cb.TotalDameBlanche++; cb.ScoreMaterielBlanc += (SCORE)VALDAME-VALPION; break; case tour: SetBit(cb.tourb, move.To); cb.CleHachage ^= CleTourB[move.To]; // Blanc gagne une tour. cb.TotalTourBlanche++; cb.ScoreMaterielBlanc += (SCORE)VALTOUR-VALPION; break; case fou: SetBit(cb.foub, move.To); cb.CleHachage ^= CleFouB[move.To]; // Blanc gagne une fou. cb.TotalFouBlanc++; cb.ScoreMaterielBlanc += (SCORE)VALFOU-VALPION; break; case cavalier: SetBit(cb.cavalierb, move.To); cb.CleHachage ^= CleCavalierB[move.To]; // Blanc gagne une cavalier. cb.TotalCavalierBlanc++; cb.ScoreMaterielBlanc += (SCORE)VALCAVALIER-VALPION; break; } } } else { // Pions noirs MovePiece( cb.pionn, move ); cb.board[move.To] = -pion; cb.CleHachage ^= ClePionN[move.From]; cb.CleHachage ^= ClePionN[move.To]; if (move.Promotion) { // Enlever un pion. ClearBit( cb.pionn, move.To ); cb.board[move.To] = -(char)move.Promotion; cb.CleHachage ^= ClePionN[move.From]; cb.TotalPionNoir--; cb.NbBlackPieces++; switch( move.Promotion ) { case dame: SetBit( cb.damen, move.To ); cb.CleHachage ^= CleDameN[move.To]; // Noir gagne une dame. cb.TotalDameNoire++; cb.ScoreMaterielNoir += (SCORE)VALDAME-VALPION; break; case tour: SetBit( cb.tourn, move.To ); cb.CleHachage ^= CleTourN[move.To]; // Noir gagne une tour. cb.TotalTourNoire++; cb.ScoreMaterielNoir += (SCORE)VALTOUR-VALPION; break; case fou: SetBit( cb.foun, move.To ); cb.CleHachage ^= CleFouN[move.To]; // Noir gagne un fou. cb.TotalFouNoir++; cb.ScoreMaterielNoir += (SCORE)VALFOU-VALPION; break; case cavalier: SetBit( cb.cavaliern, move.To ); cb.CleHachage ^= CleCavalierN[move.To]; // Noir gagne un cavalier. cb.TotalCavalierNoir++; cb.ScoreMaterielNoir += (SCORE)VALCAVALIER-VALPION; break; } } } break; // Les cavaliers. case cavalier: if ( wtm ) { MovePiece( cb.cavalierb, move ); cb.board[move.To] = cavalier; cb.CleHachage ^= CleCavalierB[move.From]; cb.CleHachage ^= CleCavalierB[move.To]; } else { MovePiece( cb.cavaliern, move ); cb.board[move.To] = -cavalier; cb.CleHachage ^= CleCavalierN[move.From]; cb.CleHachage ^= CleCavalierN[move.To]; } break; // Les fous. case fou: if ( wtm ) { MovePiece( cb.foub, move ); cb.board[move.To] = fou; cb.CleHachage ^= CleFouB[move.From]; cb.CleHachage ^= CleFouB[move.To]; } else { MovePiece( cb.foun, move ); cb.board[move.To] = -fou; cb.CleHachage ^= CleFouN[move.From]; cb.CleHachage ^= CleFouN[move.To]; } break; // Les tours. case tour: if ( wtm ) { MovePiece( cb.tourb, move ); cb.board[move.To] = tour; cb.CleHachage ^= CleTourB[move.From]; cb.CleHachage ^= CleTourB[move.To]; if ( move.From == H1 ) { cb.Roque |= ROQUEROIBLANC; } else if ( move.From == A1 ) { cb.Roque |= ROQUEDAMEBLANC; } } else { MovePiece( cb.tourn, move ); cb.board[move.To] = -tour; cb.CleHachage ^= CleTourN[move.From]; cb.CleHachage ^= CleTourN[move.To]; if ( move.From == H8 ) { cb.Roque |= ROQUEROINOIR; } else if ( move.From == A8 ) { cb.Roque |= ROQUEDAMENOIR; } } break; // Les dames. case dame: if ( wtm ) { MovePiece( cb.dameb, move ); cb.board[move.To] = dame; cb.CleHachage ^= CleDameB[move.From]; cb.CleHachage ^= CleDameB[move.To]; } else { MovePiece( cb.damen, move ); cb.board[move.To] = -dame; cb.CleHachage ^= CleDameN[move.From]; cb.CleHachage ^= CleDameN[move.To]; } break; // Les rois. case roi: if ( wtm ) { MovePiece( cb.roib, move ); cb.board[move.To] = roi; cb.Roque |= ROQUEROIBLANC | ROQUEDAMEBLANC; cb.PositionRoiBlanc = move.To; cb.CleHachage ^= CleRoiB[move.From]; cb.CleHachage ^= CleRoiB[move.To]; // Verifier pour le roque. if ( move.From == E1 && (move.To == G1 || move.To == C1 )) { TMove movetour; // Deplacer la tour. // Cote roi. if ( move.To == G1 ) { movetour.From = H1; movetour.To = F1; } // Cote dame. else { movetour.From = A1; movetour.To = D1; } MovePiece( cb.piece, movetour ); MovePieceR90L( cb.pieceR90L, movetour ); MovePieceR45L( cb.pieceR45L, movetour ); MovePieceR45R( cb.pieceR45R, movetour ); MovePiece( cb.pieceb, movetour ); MovePiece( cb.tourb, movetour ); cb.board[movetour.To] = tour; cb.board[movetour.From] = 0; cb.CleHachage ^= CleTourB[movetour.From]; cb.CleHachage ^= CleTourB[movetour.To]; } } else { MovePiece( cb.roin, move ); cb.board[move.To] = -roi; cb.Roque |= ROQUEROINOIR | ROQUEDAMENOIR; cb.PositionRoiNoir = move.To; cb.CleHachage ^= CleRoiN[move.From]; cb.CleHachage ^= CleRoiN[move.To]; if ( move.From == E8 && (move.To == G8 || move.To == C8 )) { TMove movetour; // Deplacer la tour. // Cote roi. if ( move.To == G8 ) { movetour.From = H8; movetour.To = F8; } else { movetour.From = A8; movetour.To = D8; } MovePiece( cb.piece, movetour ); MovePieceR90L( cb.pieceR90L, movetour ); MovePieceR45L( cb.pieceR45L, movetour ); MovePieceR45R( cb.pieceR45R, movetour ); MovePiece( cb.piecen, movetour ); MovePiece( cb.tourn, movetour ); cb.board[movetour.To] = -tour; cb.board[movetour.From] = 0; cb.CleHachage ^= CleTourN[movetour.From]; cb.CleHachage ^= CleTourN[movetour.To]; } // Roque. } break; } // Maintenant, verifier si une piece a ete capture et mettre a jour // en cas de besoin. if ( move.Capture ) { cb.Regle50Coup=0; switch( move.Capture ) { // Un pion. case pion : if ( wtm ) { // Noir perd un pion. cb.TotalPionNoir--; cb.TotalMaterielNoir--; cb.ScoreMaterielNoir -= VALPION; int to = move.To; if ( move.EnPassant ) { to += 8; cb.board[to] = 0; ClearBit( cb.piece, to ); ClearBit( cb.piecen, to ); ClearR90L( cb.pieceR90L, to ); ClearR45L( cb.pieceR45L, to ); ClearR45R( cb.pieceR45R, to ); } cb.CleHachage ^= ClePionN[to]; ClearBit( cb.pionn, to ); } else { // Blanc perd un pion. cb.TotalPionBlanc--; cb.TotalMaterielBlanc--; cb.ScoreMaterielBlanc -= VALPION; int to = move.To; if ( move.EnPassant ) { to -= 8; cb.board[to] = 0; ClearBit( cb.piece, to ); ClearBit( cb.pieceb, to ); ClearR90L( cb.pieceR90L, to ); ClearR45L( cb.pieceR45L, to ); ClearR45R( cb.pieceR45R, to ); } cb.CleHachage ^= ClePionB[to]; ClearBit( cb.pionb, to ); } break; // Un cavalier. case cavalier : if ( wtm ) { // Noir perd un cavalier. cb.TotalCavalierNoir--; cb.NbBlackPieces--; cb.TotalMaterielNoir--; cb.ScoreMaterielNoir -= VALCAVALIER; ClearBit( cb.cavaliern, move.To ); cb.CleHachage ^= CleCavalierN[move.To]; } else { // Blanc perd un cavalier. cb.TotalCavalierBlanc--; cb.NbWhitePieces--; cb.TotalMaterielBlanc--; cb.ScoreMaterielBlanc -= VALCAVALIER; ClearBit( cb.cavalierb, move.To ); cb.CleHachage ^= CleCavalierB[move.To]; } break; // Un fou. case fou : if ( wtm ) { // Noir perd un fou. cb.TotalFouNoir--; cb.NbBlackPieces--; cb.TotalMaterielNoir--; cb.ScoreMaterielNoir -= VALFOU; ClearBit( cb.foun, move.To ); cb.CleHachage ^= CleFouN[move.To]; } else { // Blanc perd un fou. cb.TotalFouBlanc--; cb.NbWhitePieces--; cb.TotalMaterielBlanc--; cb.ScoreMaterielBlanc -= VALFOU; ClearBit( cb.foub, move.To ); cb.CleHachage ^= CleFouB[move.To]; } break; // Une tour. case tour : if ( wtm ) { // Noir perd une tour. cb.TotalTourNoire--; cb.NbBlackPieces--; cb.TotalMaterielNoir--; cb.ScoreMaterielNoir -= VALTOUR; ClearBit( cb.tourn, move.To ); ClearBit( cb.piecen, move.To ); cb.CleHachage ^= CleTourN[move.To]; if ( move.To == H8 ) { cb.Roque |= ROQUEROINOIR; } else if ( move.To == A8 ) { cb.Roque |= ROQUEDAMENOIR; } } else { // Blanc perd une tour. cb.TotalTourBlanche--; cb.NbWhitePieces--; cb.TotalMaterielBlanc--; cb.ScoreMaterielBlanc -= VALTOUR; ClearBit( cb.tourb, move.To ); ClearBit( cb.pieceb, move.To ); cb.CleHachage ^= CleTourB[move.To]; if ( move.To == H1 ) { cb.Roque |= ROQUEROIBLANC; } else if ( move.To == A1 ) { cb.Roque |= ROQUEDAMEBLANC; } } break; // Une dame. case dame : if ( wtm ) { // Noir perd une dame. cb.TotalDameNoire--; cb.NbBlackPieces--; cb.TotalMaterielNoir--; cb.ScoreMaterielNoir -= VALDAME; ClearBit( cb.damen, move.To ); cb.CleHachage ^= CleDameN[move.To]; } else { // Blanc perd une dame. cb.TotalDameBlanche--; cb.NbWhitePieces--; cb.TotalMaterielBlanc--; cb.ScoreMaterielBlanc -= VALDAME; ClearBit( cb.dameb, move.To ); cb.CleHachage ^= CleDameB[move.To]; } break; } } // Verifier si genere une possibilite de en passant. if ( move.Piece == pion ) { if ( wtm ) { if ( move.From - move.To == 16 ) cb.EnPassantB[ply+1] = move.To + 8; } else { if ( move.To - move.From == 16 ) cb.EnPassantN[ply+1] = move.To - 8; } } cb.vide = ~cb.piece; cb.NoCoups++; }
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; }
void MainLoop() { //QueryPerformanceFrequency(&nFreq); //QueryPerformanceCounter(&nBefore); DWORD StartTime,EndTime,PassTime; double l_StartTime,l_EndTime,l_PassTime; #ifdef _WIN32 StartTime=timeGetTime(); #else l_StartTime=gettimeofday_sec(); #endif ARUint8 *image; ARMarkerInfo *marker_info; int marker_num; int j,k; if( (image = (ARUint8*)arVideoGetImage() )==NULL){ arUtilSleep(2); return; } argDrawMode2D(); argDispImage(image, 0, 0); if(arDetectMarker(image, thresh, &marker_info, &marker_num) < 0){ CleanUp(); exit(0); } arVideoCapNext(); k=-1; for(j=0;j<marker_num;j++){ if(patt_id==marker_info[j].id){ k = (k==-1) ? j : k; k = (marker_info[k].cf < marker_info[j].cf) ? j: k; } } if(k!=-1) { if(isFirst==true) nyar_NyARTransMat_O2_transMat(nyobj,&marker_info[k],patt_center,patt_width,patt_trans); else nyar_NyARTransMat_O2_transMatCont(nyobj,&marker_info[k],patt_trans,patt_center,patt_width,patt_trans); isFirst=false; if(GameOver==false){ if(arUtilTimer()>1.0){ MovePiece(3,f,p); score+=f.ShiftPiece(f.deletePiece()); arUtilTimerReset(); GameOver=GameOverCheck(f,p); } } else{ if(arUtilTimer()>15.0) InitGame(); } DrawObject(); } argSwapBuffers(); #ifdef _WIN32 EndTime=timeGetTime(); PassTime=EndTime-StartTime; (1000/FPS>PassTime)?Wait(1000/FPS-PassTime):Wait(0); FPSCount(&fps); printf("FPS=%d\n",fps); #else l_EndTime=gettimeofday_sec(); l_PassTime=l_EndTime-l_StartTime; ((double)(1000/FPS)>l_PassTime)?Wait((double)1000/FPS-l_PassTime):Wait(0); FPSCount(&fps); printf("FPS=%d\n",fps); #endif }
void main(int argc, char *argv[]){ char keypress = START; int ch=0; int moves=0; char mc[10]; set_graphics(VGA_320X200X256); PrintArrow(80, 105); do{ //Game loop PrintBorder(); PrintMenu(); keypress = (char)getch(); if(keypress == QUIT){ keypress = START; //special condition so that it will not exit on Q press at menu }else if(keypress == UP || keypress == UP2){ Erase(80, 120, 15, 15); PrintArrow(80, 105); ch = 0; }else if(keypress == DOWN || keypress == DOWN2){ Erase(80, 100, 15, 15); PrintArrow(80, 125); ch = 1; }else if(keypress == ENTER || keypress == SPACE){ switch(ch){ case 0: EraseAll(); NewGame(board); do{ //Inside-the-game loop PrintInstructions(180, 30); PrintBoard(30, 30); //* Always prints update version of board at coordinates PrintBorder(); //* Always prints border sprintf(mc, "%d", moves); Erase(55, 175, 150, 15); write_text("Moves: ", 55, 175, WHITE, 0); write_text(mc, 120, 175, WHITE, 0); ShowHint(); keypress=(char)getch(); if(keypress == UP || keypress == UP2){ //Erase(15, 15, 150, 150); MovePiece(keypress); moves++; }else if(keypress == LEFT || keypress == LEFT2){ //Erase(15, 15, 150, 150); MovePiece(keypress); moves++; }else if(keypress == RIGHT || keypress == RIGHT2){ //Erase(15, 15, 150, 150); MovePiece(keypress); moves++; }else if(keypress == DOWN || keypress == DOWN2){ //Erase(15, 15, 150, 150); MovePiece(keypress); moves++; }else if(keypress == QUIT){ Erase(55, 175, 150, 15); write_text("Really exit? Y/N", 55, 175, WHITE, 0); do{ keypress=(char)getch(); if(keypress == YES){ moves = 0; keypress = QUIT; break; }else if(keypress == NO){ keypress = YES; Erase(55, 175, 150, 15); break; } }while(1); }else{ Erase(55, 175, 150, 15); write_text("Invalid button!", 55, 175, WHITE, 0); } if(CheckWin(board)){ EraseAll(); write_text("You win!", 125, 85, WHITE, 0); moves = 0; keypress = QUIT; } }while(keypress != QUIT); EraseAll(); PrintArrow(80, 105); keypress = START; break; case 1: keypress = QUIT; break; default: break; } } }while(keypress != QUIT); set_graphics(VGA_TEXT80X25X16); clrscr(); }