为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 100
学习任务

水蛭_312 的学生作业:

#ifndef _JUDGE_H #define _JUDGE_H #include "Player.hpp" #include "ChessBoard.hpp" class Judge { public: bool isWin(Player* player) { bool ok = false; string chessColor = player->getColor(); ok = isHorizontalWin(chessColor); if (ok) { return true; } ok = isVerticalWin(chessColor); if (ok) { return true; } ok = isUphillWin(chessColor); if (ok) { return true; } ok = isDownhillWin(chessColor); if (ok) { return true; } return ok; } bool isHorizontalWin(const string& chessColor) { ChessBoard* chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); int count = 0; // 判定 // down 判定 相同的棋子 for (int i = 0;i < 5;i++) { if(chessBoard->isSameColorChess(chessColor,line + i,column)){ count++; } else { break; } } if (count >=5) { return true; } // up for (int i = 0;i < 5;i++) { if (chessBoard->isSameColorChess(chessColor, line - i, column)) { count++; } else { break; } } return count - 1 >= 5 ? true : false; } bool isVerticalWin(const string& chessColor) { ChessBoard* chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); int count = 0; // 判定 // right 判定 相同的棋子 for (int i = 0;i < 5;i++) { if (chessBoard->isSameColorChess(chessColor, line, column + i)) { count++; } else { break; } } if (count >= 5) { return true; } // left for (int i = 0;i < 5;i++) { if (chessBoard->isSameColorChess(chessColor, line, column - i)) { count++; } else { break; } } return count - 1 >= 5 ? true : false; } bool isUphillWin(const string& chessColor) { ChessBoard* chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); int count = 0; // 判定 // uphill right 判定 相同的棋子 for (int i = 0;i < 5;i++) { if (chessBoard->isSameColorChess(chessColor, line-i, column + i)) { count++; } else { break; } } if (count >= 5) { return true; } // uphill left for (int i = 0;i < 5;i++) { if (chessBoard->isSameColorChess(chessColor, line + i, column - i)) { count++; } else { break; } } return count - 1 >= 5 ? true : false; } bool isDownhillWin(const string& chessColor) { ChessBoard* chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); int count = 0; // 判定 // Downhill right 判定 相同的棋子 for (int i = 0;i < 5;i++) { if (chessBoard->isSameColorChess(chessColor, line + i, column + i)) { count++; } else { break; } } if (count >= 5) { return true; } // Downhill left for (int i = 0;i < 5;i++) { if (chessBoard->isSameColorChess(chessColor, line - i, column - i)) { count++; } else { break; } } return count - 1 >= 5 ? true : false; } }; #endif

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号