Initialized everything and completed Bucket.cs, Fire.cs, Well.cs.

This commit is contained in:
MarcUs7i 2024-12-12 17:04:24 +01:00
parent 176b3b7cbb
commit 6d01e25314
5 changed files with 55 additions and 31 deletions

View file

@ -5,7 +5,8 @@
/// </summary> /// </summary>
public sealed class Bucket public sealed class Bucket
{ {
// TODO private readonly double _capacityLiters;
private double _contentLiters;
/// <summary> /// <summary>
/// Creates a new bucket with the given capacity. /// Creates a new bucket with the given capacity.
@ -13,13 +14,14 @@ public sealed class Bucket
/// <param name="capacityLiters">Bucket capacity in liters</param> /// <param name="capacityLiters">Bucket capacity in liters</param>
public Bucket(double capacityLiters) public Bucket(double capacityLiters)
{ {
// TODO _capacityLiters = capacityLiters;
_contentLiters = 0D;
} }
/// <summary> /// <summary>
/// Gets if this bucket is currently completely empty or not. /// Gets if this bucket is currently completely empty or not.
/// </summary> /// </summary>
public bool IsEmpty => false; // TODO public bool IsEmpty => _contentLiters <= 0D;
/// <summary> /// <summary>
/// Fills the bucket to the brim if enough water is available. /// Fills the bucket to the brim if enough water is available.
@ -30,8 +32,17 @@ public sealed class Bucket
/// <returns>The amount taken for filling the bucket</returns> /// <returns>The amount taken for filling the bucket</returns>
public double Fill(double maxAvailable) public double Fill(double maxAvailable)
{ {
// TODO if (_capacityLiters - _contentLiters <= 0D)
return -1D; {
return 0D;
}
maxAvailable = Math.Abs(_capacityLiters - maxAvailable);
_contentLiters = _contentLiters + maxAvailable > _capacityLiters
? _capacityLiters
: _contentLiters + maxAvailable;
return maxAvailable;
} }
/// <summary> /// <summary>
@ -40,7 +51,8 @@ public sealed class Bucket
/// <returns>Amount emptied from the bucket, in liters</returns> /// <returns>Amount emptied from the bucket, in liters</returns>
public double Empty() public double Empty()
{ {
// TODO var content = _contentLiters;
return -1D; _contentLiters = 0D;
return content;
} }
} }

View file

@ -5,7 +5,12 @@
/// </summary> /// </summary>
public sealed class Chain public sealed class Chain
{ {
// TODO private readonly Fire _fire;
private readonly int _requiredPeople;
private readonly Well _well;
private readonly double _bucketSize;
private Person _firstPerson;
private int _availableBuckets;
/// <summary> /// <summary>
/// Creates a new bucket chain based on the supplied parameters. /// Creates a new bucket chain based on the supplied parameters.
@ -19,7 +24,12 @@ public sealed class Chain
public Chain(int requiredPeople, int availableBuckets, double bucketSize, public Chain(int requiredPeople, int availableBuckets, double bucketSize,
Well well, Fire fire, Person firstPerson) Well well, Fire fire, Person firstPerson)
{ {
// TODO _requiredPeople = requiredPeople;
_availableBuckets = availableBuckets;
_bucketSize = bucketSize;
_well = well;
_fire = fire;
_firstPerson = firstPerson;
} }
/// <summary> /// <summary>

View file

@ -5,7 +5,7 @@
/// </summary> /// </summary>
public sealed class Fire public sealed class Fire
{ {
// TODO private readonly double _growRate;
/// <summary> /// <summary>
/// Creates a new fire with the passed properties. /// Creates a new fire with the passed properties.
@ -14,19 +14,19 @@ public sealed class Fire
/// <param name="growRate">Rate by which the fire grows with each (chain operation) step</param> /// <param name="growRate">Rate by which the fire grows with each (chain operation) step</param>
public Fire(double initialFireSize, double growRate) public Fire(double initialFireSize, double growRate)
{ {
// TODO _growRate = growRate;
FireSize = initialFireSize;
} }
/// <summary> /// <summary>
/// Gets the current size of the fire; cannot be smaller than 0. /// Gets the current size of the fire; cannot be smaller than 0.
/// </summary> /// </summary>
// TODO public double FireSize { get; private set; }
// public double FireSize ...
/// <summary> /// <summary>
/// Gets if the fire has been extinguished (= size is 0). /// Gets if the fire has been extinguished (= size is 0).
/// </summary> /// </summary>
public bool Extinguished => false; // TODO public bool Extinguished => FireSize <= 0D;
/// <summary> /// <summary>
/// The fire is hit by a load of water from a bucket. /// The fire is hit by a load of water from a bucket.
@ -35,7 +35,7 @@ public sealed class Fire
/// <param name="amount">Liters of water</param> /// <param name="amount">Liters of water</param>
public void GetHitByWater(double amount) public void GetHitByWater(double amount)
{ {
// TODO FireSize = FireSize - amount < 0D ? 0D : FireSize - amount;
} }
/// <summary> /// <summary>
@ -44,7 +44,7 @@ public sealed class Fire
/// </summary> /// </summary>
public void BurnHigher() public void BurnHigher()
{ {
// TODO FireSize += _growRate;
} }
/// <summary> /// <summary>
@ -52,5 +52,5 @@ public sealed class Fire
/// The size is rounded to whole numbers. /// The size is rounded to whole numbers.
/// </summary> /// </summary>
/// <returns>String representation of the fire</returns> /// <returns>String representation of the fire</returns>
public override string ToString() => string.Empty; // TODO public override string ToString() => $"🔥 {Math.Round(FireSize)}";
} }

View file

@ -5,7 +5,8 @@
/// </summary> /// </summary>
public sealed class Person public sealed class Person
{ {
// TODO private Bucket? _backwardBucket;
private Bucket? _forwardBucket;
/// <summary> /// <summary>
/// Creates a new person. /// Creates a new person.
@ -25,21 +26,18 @@ public sealed class Person
/// <summary> /// <summary>
/// Gets the left neighbor of the person. Can be null. /// Gets the left neighbor of the person. Can be null.
/// </summary> /// </summary>
// TODO public Person? LeftNeighbor { get; private set; }
// public Person? LeftNeighbor ...
/// <summary> /// <summary>
/// Gets the right neighbor of the person. Can be null. /// Gets the right neighbor of the person. Can be null.
/// </summary> /// </summary>
// TODO public Person? RightNeighbor { get; private set; }
// public Person? RightNeighbor ...
/// <summary> /// <summary>
/// Gets the number of the last step in which this person performed a bucket move action. /// Gets the number of the last step in which this person performed a bucket move action.
/// Each person can only move, at most, once per step. /// Each person can only move, at most, once per step.
/// </summary> /// </summary>
// TODO public int LastStepPerformed { get; private set; }
// public int LastStepPerformed ...
/// <summary> /// <summary>
/// The person joins an existing bucket chain at a specific position. /// The person joins an existing bucket chain at a specific position.

View file

@ -5,7 +5,8 @@
/// </summary> /// </summary>
public sealed class Well public sealed class Well
{ {
// TODO private readonly double _maxCapacity;
private readonly double _refillRate;
/// <summary> /// <summary>
/// Creates a new well with the supplied properties. /// Creates a new well with the supplied properties.
@ -16,22 +17,24 @@ public sealed class Well
/// operation step</param> /// operation step</param>
public Well(double maxCapacity, double refillRate) public Well(double maxCapacity, double refillRate)
{ {
// TODO _maxCapacity = maxCapacity;
_refillRate = refillRate;
} }
/// <summary> /// <summary>
/// Gets how many liters currently remain in the well. /// Gets how many liters currently remain in the well.
/// Cannot exceed the max. capacity of the well or drop below 0. /// Cannot exceed the max. capacity of the well or drop below 0.
/// </summary> /// </summary>
// TODO public double LitersRemaining { get; private set; }
// public double LitersRemaining ...
/// <summary> /// <summary>
/// Refills the well by the constant rate. /// Refills the well by the constant rate.
/// </summary> /// </summary>
public void Refill() public void Refill()
{ {
// TODO LitersRemaining = LitersRemaining + _refillRate > _maxCapacity
? _maxCapacity
: LitersRemaining + _refillRate;
} }
/// <summary> /// <summary>
@ -42,7 +45,8 @@ public sealed class Well
/// <param name="bucket">The bucket to fill</param> /// <param name="bucket">The bucket to fill</param>
public void FillBucket(Bucket bucket) public void FillBucket(Bucket bucket)
{ {
// TODO var litersTaken = bucket.Fill(LitersRemaining);
LitersRemaining -= litersTaken;
} }
/// <summary> /// <summary>
@ -50,5 +54,5 @@ public sealed class Well
/// Shows the current and max. amount of liters - rounded to whole numbers. /// Shows the current and max. amount of liters - rounded to whole numbers.
/// </summary> /// </summary>
/// <returns>String representation of the well</returns> /// <returns>String representation of the well</returns>
public override string ToString() => string.Empty; // TODO public override string ToString() => $"💧 {LitersRemaining}/{_maxCapacity}";
} }