Commit 40f83962 authored by jabapo's avatar jabapo
Browse files

1. Captures now work (Bishop, Knight) but still needs further testing

2. Now checks if corners are rooks for castling
3. Possible moves started, does not work
parent 6c9f4d8a
......@@ -50,15 +50,25 @@ class Game{
chessboard.checkTileColor(movecol,moverow) != side){
if(MoveValidation(movingpiece,startcol,startrow,movecol,moverow)) {
//convert into chess notation here
std::string moving = chessboard.ConvertPiece(movingpiece) + "x" + move;
Piece remove = chessboard.getPiece(movecol,moverow);
chessboard.removePiece(movingpiece,startcol,startrow);
chessboard.removePiece(remove,movecol,moverow);
chessboard.setPiece(movingpiece,movecol,moverow);
chessboard.removePiece(movingpiece,startcol,startrow);
if(side == Color::White){
std::cout << moving << '\n';
}
}
}
//if spot is not occupied move validation
else if(MoveValidation(movingpiece,startrow,startcol,moverow,movecol)){
chessboard.removePiece(movingpiece,startcol,startrow);
chessboard.setPiece(movingpiece,movecol,moverow);
chessboard.removePiece(movingpiece,startcol,startrow);
}
//two cases, if occupied by OPPOSITE COLOR, can take, same color
}
......@@ -73,7 +83,7 @@ class Game{
// if (startr < 0 || startc < 0 || endr < 0 || endc < 0 ||
// startr > 7 || startc > 7 || endr > 7 || endc > 7) return false;
//invalid move if the piece at the end is the same color
if (chessboard.checkTileColor(endc,endr) == p.c) return false;
// if (chessboard.checkTileColor(endc,endr) == p.c) return false;
if (p.t == Type::Rook){
// check if same row/column. Travels in a straight line.
// Column or row has to be empty for it to move.
......@@ -91,7 +101,7 @@ class Game{
else if(p.t == Type::Bishop){
//check column. Column or row has to be empty for it to move.
if (abs(startr - endr) != abs(startc - endc)) return false;
!chessboard.checkDiagonalO(startr,startc,endr,endc); //TODO: Bishop capture is not correct. Will eval false when attempting to capture
return !chessboard.checkDiagonalO(startr,startc,endr,endc) && (p.c != chessboard.getPiece(endc,endr).c); //TODO: Bishop capture is not correct. Will eval false when attempting to capture
}
else if(p.t == Type::Pawn){
// check direction of movement
......@@ -190,14 +200,18 @@ class Game{
if(dir == 'q' && !chessboard.checkRowO(row,1,3)){
//now need to check if any of these squares are being attacked
//checks if the rook is in the correct spot
Piece r = chessboard.getPiece(row,0);
if(kingchecks[row][2].second || kingchecks[row][1].second){return false;}
if(chessboard.getPiece(row,0).t != Type::Rook) return false;
if(r.t != Type::Rook || r.c != side) return false;
}
else if(dir == 'k' && !chessboard.checkRowO(row,5,6)){
Piece r = chessboard.getPiece(row,0);
if(kingchecks[row][5].second || kingchecks[row][6].second){return false;}
if(chessboard.getPiece(row,7).t != Type::Rook){return false;}
if(r.t != Type::Rook || r.c != side) return false;
}
return false;
}
//R: checks living pieces, and observes whether or not the OPPOSITE king is now in check.
//M: black check or white check
......@@ -215,8 +229,35 @@ class Game{
if(side == Color::White){return kingchecks[row][col].second;}
else{return kingchecks[row][col].first;}
}
//rooks, bishops, queens
void PossibleMoves(Piece p){
//
int startdir = p.t == Type::Bishop ? 4 : 8;
int distancetoedge = p.col;
if(p.t == Type::Bishop){
for(int i = 0; i < distancetoedge;i++){
if(MoveValidation(p,p.row,p.col,p.row + i,p.row + i))
}
}
else if(p.t == Type::Rook){
}
else if(p.t == Type::Queen){
}
else if(p.t == Type::Knight){
}
else if(p.t == Type::Pawn){
int attackingrow = (p.c == Color::Black) ? -1 : 1;
for(int i = 0; i < 3;i++){
if(MoveValidation(p,p.row,p.col,p.row + attackingrow,p.col - 1 + i)){
if(p.c == Color::Black) kingchecks[p.col - 1 + i][p.row + attackingrow].second = true;
else kingchecks[p.col - 1 + i][p.row + attackingrow].first = true;
}
}
}
}
Color WhoMoves(){
return (blackmoves < whitemoves) ? Color::Black : Color::White;
......@@ -229,8 +270,8 @@ class Game{
// marks the tile that can be captured en passant; updated in MovePiece() with:
// new coord of Pawn if Pawn moves two spaces forward, (-1,-1) for all other moves
Coord enpassant = { -1, -1 };
Coord whiteking = { 4, 0};
Coord blackking = { 4, 7};
Coord whiteking = { 4, 0 };
Coord blackking = { 4, 7 };
// this checks if the king is under attack
bool blackcheck = false;
bool whitecheck = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment