1
1
package pet
2
2
3
3
import (
4
+ "math/rand/v2"
4
5
"sync"
5
6
"time"
6
7
)
@@ -104,21 +105,27 @@ func (r Room) String() string {
104
105
func (s * Status ) Clean (asof time.Time ) (Room , Satisfaction ) {
105
106
s .mu .Lock ()
106
107
defer s .mu .Unlock ()
107
- type pair struct {
108
+ type cleanup struct {
108
109
room Room
109
110
tm * time.Time
111
+ add time.Duration
110
112
}
111
- ck := []pair {
112
- {Bedroom , & s .bed },
113
- {Kitchen , & s .kitche },
114
- {Living , & s .living },
115
- {Bathroom , & s .bath },
113
+ ck := []cleanup {
114
+ {Bedroom , & s .bed , 100 * time .Hour },
115
+ {Bedroom , & s .bed , 120 * time .Hour },
116
+ {Kitchen , & s .kitche , 30 * time .Hour },
117
+ {Kitchen , & s .kitche , 50 * time .Hour },
118
+ {Living , & s .living , 156 * time .Hour },
119
+ {Living , & s .living , 176 * time .Hour },
120
+ {Bathroom , & s .bath , 80 * time .Hour },
121
+ {Bathroom , & s .bath , 100 * time .Hour },
116
122
}
123
+ rand .Shuffle (len (ck ), func (i , j int ) { ck [i ], ck [j ] = ck [j ], ck [i ] })
117
124
for _ , c := range ck {
118
125
if asof .Before (* c .tm ) {
119
126
continue
120
127
}
121
- * c .tm = asof .Add (40 * time . Hour )
128
+ * c .tm = asof .Add (c . add )
122
129
return c .room , s .satLocked (asof )
123
130
}
124
131
return AllClean , s .satLocked (asof )
@@ -128,9 +135,14 @@ func (s *Status) Clean(asof time.Time) (Room, Satisfaction) {
128
135
// love is interpreted as a number of minutes for which the pet will feel loved
129
136
// with this pat. If the resulting time expires before its existing love, it
130
137
// has no effect.
138
+ // If all the pet's other needs are met, but not pat, the pat becomes stronger.
131
139
func (s * Status ) Pat (asof time.Time , love int ) Satisfaction {
132
140
s .mu .Lock ()
133
141
defer s .mu .Unlock ()
142
+ r := s .satLocked (asof )
143
+ if r == (Satisfaction {Fed : true , Bed : true , Kitche : true , Living : true , Bath : true , Pats : false }) {
144
+ love *= 2
145
+ }
134
146
sat := asof .Add (time .Duration (love ) * time .Minute )
135
147
if s .pats .Before (sat ) {
136
148
s .pats = sat
0 commit comments