diff --git a/game/master.go b/game/master.go new file mode 100644 index 0000000..d8e9ead --- /dev/null +++ b/game/master.go @@ -0,0 +1,16 @@ +package game + +import ( + "errors" + "local/secret-hitler-via-matrix/game/state" +) + +type Master struct{} + +func New() (*Master, error) { + return nil, errors.New("not impl") +} + +func (m *Master) State() (state.State, error) { + return state.State{}, errors.New("not impl") +} diff --git a/game/state/alignment.go b/game/state/alignment.go new file mode 100644 index 0000000..00e4d38 --- /dev/null +++ b/game/state/alignment.go @@ -0,0 +1,17 @@ +package state + +type Alignment int + +const ( + LIBERAL = Alignment(iota) + FACIST + HITLER +) + +func (a Alignment) CanSeeFacist() bool { + return a == FACIST +} + +func (a Alignment) CanSeeHitler() bool { + return a == FACIST +} diff --git a/game/state/card.go b/game/state/card.go new file mode 100644 index 0000000..18f164f --- /dev/null +++ b/game/state/card.go @@ -0,0 +1,17 @@ +package state + +type CardState struct { + IsFacist bool + + IsDrawn bool + IsPlayed bool + IsDiscarded bool +} + +func (state CardState) Redact(alignment Alignment) CardState { + state2 := state + + state2.IsFacist = false + + return state2 +} diff --git a/game/state/player.go b/game/state/player.go new file mode 100644 index 0000000..5960cbe --- /dev/null +++ b/game/state/player.go @@ -0,0 +1,30 @@ +package state + +type PlayerState struct { + ID string + Name string + + IsFacist bool + IsHitler bool + + IsDead bool + + IsChancellor bool + IsCandidateChancellor bool + IsPresident bool + IsCandidatePresident bool + + IsVoting bool + IsShooting bool + IsInspecting bool + IsPeeking bool +} + +func (state PlayerState) Redact(alignment Alignment) PlayerState { + state2 := state + + state2.IsFacist = state2.IsFacist && alignment.CanSeeFacist() + state2.IsHitler = state2.IsHitler && alignment.CanSeeHitler() + + return state2 +} diff --git a/game/state/state.go b/game/state/state.go new file mode 100644 index 0000000..ccbc920 --- /dev/null +++ b/game/state/state.go @@ -0,0 +1,36 @@ +package state + +type State struct { + Players []PlayerState + Cards []CardState +} + +func (state State) Copy() State { + return State{ + Players: append([]PlayerState{}, state.Players...), + Cards: append([]CardState{}, state.Cards...), + } +} + +func (state State) RedactLiberal() State { + return state.Redact(LIBERAL) +} + +func (state State) RedactFacist() State { + return state.Redact(FACIST) +} + +func (state State) RedactHitler() State { + return state.Redact(HITLER) +} + +func (state State) Redact(alignment Alignment) State { + state2 := state.Copy() + for i := range state2.Players { + state2.Players[i] = state2.Players[i].Redact(alignment) + } + for i := range state2.Cards { + state2.Cards[i] = state2.Cards[i].Redact(alignment) + } + return state2 +} diff --git a/server/server.go b/server/server.go new file mode 100644 index 0000000..61f75d3 --- /dev/null +++ b/server/server.go @@ -0,0 +1,9 @@ +package server + +import "errors" + +type Server struct{} + +func New() (*Server, error) { + return &Server{}, errors.New("not impl") +}