Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a 'Corpse' class that represents a deceased agent.
- Loading branch information
1 parent
753f615
commit 6eef9ce
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Cas.Core.Extensions; | ||
using Cas.Core.Interfaces; | ||
|
||
namespace Cas.Core | ||
{ | ||
/// <summary> | ||
/// When an agent dies, a corpse object is created which contains the resources that | ||
/// were encoded in its genetic code. | ||
/// </summary> | ||
public class Corpse : IResourceNode | ||
{ | ||
internal List<Resource> Reservoir { get; private set; } | ||
|
||
public long Id { get; private set; } | ||
|
||
public Tag Offense { get; set; } | ||
|
||
public Tag Defense { get; set; } | ||
|
||
public Tag Exchange { get; set; } | ||
|
||
|
||
public Corpse(IAgent deceased) | ||
{ | ||
if (deceased == null) throw new ArgumentNullException("deceased"); | ||
|
||
this.Id = deceased.Species.Id; | ||
this.Offense = Tag.New(deceased.Offense); | ||
this.Defense = Tag.New(deceased.Defense); | ||
this.Exchange = Tag.New(deceased.Exchange); | ||
|
||
// Build the reservoir from the genetic code of the deceased. | ||
this.Reservoir = deceased.GeneticMaterial; | ||
} | ||
|
||
public int CurrentResourceCount | ||
{ | ||
get | ||
{ | ||
return this.Reservoir.Count; | ||
} | ||
} | ||
|
||
public List<Resource> RemoveResources(int count) | ||
{ | ||
if (count < 0) throw new ArgumentOutOfRangeException("count"); | ||
|
||
var resources = new List<Resource>(); | ||
for (int i = 0; i < count; i++) | ||
{ | ||
if (this.Reservoir.Count == 0) break; | ||
resources.Add(this.Reservoir.RemoveRandom()); | ||
} | ||
return resources; | ||
} | ||
|
||
public void AddResources(List<Resource> resources) | ||
{ | ||
throw new NotSupportedException("Resources cannot be added to a corpse."); | ||
} | ||
|
||
public string ShowResourcePool(string delimiter) | ||
{ | ||
return string.Join(delimiter, this.Reservoir.Select(x => x.Label.ToString())); | ||
} | ||
|
||
public IResourceNode Source | ||
{ | ||
get | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public List<Resource> RenewableResources | ||
{ | ||
get | ||
{ | ||
return new List<Resource>(); | ||
} | ||
} | ||
|
||
public void RefreshReservoir() | ||
{ | ||
throw new NotSupportedException("Cannot refresh a corpse"); | ||
} | ||
|
||
public string ToShortString() | ||
{ | ||
return string.Format("C.{0}: {1} {2}", this.Id, this.Offense, this.Defense); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return string.Format("C.{0}: {1} {2}, {3} resources", this.Id, this.Offense, this.Defense, this.Reservoir.Count); | ||
} | ||
|
||
public IResourceNode DeepCopy() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters