程序代写代做代考 game Erlang CS 511 – Quiz 6: Message Passing in Erlang

CS 511 – Quiz 6: Message Passing in Erlang
Names: Pledge:
11 November 2020
Exercise 1
You are asked to implement a guessing game. A server receives requests to play the game from clients. These requests are of the form {From,start}, where From is the Pid of the client, and start is an atom. The server should then:
1. generate a pseudorandom number in the range [0,10];
2. spawn a “servlet” process that plays the game with the client, providing the generated number to be guessed;
3. notify the client of the PID of the “servlet”; and
4. then receive new client requests.
Note that by spawning a servlet the server is always responsive to new game requests. The servlet should behave as follows:
• wait for guesses from the client of the form {Pid,Ref,Number}, where Pid is its Pid, Ref is a reference number and Number is the number the client is guessing.
• answereachmessage,indicatingwhethertheclienthasguessed(gotIt)ornot(tryAgain).
The client should keep guessing random numbers. Once it has guessed correctly, both client and servlet simply ends their execution.
You can use the function rand:uniform(N) for generating random numbers between 1 and N. Also, you may include helper functions.
-module(gg). -compile(export_all).
start () ->
S = spawn(fun server/0), spawn(?MODULE ,client ,[S]).
server () -> exit(incomplete).
client(S) -> exit(incomplete).
1