Skip to content

Commit

Permalink
[#9]: add player
Browse files Browse the repository at this point in the history
  • Loading branch information
3k-dome committed May 8, 2023
1 parent c39cef8 commit 7cce4eb
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions catan-lib/Parts/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using CatanLib.Enums;
using CatanLib.Interfaces.Components;

namespace CatanLib.Parts
{
public class Player : IPlayer
{
public PlayerNumber Number { get; set; }

public Dictionary<ResourceType, int> Resources { get; } = new()
{
{ ResourceType.Sheep, 0 },
{ ResourceType.Wheat, 0 },
{ ResourceType.Ore, 0 },
{ ResourceType.Brick, 0 },
{ ResourceType.Wood, 0 }
};

public Dictionary<PieceType, int> Pieces { get; } = new()
{
{ PieceType.Road, 15 },
{ PieceType.Settlement, 5 },
{ PieceType.City, 4 }
};

public IEnumerable<float> ToVector(ICatan catan)
{
float[] pieceEncoding = new float[]
{
Pieces[PieceType.Road] / 15f,
Pieces[PieceType.Settlement] / 5f,
Pieces[PieceType.City] / 4f
};

IEnumerable<float> resourceEncoding = Number == catan.CurrentPlayer.Number
? Enum.GetValues<ResourceType>().Select(resource => Resources[resource] / 19f)
: new float[] { Enum.GetValues<ResourceType>().Select(resource => Resources[resource]).Sum() / 95f };

return resourceEncoding.Concat(pieceEncoding);
}
}
}

0 comments on commit 7cce4eb

Please sign in to comment.