From 8b35a1fc851ac8d0ffb4100138a465e8ccd21f56 Mon Sep 17 00:00:00 2001 From: Andre Henriques Date: Sat, 20 Jan 2024 17:50:23 +0000 Subject: [PATCH] Added how to use instructins --- README.md | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a11769..d873632 100644 --- a/README.md +++ b/README.md @@ -127,4 +127,105 @@ The server will answer with one of the following: # Usage instructions -!!! TODO !!! +There is two ways of interacting with the server via the API or the `Client` Module + +## API + +Start a new iex session and compilie `paxos.ex` and `server.ex`: + +```elixir +c "paxos.ex"; c "server.ex" +``` + +** Paxos needs to be compiled before the server as the server requires macros written in the paxos file ** + +Now start 3 instances of the server: + +```elixir +procs = Enum.to_list(1..3) |> Enum.map(fn x -> :"p#{x}" end) +pids = procs |> Enum.map(fn x -> Server.start(x, procs) end) +``` + +After the 3 instances have been started you can use Server helper functions to communicate with the Server: + +```elixir +Server.start_game(:p1, [:p1, :p2]) +Server.get_game_state(:p1, 1) +Server.make_move(:p1, 1, 0) +``` + +## Using the Client + +Open 2 different terminals. One terminal will be the display game and the other will be used to control the game + +In the first terminal start an iex session with a session name: +``` +iex --sname c1 +``` + +In the second terminal start an iex session with a session name: +``` +iex --sname c2 +``` + +On the first terminal connect to the second terminal: +```elixir +# In c1 +Node.connect(:"c2@") +``` + +On both terminals compile paxos and server: +```elixir +# In both run +c "paxos.ex"; c "server.ex" +``` + +On the first terminal start the servers, create a game and enter display mode: +```elixir +# In c1 +procs = Enum.to_list(1..3) |> Enum.map(fn x -> :"p#{x}" end) +pids = procs |> Enum.map(fn x -> Server.start(x, procs) end) + +Server.start_game(:p1, [:p1, :p2]) +Client.display_game(:p1, 1) +``` + +You now should see something like: + +``` + 0 H + + 1 + Be + H + + 5 2 + Be + + Be Li + + + 4 3 + + + Be +``` + +The Center "Atom" is your hand, while the Letters arround are the game_state or board, +the number represents where you can put the "Atom" in your hand + + +On the second terminal start enter control mode: +```elixir +# In c2 +Client.control_game(:p1, 1) +``` + +You should see: +``` +Type the number you want to play or q to exit: +``` + +Keep your mouse in the second terminal, and insert the number, where you want to make your move, and hit enter! + +The map should update on the top screen and now you can play the game!