CSCI 3171 Network Computing - Assignment 3


  • 作业标题:CSCI 3171 - Assignment 3
  • 课程名称:Dalhouse University CSCI 3171 Network Computing
  • 完成周期:2天

1. ASSIGNMENT TASK

Design a client-server application using TCP sockets, where you use the client to play a game of
“Prisoner’s Dilemma” with the server.
You may complete this assignment individually or in groups of 2 students. Only one
submission per group is required. You may use C/C++ or Java for this assignment; however, your
code must compile using gcc/g++ or javac on the command line.

2. ASSIGNMENT DETAILS:

The Prisoner’s Dilemma:
“The prisoner’s dilemma is a standard example of a game analyzed in game theory that shows
why two completely ‘rational’ individuals might not cooperate, even if it appears that it is in their
best interests to do so”

It is presented as follows:

“Two members of a criminal gang are arrested and imprisoned. Each prisoner is in
solitary confinement with no means of communicating with the other. The
prosecutors lack sufficient evidence to convict the pair on the principal charge. They
hope to get both sentenced to a year in prison on a lesser charge. Simultaneously,
the prosecutors offer each prisoner a bargain. Each prisoner is given the opportunity
either to: betray the other by testifying that the other committed the crime, or to
cooperate with the other by remaining silent. The offer is:

  • If A and B each betray the other, each of them serves 2 years in prison
  • If A betrays B but B remains silent, A will be set free and B will serve 3 years in prison (and vice versa)
  • If A and B both remain silent, both will only serve 1 year in prison (on the lesser charge)”1

This is summarized in the figure on the right. The following YouTube video also explains Prisoner’s Dilemma (you only need to watch up to 1:50 minutes of this video):
https://www.youtube.com/watch?v=t9Lo2fgxWHw

Your Task:
you will write simple client-server application(s) in which the
client acts as prisoner A and the server acts as prisoner B. The
protocol between the client and server should be as follows:

  • The server program is started on a user-defined port.
  • The client program is started and connects to the server using the server IP and port
    number provided on the command line.
  • The client asks the user for input. The input may either be Silent or Betray. Any other input
    should result in an error message, asking the user to try again.
  • The user’s input is sent to the server via the connected socket.
  • The server (acting as prisoner B) may decide to remain Silent or Betray. How the server
    decides is completely up to you. For fairness, you may use a random approach.
  • The server reads the user’s input from the client socket, evaluates the outcome (years in
    prison for both Prisoner A (i.e., client), and Prisoner B (i.e., server)), displays each prisoners’
    choice and resulting sentences (Freedom, 1 year in prison, 2 years in prison or 3 years
    in prison), and sends this information (i.e., Server’s choice and the resulting prison
    sentences for both prisoners) back to the client.
  • The client should display the server’s reply (i.e., Server’s choice and the resulting sentences)
    to the user.
  • The client should give the user an option to try again or quit.

。。。


文章作者: IT神助攻
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 IT神助攻 !
  目录