//每当落子后,判断胜负 bool ChessBoard::judgeVictory(Chess& lastchess) { int row = lastchess.getRow(); int column = lastchess.getColumn(); int type = lastchess.getChessType(); //垂直方向 if(fiveInDirection(row, column, type, VERTICAL)) { return VICTORY; } //水平方向 if(fiveInDirection(row, column, type, HORIZON)) { return VICTORY; } //右斜方向 if(fiveInDirection(row, column, type, RIGHT)) { return VICTORY; } //左斜方向 if(fiveInDirection(row, column, type, LEFT)) { return VICTORY; } return CONTINUE; }
//指定一个棋子 void ChessBoard::setOneChess(Chess chess) { int row = chess.getRow(); int column = chess.getColumn(); this->chessboardmat[row][column] = chess.getChessType(); steps.push_back(chess); }
//悔棋 bool ChessBoard::backStep() { if(steps.size() < 2) { return false; } for(int i = 0; i < 2; i++) { vector<Chess>::iterator it = steps.end() - 1; Chess chess = *it; int row = chess.getRow(); int column = chess.getColumn(); this->chessboardmat[row][column] = EMPTY_CHESS; steps.pop_back(); } return true; }