Browse Source

docs(mobs): correct grammar

DEV-3198-new-go-exercise-get-digit-len
davhojt 2 years ago committed by Dav Hojt
parent
commit
c94fb5f351
  1. 86
      subjects/mobs/README.md

86
subjects/mobs/README.md

@ -2,54 +2,52 @@
### Instructions ### Instructions
Create a module `mobs`, in which has to be present: Create a module named `mobs`, containing a structure `Mob` which has:
- a `Mob` structure which consists of: - `name`: `String`
- a String `name` - `boss`: `Boss`
- a Boss struct `boss` - `members`: a vector of `Member`
- a vector of Members `members` - `cities`: a vector of tuples containing a city name and a `u8`
- a vector of tuples `cities` containing the city name String and a value u8 - `wealth`: `u32`
- a u32 `wealth` - `recruit`: an associated function which adds a `Member` to the `members` vector. It should accept a `name`, and an `age`. The member's role should be set to `Associate`.
- `attack`: an associated function which receives another `Mob`. It will remove the last member from the vector of `Member` from whichever mob has the least power combat score. In the case of a draw, the attacker loses. In the case that one of the mobs is left with zero members, the victorious mob will **also** take the cities and wealth from the losing mob. The power combat score is calculated from the sum of the `role` of each mob `member`:
The Mob struct should implement the following functions: - `Underboss`: 4
- `Caporegime`: 3
- `recruit`, which adds a member to the members vector of the Mob when receiving a `member_name` (&str) and a `member_age` (u8) (the role should be Associate) - `Soldier`: 2
- `attack`, which receives another Mob and will remove the last member from the vector of Members from the Mob with the less power combat (in case of draw, the loser is the attacker). The power combat is calculated by its members: - `Associate`: 1
- an Underboss power combat is 4 - `steal`: an associated function which receives a `Mob` to target, and a `u32` value to steal. The 'self' mob steals the value from the wealth of the target mob, and adds the value to its own wealth. Only as much money as the target mob has can be stolen.
- a Caporegime power combat is 3 - `conquer_city`: an associated function which receives a vector of `Mob`, a city name and a `u8` value. The city name and `u8` value are added to its list of cities if non of the other mobs in the vector have a city with the same name.
- a Soldier power combat is 2
- an Associate power combat is 1 You will also need to create two submodules of mob:
- In case of one of the mobs stays without members, the winner mob adds to its cities every city of the loser mob and the same happens to the wealth, and the loser mob loses all cities and all wealth
- `steal`, which receives a targeted mob (Mob) and a value (u32) and subtracts the value from the target mob. The value is then added to itself. It can't be stolen more than the target mob currently has. - `boss`: which should contain:
- `conquer_city`, which receives a vector of mobs, a city name (String) and a value (u8) and adds it to the vector of cities of the own mob, only if no mob in the vector owns a city with this name - `Boss`: a struct which consists of:
- `name`: `String`
Create also two submodules of mob: - `age`: `u8`
- `new`: an associated function which accepts a `name` and `age`, and returns a `Boss`.
- `boss` submodule which should contain:
- a `Boss` struct which consists of:
- a String `name`
- an u8 `age`
- a function `new` which returns a Boss on receiving a name (&str) and an age (u8)
- `member` submodule which consists of: - `member` submodule which consists of:
- a enum `Role` with the variants: - `Role`: an enum with the variants:
- Underboss - `Underboss`
- Caporegime - `Caporegime`
- Soldier - `Soldier`
- Associate - `Associate`
- a `Member` struct which consists of: - `Member`: a struct which consists of:
- a String name - `name`: `String`
- a enum Role `role` - `role`: `Role`
- a u8 `age` - `age`: `u8`
- the Member struct should implement a function `get_promotion` which will change the member role. If a member is an Associate, it will get promoted to Soldier; a Soldier is promoted to a Caporegime and a Caporegime is promoted to Underboss `get_promotion`: an associated function which when invoked should promote the member from:
- a function `new` which return a Member on receiving a name(&str), a role (Role) and an age (u8) - `Associate` -> `Soldier`
- `Soldier` -> `Caporegime`
The submodules should be created inside a folder called `mobs`. We advise you to create two files one to each submodule, but it is up to you. - `Caporegime` -> `Underboss`
- `new`: accepts a `name`, `role` and `age`, returning a `Member`.
You must include `#[derive(Debug, CLone, PartialEq)]` on top of every struct and the enum.
The submodules should be created inside a folder named `mobs`. We advise you to create two files for each submodule, but that is up to you.
You must include `#[derive(Debug, CLone, PartialEq)]` above every struct and enum.
### Expected Function ### Expected Function
> You'll need to work out the function signatures for yourself.
#### For this exercise the signature of the function has to be found out.
### Usage ### Usage

Loading…
Cancel
Save