#Get the valuation price i.e the Auctioneer's expected price of the property puts"Enter the valuation: " STDOUT.flush valuation = gets.to_i #Get the Reserve price i.e. the minimum acceptable price of the property puts "Enter the reserve price: " STDOUT.flush reservePrice = gets.to_i #Each agent knows the maximun amount it can afford to pay for the property puts "How much is investerA willing to spend? " STDOUT.flush max_price_A = gets.to_i puts "How much is investerB willing to spend? " STDOUT.flush max_price_B = gets.to_i puts "How much is investerC willing to spend? " STDOUT.flush max_price_C = gets.to_i puts "How much is investerD willing to spend? " STDOUT.flush max_price_D = gets.to_i puts "How much is investerE willing to spend? " STDOUT.flush max_price_E = gets.to_i #Calculate invester bid magins i.e. difference btw an agent's max willing price and the reserve price a_margin = max_price_A - reservePrice b_margin = max_price_B - reservePrice c_margin = max_price_C - reservePrice d_margin = max_price_D - reservePrice e_margin = max_price_E - reservePrice #Initialize bids for the investers here. First bid is reserve price plus half of the margin. #The other half will be incrementally bidded at 50% per round of bidding a_bid = reservePrice + a_margin/2 b_bid = reservePrice + b_margin/2 c_bid = reservePrice + c_margin/2 d_bid = reservePrice + d_margin/2 e_bid = reservePrice + e_margin/2 =begin Assumptions 1. Probability of two or more investers having the same max price is negligible 2. Investers do not know each other's willing prices 3. A margin can't be zero...to be explained later =end #Initialize auction's highest bid highestBid = reservePrice #Continue bidding as long as the highest bid is less or equal to valuation price. #Trivially, the property will be sold to the agent that reaches or exceeds the valuation price while highestBid <= valuation do #check if A should bid first if a_bid != max_price_A then if a_bid< b_bid && a_bid < c_bid && a_bid < d_bid && a_bid < e_bid then a_bid += a_margin * 0.25 highestBid = a_bid puts "Invester A is bidding ", highestBid, "\n" if highestBid >= valuation then puts "This property has been sold to Invester A" end end end # How does A quit when the while loop is true? #Check if B should bid first in the round if b_bid != max_price_B then if b_bid < a_bid && b_bid < c_bid && b_bid < d_bid && b_bid < e_bid then b_bid += b_margin * 0.25 highestBid = b_bid puts "Invester B is bidding ", highestBid, "\n" if highestBid >= valuation then puts "This property has been sold to Invester B" end end end #Check if C should bid first in the round if c_bid != max_price_C then if c_bid < a_bid && c_bid < b_bid && c_bid < d_bid && c_bid < e_bid then c_bid += c_margin * 0.25 highestBid = c_bid puts "Invester C is bidding ", highestBid, "\n" if highestBid >= valuation puts "This property has been sold to Invester C" end end end #Check if D should bid first in the round if d_bid != max_price_D then if d_bid < a_bid && d_bid < b_bid && d_bid < c_bid && d_bid < e_bid then d_bid += d_margin * 0.25 highestBid = d_bid puts "Invester D is bidding ", highestBid, "\n" if highestBid >= valuation puts "This property has been sold to Invester D" end end end #Check if E should bid first in the round if e_bid != max_price_E then if e_bid < a_bid && e_bid < b_bid && e_bid < c_bid && e_bid < d_bid then e_bid += e_margin * 0.25 highestBid = e_bid puts "Invester E is bidding ", highestBid, "\n" =begin if highestBid >= valuation puts "This property has been sold to Invester E" end =end end end end #=end