From: Skullheadx Date: Sat, 23 May 2026 03:19:24 +0000 (-0400) Subject: REMOVE BOOL FOR IN JAIL X-Git-Url: http://git.skullheadx.com/about.html?a=commitdiff_plain;h=e08ff47ed87cb50b7efa2babacbf310f8ae656a0;p=monopoly-web.git REMOVE BOOL FOR IN JAIL --- diff --git a/game/game.go b/game/game.go index 2c67838..bf5e1c0 100644 --- a/game/game.go +++ b/game/game.go @@ -22,6 +22,12 @@ func initTurn(pID PlayerID) Turn { 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)} @@ -38,7 +44,8 @@ func InitCtx(randSeed rand.Source, players []Player) *Context { return &Context{ Random: rand.New(randSeed), Players: Players{ - Alive: players, + Alive: players, + CanMove: playerIDs, }, Turn: initTurn(startingPlayerID), Visitors: Visitors{ @@ -67,10 +74,18 @@ func InitPlayer() Player { 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()] } diff --git a/game/jail.go b/game/jail.go index f7d02b2..cdccb74 100644 --- a/game/jail.go +++ b/game/jail.go @@ -9,18 +9,20 @@ func (ctx *Context) RemovePlayerFromJail(playerID PlayerID) { 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] } } } diff --git a/game/movement.go b/game/movement.go index 61772a0..68233a9 100644 --- a/game/movement.go +++ b/game/movement.go @@ -8,13 +8,9 @@ func GetPlayerMoveDistance(start SpaceID, dest SpaceID) int32 { 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) diff --git a/game/types.go b/game/types.go index 5ad649c..fd0ad19 100644 --- a/game/types.go +++ b/game/types.go @@ -9,7 +9,6 @@ type Player struct { Money int32 CurrentSpaceID SpaceID GetOutOfJailCards int32 - CanMove bool } type PropertyType int @@ -135,7 +134,8 @@ type Modifiers struct { } type Players struct { - Alive []Player // PlayerID is PK + Alive []Player // PlayerID is PK + CanMove []PlayerID } type Turn struct { diff --git a/game/unowned.go b/game/unowned.go index bc4d164..c42ca86 100644 --- a/game/unowned.go +++ b/game/unowned.go @@ -1,29 +1,29 @@ 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) - } + // } }