]> Skullheadx's Git Forge - monopoly-web.git/commitdiff
REMOVE BOOL FOR IN JAIL
authorSkullheadx <admonty1@protonmail.com>
Sat, 23 May 2026 03:19:24 +0000 (23:19 -0400)
committerSkullheadx <admonty1@protonmail.com>
Sat, 23 May 2026 03:29:13 +0000 (23:29 -0400)
game/game.go
game/jail.go
game/movement.go
game/types.go
game/unowned.go

index 2c678386980b5a996f4d38d70c0d39a409d01855..bf5e1c003962638004970a704cd717a8e53d6654 100644 (file)
@@ -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()]
 }
index f7d02b208c7da507b4142ae7c664f6c09e154e66..cdccb749e077b0494599f33350e5b29a5c0dd787 100644 (file)
@@ -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]
                }
        }
 }
index 61772a024db9d9bc52213d19a5e3a3e91042ccbe..68233a909c19bb852fe5b756802619f6a65470a3 100644 (file)
@@ -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)
index 5ad649c6d2c7d8f46dfdcafb7893980bf7e56866..fd0ad19139e4ffed1869e63742205d7d7a9ba182 100644 (file)
@@ -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 {
index bc4d16468e3e50a36dd84a9eab5cad744e3b1ac6..c42ca867642e57ceb3b9722d531e78f4c11c429c 100644 (file)
@@ -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)
 
-       }
+       // }
 }