1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
package game
func GetPlayerMoveDistance(start SpaceID, dest SpaceID) int32 {
distance := dest.ID - start.ID
if distance < 0 {
distance += int32(len(BoardSpaces))
}
return distance
}
func (ctx *Context) ProcessMovement() {
cID := ctx.Turn.Current
for {
dist := ctx.Turn.MoveQueue[0]
ctx.Turn.MoveQueue = ctx.Turn.MoveQueue[1:]
ctx.AdvancePlayer(cID, ctx.Players.Alive[cID.Index()].CurrentSpaceID, dist)
ctx.ProcessLanding()
if len(ctx.Turn.MoveQueue) == 0 {
break
}
}
}
func (ctx *Context) ProcessLanding() {
ctx.ProcessGo()
ctx.ProcessTax()
ctx.ProcessOwnedColors()
ctx.ProcessOwnedUtility()
ctx.ProcessOwnedRailroad()
ctx.ProcessUnowned()
ctx.ProcessChance()
ctx.ProcessChest()
// ProcessPolice()
ctx.ProcessJail()
}
func CalculateNextPos(currentPosition SpaceID, distance int32) SpaceID {
nextPos := Add(currentPosition, distance)
nextPos.ID %= int32(len(BoardSpaces))
return nextPos
}
func (ctx *Context) AdvancePlayer(playerID PlayerID, currentPosition SpaceID, diceRoll int32) {
nextPos := CalculateNextPos(currentPosition, diceRoll)
ctx.Players.Alive[playerID.Index()].CurrentSpaceID = nextPos
numGoPasses := Add(currentPosition, diceRoll).ID / int32(len(BoardSpaces))
if numGoPasses > 0 {
if BoardSpaces[nextPos.Index()].PropertyType == TypeGo {
numGoPasses--
}
for range numGoPasses {
ctx.Visitors.Go = append(ctx.Visitors.Go, playerID)
}
}
prop := BoardSpaces[nextPos.Index()]
switch prop.PropertyType {
case TypeGo:
ctx.Visitors.Go = append(ctx.Visitors.Go, playerID)
case TypeChest:
ctx.Visitors.Chest = append(ctx.Visitors.Chest, playerID)
case TypeChance:
ctx.Visitors.Chance = append(ctx.Visitors.Chance, playerID)
case TypeTax:
ctx.Visitors.Tax = append(ctx.Visitors.Tax, TaxVisitor{VisitorID: playerID, TaxID: prop.SubIndexID})
case TypePolice: // hardcoding to send straight to jail
ctx.Turn.Log = append(ctx.Turn.Log, LogLandPolice)
ctx.PutPlayerInJail(playerID)
case TypeColor:
propID := ctx.getOwnablePropID(nextPos)
ownerID := ctx.Properties.Owners[propID.Index()].OwnerID
if ownerID != BankPlayerID { // property owned?
if ownerID != playerID && !ctx.IsMortgaged(propID) { // not by you
ctx.Visitors.Color = append(ctx.Visitors.Color, OwnedColorVisitor{VisitorID: playerID, OwnerID: ownerID, ColorID: prop.SubIndexID})
}
} else {
ctx.Visitors.Unowned = append(ctx.Visitors.Unowned, UnownedPropertyVisitor{VisitorID: playerID, PropertyID: propID})
}
case TypeRailroad:
propID := ctx.getOwnablePropID(nextPos)
ownerID := ctx.Properties.Owners[propID.Index()].OwnerID
if ownerID != BankPlayerID { // property owned?
if ownerID != playerID && !ctx.IsMortgaged(propID) { // not by you
ctx.Visitors.Railroad = append(ctx.Visitors.Railroad, OwnedRailroadVisitor{VisitorID: playerID, OwnerID: ownerID, RailroadID: prop.SubIndexID})
}
} else {
ctx.Visitors.Unowned = append(ctx.Visitors.Unowned, UnownedPropertyVisitor{VisitorID: playerID, PropertyID: propID})
}
case TypeUtility:
propID := ctx.getOwnablePropID(nextPos)
ownerID := ctx.Properties.Owners[propID.Index()].OwnerID
if ownerID != BankPlayerID { // property owned?
if ownerID != playerID && !ctx.IsMortgaged(propID) { // not by you
ctx.Visitors.Utility = append(ctx.Visitors.Utility, OwnedUtilityVisitor{VisitorID: playerID, OwnerID: ownerID, UtilityID: prop.SubIndexID, DiceRoll: diceRoll})
}
} else {
ctx.Visitors.Unowned = append(ctx.Visitors.Unowned, UnownedPropertyVisitor{VisitorID: playerID, PropertyID: propID})
}
}
}
|