Example SIMPREMI.PRT
; SIMPREMI
;
; Program for Proteus
;
; (C) 2003-2004 Simone Zanella Productions
;
; This program simulates a price generator; these are the default parameters:
; 3   operators that, independently, randomly give prices to customers
; 57  prices per our to be given away
; 450 customers

#!proteus -z

DefCustomers = 450
DefPrices = 57
DefOperators = 3

IF STREQ(ARGV(5), "?")
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " operators prices_per_hour customers_per_hour"
  ABORT 0
FI
IF GE(ARGC, 5)
  N = ARGV(5)
  IF GE(ARGC, 6)
    W = ARGV(6)
    IF GE(ARGC, 7)
      G = ARGV(7)
    ELSE
      ; Number of customers to be served in one hour
      G = DefCustomers
    FI    
  ELSE
    ; Number of prices to be assigned in one hour
    W = DefPrices

    ; Number of customers to be served in one hour
    G = DefCustomers
  FI
ELSE
  ; Number of operators
  N = DefOperators

  ; Number of prices to be assigned in one hour
  W = DefPrices
  
  ; Number of customers to be served in one hour
  G = DefCustomers
FI

; Prices to be assigned in one hour by each operator
WT = FDIV(W, N)

; Initial percentage for each operator
P = SUB(MUL(FDIV(W, G), 100), 2)

; Likelyhood delta (positive or negative) when Win happens
Delta = 0.01
MaxDelta = 0.1

Term = VECNEW(N)
R = MyInitRand()
FOR X = 1 TO N
  V = VECNEW(4)
  VECSET(Term, X, V)
  VECSET(V, 1, R)
  VECSET(V, 2, 0)
  VECSET(V, 3, QUEUENEW())
  VECSET(V, 4, P)
  ADD(@R, 7)
NEXT

X = 0
WHILE LE(X, G)
  FOR Y = 1 TO N
    Win(Y)
  NEXT
  ADD(@X, N)
LOOP
CONSOLELN "Wins:"

S = ""
FOR X = 1 TO N
  S = LTRIM(S " " PADR("-- Operator " X " --", 20, " "), " ")
NEXT
CONSOLELN S

V = VECGET(Term, 1)
Q = VECGET(V, 3)
M = QUEUELEN(Q)

FOR Y = 1 TO M
  S = ""
  FOR X = 1 TO N
    V = VECGET(Term, X)
    Q = VECGET(V, 3)
    S = LTRIM(S " " PADR(DEQUEUE(Q), 20, " "), " ")  
  NEXT
  CONSOLELN S
NEXT

S = ""
FOR X = 1 TO N
  V = VECGET(Term, X)
  H = VECGET(V, 2)
  S = LTRIM(S " " PADR("Wins total: " H, 20, " "), " ")  
NEXT
CONSOLELN S
ABORT 0


FUNCTION Win(nterm)

V = VECGET(_Term, nterm)
H = VECGET(V, 2)
P = VECGET(V, 4)
IF GE(H, PUB(WT))
  vinto = 0
ELSE
  K = MyRandom()
  IF LE(K, P)
    vinto = 1
  ELSE
    vinto = 0
  FI
  VARIAZIONE = PUB(Delta)
  IF vinto
    IF GT(P, 0)
      SUB(@P, VARIAZIONE)
    FI
  ELSE
    IF LT(P, 100)
      ADD(@P, VARIAZIONE)
    FI
  FI
  IF vinto
    INC(@H)
  FI
FI
; Update H and P for the operator
VECSET(V, 2, H)
VECSET(V, 4, P)
ENQUEUE(VECGET(V, 3), vinto)
RETURN


FUNCTION MyInitRand()

; Initialize seed, based on time
RETURN ADD(CLOCK(), TIMETOSEC(TIME()))


FUNCTION MyRandom()

; Return a number between 1 and 100
RETURN INC(MOD(RANDOM(-1), 100))
Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell