Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Player.cs #20

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions BinaryMatrixEngine/ActionSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace BinaryMatrix.Engine;

public enum ActionType {
NONE,
DRAW,
PLAY,
FACEUP_PLAY,
COMBAT,
DISCARD
}

public interface CardSpecification {
public int? ResolveForPlayer(Player player);
}

public struct ActionSet {
public readonly ActionType type;
public readonly int lane;
public readonly CardSpecification? card;

/* "a" Pseudo-Lane */
public const int LANE_A = 6;
public static readonly ActionSet NONE = new(ActionType.NONE);

public ActionSet(ActionType type) {
if(type != ActionType.NONE)
throw new ArgumentException("Invalid overload called for this type.", nameof(type));
this.type = type;
this.lane = -1;
this.card = default;
}

public ActionSet(ActionType type, int lane) {
if(type != ActionType.DRAW && type != ActionType.COMBAT)
throw new ArgumentException("Invalid overload called for this type.", nameof(type));
this.type = type;
this.lane = lane;
this.card = default;
}

public ActionSet(ActionType type, CardSpecification card, int lane) {
if(type != ActionType.PLAY && type != ActionType.FACEUP_PLAY && type != ActionType.DISCARD)
throw new ArgumentException("Invalid overload called for this type.", nameof(type));
this.type = type;
this.lane = lane;
this.card = card;
}
}
93 changes: 23 additions & 70 deletions BinaryMatrixEngine/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,6 @@ public enum PlayerRole {
DEFENDER
}

public enum ActionType {
NONE,
DRAW,
PLAY,
FACEUP_PLAY,
COMBAT,
DISCARD
}

public struct ActionSet {
public readonly ActionType type;
public readonly int lane;
public readonly CardSpecification? card;

/* "a" Pseudo-Lane */
public const int LANE_A = 6;
public static readonly ActionSet NONE = new(ActionType.NONE);

public ActionSet(ActionType type) {
if(type != ActionType.NONE)
throw new ArgumentException("Invalid overload called for this type.", nameof(type));
this.type = type;
this.lane = -1;
this.card = default;
}

public ActionSet(ActionType type, int lane) {
if(type != ActionType.DRAW && type != ActionType.COMBAT)
throw new ArgumentException("Invalid overload called for this type.", nameof(type));
this.type = type;
this.lane = lane;
this.card = default;
}

public ActionSet(ActionType type, CardSpecification card, int lane) {
if(type != ActionType.PLAY && type != ActionType.FACEUP_PLAY && type != ActionType.DISCARD)
throw new ArgumentException("Invalid overload called for this type.", nameof(type));
this.type = type;
this.lane = lane;
this.card = card;
}
}

public interface CardSpecification {
public int? ResolveForPlayer(Player player);
}

public class PlayerData : IDisposable {
public readonly PlayerID id;
public int invalidOperationCount;
Expand All @@ -73,6 +26,29 @@ public PlayerData Copy() {
}
}

public readonly struct PlayerID {
public readonly PlayerRole role;
public readonly int index;

public PlayerID(PlayerRole role, int index) {
this.role = role;
this.index = index;
}

override public string ToString() {
return (this.role == PlayerRole.ATTACKER ? 'a' : 'd') + this.index.ToString();
}
}

public interface PlayerActor : IDisposable {
public void ReportOperationError(OperationError error);
}

[Obsolete("Implement your own `GetActions` hook instead of relying on this interface.")]
public interface ActionablePlayerActor : PlayerActor {
public ActionSet GetAndConsumeAction();
}

public sealed class Player : IDisposable {
public Player(
PlayerRole role,
Expand Down Expand Up @@ -109,26 +85,3 @@ public void Dispose() {
this.actor.Dispose();
}
}

public interface PlayerActor : IDisposable {
public void ReportOperationError(OperationError error);
}

[Obsolete("Implement your own `GetActions` hook instead of relying on this interface.")]
public interface ActionablePlayerActor : PlayerActor {
public ActionSet GetAndConsumeAction();
}

public readonly struct PlayerID {
public readonly PlayerRole role;
public readonly int index;

public PlayerID(PlayerRole role, int index) {
this.role = role;
this.index = index;
}

override public string ToString() {
return (this.role == PlayerRole.ATTACKER ? 'a' : 'd') + this.index.ToString();
}
}
Loading