package Ġuk . co . j ake lee . pixel book shop . utils Ċ Ċ import Ġuk . co . j ake lee . pixel book shop . database . entity . Owned F urniture With Owned Books Ċ import Ġuk . co . j ake lee . pixel book shop . database . entity . Pending Purchase Ċ import Ġuk . co . j ake lee . pixel book shop . look ups . F urniture Type Ċ import Ġuk . co . j ake lee . pixel book shop . look ups . Visitor Ċ import Ġkotlin . math . max Ċ Ċ class ĠPending Purchase Generator Ġ{ ĊĊĠĠĠ Ġfun Ġgenerate ( shop Id : ĠInt , Ġday : ĠInt , Ġf urniture : ĠList < Owned F urniture With Owned Books >): ĠList < Pending Purchase > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrandom Helper Ġ= ĠRandom Helper () ĊĠĠĠĠĠĠĠ Ġval Ġse ating F urniture Ġ= Ġget Se ating F urniture ( f urniture ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmax P urchases Ġ= ĠgetMax P urchases ( f urniture ) ĊĠĠĠĠĠĠĠ Ġval Ġmax Visitor s Ġ= Ġse ating F urniture . sum By Ġ{ Ġit . owned F urniture . f urniture . capacity Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġnum Visitor s Ġ= Ġ 1 // Ġmax ( random Helper . getInt ( max Visitor s ), Ġ 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpending P urchases Ġ= Ġmutable ListOf < Pending Purchase >() ĊĠĠĠĠĠĠĠ Ġval Ġall Books Ġ= Ġget Display F urniture ( f urniture ) ĊĠĠĠĠĠĠĠ Ġ( 0 Ġuntil Ġnum Visitor s ). forEach Ġ{ Ġ_ Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġvisitor Ġ= Ġget Visitor () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġse ating Area Ġ= Ġse ating F urniture . random (). owned F urniture ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnum P urchases Ġ= Ġmax ( random Helper . getInt ( max P urchases ), Ġ 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( 0 Ġuntil Ġnum P urchases ). forEach Ġ{ Ġ_ Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( all Books . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġbook Ġ= Ġall Books . random () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġall Books . remove ( book ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġpurchase Hour Ġ= Ġrandom Helper . getInt ( Game Time Helper . END _ HOUR ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpending P urchases . add ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPending Purchase ( 0 , Ġshop Id , Ġday , Ġpurchase Hour , Ġvisitor , Ġbook . id , Ġse ating Area . id ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ Ġ// ĠIf Ġwe Ġrun Ġout Ġof Ġbooks Ġduring Ġselection ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġpending P urchases ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġpending P urchases ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Se ating F urniture ( f urniture : ĠList < Owned F urniture With Owned Books >) Ġ= Ġf urniture ĊĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . owned F urniture . f urniture . type Ġ== ĠF urniture Type . Se ating Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠgetMax P urchases ( f urniture : ĠList < Owned F urniture With Owned Books >) Ġ= Ġf urniture ĊĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . owned F urniture . f urniture . type Ġ== ĠF urniture Type . Decoration Ġ} ĊĠĠĠĠĠĠĠ Ġ. sum By Ġ{ Ġit . owned F urniture . f urniture . capacity Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Display F urniture ( f urniture : ĠList < Owned F urniture With Owned Books >) Ġ= Ġf urniture ĊĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . owned F urniture . f urniture . type Ġ== ĠF urniture Type . Display Ġ&& Ġit . owned Books . isNotEmpty () Ġ} ĊĠĠĠĠĠĠĠ Ġ. flatMap Ġ{ Ġit . owned Books Ġ}. to Mutable List () ĊĊĠĠĠ Ġprivate Ġfun Ġget Visitor (): ĠVisitor Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtotal Weight ing Ġ= ĠVisitor . values (). sum By Double Ġ{ Ġit . frequency Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġrandom Number Ġ= ĠRandom Helper (). getDouble ( total Weight ing ) ĊĠĠĠĠĠĠĠ Ġvar Ġprobability Iterator Ġ= Ġ 0 . 0 ĊĠĠĠĠĠĠĠ Ġreturn ĠVisitor . values (). first OrNull Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprobability Iterator Ġ+= Ġit . frequency ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprobability Iterator Ġ>= Ġrandom Number ĊĠĠĠĠĠĠĠ Ġ} Ġ?: ĠVisitor . values (). first () ĊĠĠĠ Ġ} Ċ }