func InitCtx(randSeed rand.Source, players []Player) *Context {
startingPlayerID := PlayerID{id: 0}
+
+ playerIDs := []PlayerID{}
+ for i := range players {
+ playerIDs = append(playerIDs, PlayerID{id: int32(i)})
+ }
+
ownableProps := []OwnableProperty{}
for i, s := range BoardSpaces {
spaceID := SpaceID{id: int32(i)}
return &Context{
Random: rand.New(randSeed),
Players: Players{
- Alive: players,
+ Alive: players,
+ CanMove: playerIDs,
},
Turn: initTurn(startingPlayerID),
Visitors: Visitors{
Money: StartingMoney,
CurrentSpaceID: SpecialSpaces.Go,
GetOutOfJailCards: StartingGetOutOfJailFreeCards,
- CanMove: true,
}
}
+func (ctx *Context) PlayerCanMove(pID PlayerID) bool {
+ for i, _ := range ctx.Players.CanMove {
+ if i == pID.Index() {
+ return true
+ }
+ }
+ return false
+}
+
func (ctx *Context) GetCurrentTurnPlayer() *Player {
return &ctx.Players.Alive[ctx.Turn.Current.Index()]
}
if playerID == iJV.visitorID {
ctx.Visitors.InJail[i] = ctx.Visitors.InJail[len(ctx.Visitors.InJail)-1]
ctx.Visitors.InJail = ctx.Visitors.InJail[:len(ctx.Visitors.InJail)-1]
-
}
}
- ctx.Players.Alive[playerID.Index()].CanMove = true
+
+ if !ctx.PlayerCanMove(playerID) {
+ ctx.Players.CanMove = append(ctx.Players.CanMove, playerID)
+ }
}
func (ctx *Context) RemovePlayerFromMoveable(pID PlayerID) {
- for i, _ := range ctx.Players.Alive {
- playerID := PlayerID{id: int32(i)}
- if pID == playerID {
- ctx.Players.Alive[playerID.Index()].CanMove = false
+ for i, cM := range ctx.Players.CanMove {
+ if pID == cM {
+ ctx.Players.CanMove[i] = ctx.Players.CanMove[len(ctx.Players.CanMove)-1]
+ ctx.Players.CanMove = ctx.Players.CanMove[:len(ctx.Players.CanMove)-1]
}
}
}
return distance
}
-func (ctx *Context) AllowedToMove(playerID PlayerID) bool {
- return ctx.Players.Alive[playerID.Index()].CanMove
-}
-
func (ctx *Context) ProcessMovement() {
cID := ctx.Turn.Current
- if ctx.AllowedToMove(cID) {
+ if ctx.PlayerCanMove(cID) {
dist := ctx.Turn.MoveQueue[0]
ctx.Turn.MoveQueue = ctx.Turn.MoveQueue[1:]
ctx.AdvancePlayer(cID, ctx.Players.Alive[cID.Index()].CurrentSpaceID, dist)
Money int32
CurrentSpaceID SpaceID
GetOutOfJailCards int32
- CanMove bool
}
type PropertyType int
}
type Players struct {
- Alive []Player // PlayerID is PK
+ Alive []Player // PlayerID is PK
+ CanMove []PlayerID
}
type Turn struct {
package game
func (ctx *Context) ProcessUnowned() {
- for _, uV := range ctx.Visitors.Unowned {
- visitorID := uV.visitorID
- propID := uV.propertyID
+ // for _, uV := range ctx.Visitors.Unowned {
+ // visitorID := uV.visitorID
+ // propID := uV.propertyID
- prop := ctx.Properties.Owners[propID.Index()]
+ // prop := ctx.Properties.Owners[propID.Index()]
- // TODO: trigger buy or auction
+ // TODO: trigger buy or auction
- // spaceID := prop.SpaceID
- // space := BoardSpaces[spaceID.Index()]
- //
- // var price int32 = 0
- //
- // switch space.PropertyType {
- // case TypeColor:
- // price = ColorProperties[space.SubIndexID].Price
- // case TypeUtility:
- // price = UtilityPrice
- // case TypeRailroad:
- // price = RailroadPrice
- // }
- //
- // ctx.AdjustPlayerMoney(visitorID, -price)
+ // spaceID := prop.SpaceID
+ // space := BoardSpaces[spaceID.Index()]
+ //
+ // var price int32 = 0
+ //
+ // switch space.PropertyType {
+ // case TypeColor:
+ // price = ColorProperties[space.SubIndexID].Price
+ // case TypeUtility:
+ // price = UtilityPrice
+ // case TypeRailroad:
+ // price = RailroadPrice
+ // }
+ //
+ // ctx.AdjustPlayerMoney(visitorID, -price)
- }
+ // }
}