
作业社区
探索学习新天地,共享知识资源!
ctwong 的学生作业:
Judge.hpp #ifndef _JUDGE_HEAD_H #define _JUDGE_HEAD_H #include "Player.hpp" #include "ChessBoard.hpp" class Judge { public: bool isWin(Player *player) { bool ok = false; string chessColour = player->getColour(); ok = isHorizontalWin(chessColour); if (ok) { return true; } ok = isVerticalWin(chessColour); if (ok) { return true; } ok = isUphillWin(chessColour); if (ok) { return true; } ok = isDownhillWin(chessColour); if (ok) { return true; } return ok; } bool isHorizontalWin(const string &chessColour) { int count = 0; ChessBoard *chessBoard = ChessBoard::getChessBoard(); int curLine = chessBoard->getCurrentLine(); int curColumn = chessBoard->getCurrentColumn(); // right for (int i = 0; i < 5; i ++) { if (chessBoard->isSameColourChess(chessColour, curLine, curColumn + i)) { count ++; } else { break; } } if (count >= 5) { return true; } // left for (int i = 0; i < 5; i ++) { if (chessBoard->isSameColourChess(chessColour, curLine, curColumn - i)) { count ++; } else { break; } } return count - 1 >= 5 ? true : false; } bool isVerticalWin(const string &chessColour) { int count = 0; ChessBoard *chessBoard = ChessBoard::getChessBoard(); int curLine = chessBoard->getCurrentLine(); int curColumn = chessBoard->getCurrentColumn(); // Up for (int i = 0; i < 5; i ++) { if (chessBoard->isSameColourChess(chessColour, curLine - i, curColumn)) { count ++; } else { break; } } if (count >= 5) { return true; } // Down for (int i = 0; i < 5; i ++) { if (chessBoard->isSameColourChess(chessColour, curLine + i, curColumn)) { count ++; } else { break; } } return count - 1 >= 5 ? true : false; } bool isUphillWin(const string &chessColour) { int count = 0; ChessBoard *chessBoard = ChessBoard::getChessBoard(); int curLine = chessBoard->getCurrentLine(); int curColumn = chessBoard->getCurrentColumn(); // uphill->up for (int i = 0; i < 5; i ++) { if (chessBoard->isSameColourChess(chessColour, curLine - i, curColumn + i)) { count ++; } else { break; } } if (count >= 5) { return true; } // uphill->Down for (int i = 0; i < 5; i ++) { if (chessBoard->isSameColourChess(chessColour, curLine + i, curColumn - i)) { count ++; } else { break; } } return count - 1 >= 5 ? true : false; } bool isDownhillWin(const string &chessColour) { int count = 0; ChessBoard *chessBoard = ChessBoard::getChessBoard(); int curLine = chessBoard->getCurrentLine(); int curColumn = chessBoard->getCurrentColumn(); // downhill->Up for (int i = 0; i < 5; i ++) { if (chessBoard->isSameColourChess(chessColour, curLine - i, curColumn - i)) { count ++; } else { break; } } if (count >= 5) { return true; } // downhill->Down for (int i = 0; i < 5; i ++) { if (chessBoard->isSameColourChess(chessColour, curLine + i, curColumn + i)) { count ++; } else { break; } } return count - 1 >= 5 ? true : false; } }; #endif main.cpp #include "BlackPlayer.hpp" #include "WhitePlayer.hpp" #include "KeyHandle.hpp" #include "Judge.hpp" int main(int argc, const char *argv[]) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); chessBoard->show(); BlackPlayer blackPlayer("tiechui"); WhitePlayer whitePlayer("cuihua"); Player *players[] = {&blackPlayer, &whitePlayer}; #if 0 blackPlayer.placeChess(5, 1); whitePlayer.placeChess(5, 3); #endif KeyHandle keyHandle; Judge judge; bool win = false; while (!win) { for (Player *player:players) { keyHandle.waitPlayerPlaceChess(player); bool ok = judge.isWin(player); if (ok) { win = true; break; } } } return 0; } 【图片】





weixin_慕哥3021856 的学生作业:
seq和ack都是序列号。 seq: 数据序号。客户端发送报文段的第一个字节的编号。它是作为TCP连接中传送的字节流的第一个字节的顺序编号,用于记录传输的报文段。 ack: 确认序号,用于TCP对上一次seq序号的确认。接收方的ack值会在接受的报文序列号基础上加一。 ACK,SYN,FIN都是标志位字段 ACK: 在TCP连接建立时的确认字段。TCP连接建立后ACK为1,ACK为1表示前面的确认字段有效。 SYN: 在TCP连接建立的三次握手阶段,用于同步序号。当SYN=1且ACK=0时,用于描述一个请求建立连接的报文;当SYN=1且ACK=1时,用于描述一个对方同意连接的报文。 FIN: 一个描述数据发送完成的标记。FIN=1表示数据已经发送完毕,即将释放连接,在断开连接的四次挥手阶段会出现。




