Added how to use instructins
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Andre Henriques 2024-01-20 17:50:23 +00:00
parent 0f9f885cc0
commit 8b35a1fc85

103
README.md
View File

@ -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@<computer_name>")
```
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!