<aside> 💡
10/14 更新評分標準 Update homework ranking
</aside>
本次作業的目標是要讓同學實作能透過 TCP 以及 UDP 溝通的程式,本作業要求同學實作一個簡單的雙人連機遊戲。本作業將會分為兩個部分,第一部分是玩家發送遊戲邀請:玩家 A 要能夠透過 UDP 發送邀請給玩家 B,玩家 B 要能夠告訴玩家 B 他接收邀請,玩家 A 收到玩家 B 的回覆後要再次發送自己 Port(整個發送遊戲邀請的部分皆是透過 UDP 溝通)。第二部分是連機遊戲,玩家 B 在得知玩家 A 的 IP 與 port 後,玩家 B 要能夠透過 TCP 與玩家 A 建立連線,並透過 TCP 玩遊戲(遊戲類型不限,只要是雙人遊戲即可,例如猜拳、西洋棋⋯⋯)。
The goal of this assignment is to write programs that can communicate using both TCP and UDP, you are tasked to implement a simple two-player online game. The assignment is divided into two parts. The first part is the game invitation: Player A should send an invitation to Player B using UDP. Player B should then inform Player A that they have received and accepted the invitation. After receiving Player B's response, Player A should send their port information back (the entire invitation process must be done using UDP communication). The second part is the online game. Once Player B knows Player A's IP address and port number, Player B should connect to Player A using TCP, and they can play a game together through TCP (the type of game is not restricted, as long as it is a two-player game, e.g., rock-paper-scissors, chess, etc.).

一開始玩家 A 在發送邀請時,必須知道玩家 B 的 UDP server IP 位址以及 Port,為了簡化作業,本次作業玩家 B 規定要運行在系計中的 server 上(總共 4 台,請參考以下表格),並且 UDP server 的 Port 必須為 10000 以上。在發送邀請之前,玩家 A 必須檢查所有的 server 是否有其他玩家正在等待邀請。確認所有正在等待邀請的玩家後,選擇其中一個玩家發送邀請。
When Player A sends an invitation, they must know Player B's UDP server IP address and port. To simplify things, Player B is required to run on CSIT servers (there are a total of four servers as shown below), and the UDP server's port must be above 10000. Before sending the invitation, Player A must check all the servers to see if any players are waiting for an invitation, after searching all players who are waiting, choose one player to send the invitation.
| Server Host Name | IP |
|---|---|
| linux1.cs.nycu.edu.tw | 140.113.235.151 |
| linux2.cs.nycu.edu.tw | 140.113.235.152 |
| linux3.cs.nycu.edu.tw | 140.113.235.153 |
| linux4.cs.nycu.edu.tw | 140.113.235.154 |

當玩家 B 收到邀請時,要能夠選擇是否接受邀請,如果不接受邀請,玩家 A B 之間不會建立連線,玩家 B 恢復至等待其他玩家邀請的狀態。如果玩家 B 接受邀請,玩家 B 必須告訴玩家 A 他接受邀請,玩家 A 確認玩家 B 接受邀請後會建立一個 TCP server 並傳送該 TCP server 的 port 資訊給玩家 B。