stub state

master
Bel LaPointe 2021-02-21 23:22:49 -06:00
parent 7216ac1620
commit 3954d3cc6a
6 changed files with 125 additions and 0 deletions

16
game/master.go Normal file
View File

@ -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")
}

17
game/state/alignment.go Normal file
View File

@ -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
}

17
game/state/card.go Normal file
View File

@ -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
}

30
game/state/player.go Normal file
View File

@ -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
}

36
game/state/state.go Normal file
View File

@ -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
}

9
server/server.go Normal file
View File

@ -0,0 +1,9 @@
package server
import "errors"
type Server struct{}
func New() (*Server, error) {
return &Server{}, errors.New("not impl")
}