public void printResults( ArrayList<Bidder> Bidders, ArrayList<Auction> Auctions, OptimisedBidder OptimisedBidder) { DecimalFormat decFor = new DecimalFormat("00.00"); // Print the utility that all generated bidders have made from the auction for (int i = 0; i < Bidders.size(); i++) { Bidder bidder = Bidders.get(i); double utility = 0; for (int j = 0; j < Auctions.size(); j++) { Auction auction = Auctions.get(j); if (bidder == auction.getHighBidder()) { utility = utility + auction.getUtility(); } } System.out.println( bidder.getUserName() + " has made a utility of $" + decFor.format(utility)); } double optimisedBidderutility = 0; for (int j = 0; j < Auctions.size(); j++) { Auction auction = Auctions.get(j); if (OptimisedBidder == auction.getHighBidder()) { optimisedBidderutility = optimisedBidderutility + auction.getUtility(); } } System.out.println( OptimisedBidder.getUserName() + " has made a utility of $" + decFor.format(optimisedBidderutility)); }
private void setProgressCircle(Bidder bidder) { if ((bidder.getState() == BidderState.BIDDING) || (bidder.getState() == BidderState.JOINING)) { setProgressBarIndeterminateVisibility(true); } else { setProgressBarIndeterminateVisibility(false); } }
private Bidder join(XMPPAuctionHouse house, String itemId) throws AuctionIsNotAvailable { Auction auction = house.auctionFor(itemId); Bidder bidder = new Bidder(auction); auction.addAuctionEventListener(bidder); bidder.addBidderListener(new UIThreadBidderListener(new BidderDisplayer())); bidder.join(); bidder.setIdImage(idImages[idSelect]); return bidder; }
public void passAuctionsToBidders() { for (int i = 0; i < Bidders.size(); i++) { // Iterate through the ArrayList of bidders generated by the scenario generator Bidder bidder = Bidders.get(i); bidder.setAuctions(Auctions); bidder.setPerceivedRrp(); } }
private int preSnipe() { UpdateBlocker.startBlocking(); mEntry.setLastStatus("Preparing snipe."); // Log in mCJ = mLogin.getSignInCookie(null); if (mCJ == null) { // Alert somebody that we couldn't log in? mEntry.setLastStatus( "Pre-snipe login failed. Snipe will be retried, but is unlikely to fire."); MQFactory.getConcrete("Swing").enqueue("NOTIFY Pre-snipe login failed."); JConfig.log().logDebug("Pre-snipe login failed."); UpdateBlocker.endBlocking(); return RESNIPE; } int presnipeResult = SUCCESSFUL; // Get Bid Key/Form try { JConfig.increment("stats.presniped"); mBidForm = mBidder.getBidForm(mCJ, mEntry, mEntry.getSnipeAmount()); } catch (BadBidException bbe) { String result = getSnipeResult(bbe.getResult(), mEntry.getTitle(), mEntry); mEntry.setLastStatus(result); MQFactory.getConcrete("Swing").enqueue("NOTIFY " + result); JConfig.log().logDebug(result); presnipeResult = FAIL; } UpdateBlocker.endBlocking(); return presnipeResult; }
private int doSnipe() { // Just punt if we had failed to get the bidding form initially. if (mBidForm == null) return FAIL; UpdateBlocker.startBlocking(); if (mEntry.isMultiSniped()) { MultiSnipe ms = mEntry.getMultiSnipe(); // Make sure there aren't any update-unfinished items. if (ms.anyEarlier(mEntry)) { mEntry.setLastStatus( "An earlier snipe in this multisnipe group has not ended, or has not been updated after ending."); mEntry.setLastStatus( "This snipe is NOT being fired, as it could end up winning two items."); UpdateBlocker.endBlocking(); return RESNIPE; } } MQFactory.getConcrete("Swing").enqueue("Sniping on " + mEntry.getTitle()); mEntry.setLastStatus("Firing actual snipe."); int rval = mBidder.placeFinalBid( mCJ, mBidForm, mEntry, mEntry.getSnipeAmount(), mEntry.getSnipeQuantity()); JConfig.increment("stats.sniped"); String snipeResult = getSnipeResult(rval, mEntry.getTitle(), mEntry); mEntry.setLastStatus(snipeResult); MQFactory.getConcrete("Swing").enqueue("NOTIFY " + snipeResult); JConfig.log().logDebug(snipeResult); mEntry.snipeCompleted(); UpdateBlocker.endBlocking(); return DONE; }
public void run() { double budget = 50; Optimiser optimiser = new Optimiser(); // Instantiate optimiser class ScenarioGenerator scenGen = new ScenarioGenerator(5, 20); // Instantiate ScenarioGenerator class OptimisedBidder OptimisedBidder = new OptimisedBidder("OptimisedBidder", budget); // Instantiate OptimisedBidder class scenGen.createItemAndAuction(); // Create items and auctions scenGen.createBidders(); // Create bidders scenGen.passAuctionsToBidders(); // Pass list of generated auctions to all simulated bidders OptimisedBidder.setAuctions( scenGen.getAuctions()); // Pass list of generated auctions to OptimisedBidder OptimisedBidder.setOptimiser(optimiser); // Pass optimiser to OptimisedBidder OptimisedBidder.setScenarioGenerator(scenGen); // Pass scenGen to OptimisedBidder scenGen .printItemsUtility(); // Prints a list of all items created by the scenario generator, the // current high bid on that item and it's resultant utility System.out.println("Simulation started at: " + time()); try { OptimisedBidder.activate(); // Activate OptimisedBidder thread for (int i = 0; i < scenGen.getBidders().size(); i++) { // Activate bidder threads (i.e. set them to active, wakeup now and add them to the // queue Bidder bidder = scenGen.getBidders().get(i); bidder.activate(); } Scheduler.startSimulation(); // Start simulation hold(50); SimulationProcess.mainResume(); // Resume main thread } catch (SimulationException e) { e.printStackTrace(); } catch (RestartException e) { e.printStackTrace(); } System.out.println("Simulation ended at: " + time()); printResults(scenGen.getBidders(), scenGen.getAuctions(), OptimisedBidder); System.exit(0); }
static void displayRound( int playerOneMoney, int playerTwoMoney, int playerOneBid, int playerTwoBid, byte roundWinner, int currentPosition, Bidder playerOne, Bidder playerTwo) { System.out.println(playerOne.getName() + " Balance: " + playerOneMoney); System.out.println(playerTwo.getName() + " Balance: " + playerTwoMoney); switch (roundWinner) { case 0: break; case 1: System.out.println(playerOne.getName() + " bid: " + playerOneBid + " *Wins round"); System.out.println(playerTwo.getName() + " bid: " + playerTwoBid); break; case 2: System.out.println(playerOne.getName() + " bid: " + playerOneBid); System.out.println(playerTwo.getName() + " bid: " + playerTwoBid + " *Wins round"); break; default: // This case should never happen } for (int i = 0; i < NUMBER_OF_POSITIONS; i++) { if (i == currentPosition - 1) System.out.print(" X "); else System.out.print(" _ "); } System.out.println(); System.out.println(); }
/** Remove bids */ private void removeBids() { Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement("DELETE FROM auction_bid WHERE auctionId=?"); statement.setInt(1, getId()); statement.execute(); statement.close(); } catch (Exception e) { _log.fatal("Exception: Auction.deleteFromDB(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } for (Bidder b : _bidders.values()) { if (ClanTable.getInstance().getClanByName(b.getClanName()).getHasHideout() == 0) returnItem(b.getClanName(), PcInventory.ADENA_ID, b.getBid(), true); // 10 % tax else { L2Player bidder = L2World.getInstance().getPlayer(b.getName()); if (bidder != null) bidder.sendMessage("Congratulations! You have won a ClanHall!"); } ClanTable.getInstance().getClanByName(b.getClanName()).setAuctionBiddedAt(0, true); } _bidders.clear(); }
public static void main(String[] args) { // keep track of how much money each player has int playerOneMoney; int playerTwoMoney; // keep track of the position int currentPos; // variable for the players Bidder playerOne; Bidder playerTwo; // keep track of moves ArrayList<Integer> playerOneMoves = new ArrayList<Integer>(); ArrayList<Integer> playerTwoMoves = new ArrayList<Integer>(); // flag for illegal move boolean illegalMove = false; // Change this based on the Class they choice playerOne = new ExampleBidderOne(); playerTwo = new ExampleBidderTwo(); // Initialize the money playerOneMoney = STARTING_AMOUNT; playerTwoMoney = STARTING_AMOUNT; // Set the position currentPos = STARTING_POSITION; // Display the beginning displayRound(playerOneMoney, playerTwoMoney, 0, 0, (byte) 0, currentPos, playerOne, playerTwo); // while you are not at the ends and both players have money left keep playing while (currentPos != 1 && currentPos != NUMBER_OF_POSITIONS && playerOneMoney > 0 && playerTwoMoney > 0) { byte roundWinner; // get the players bids int playerOneBid = playerOne.calculateBid( playerOneMoves, playerTwoMoves, currentPos - 1, playerOneMoney, playerTwoMoney); int playerTwoBid = playerTwo.calculateBid( playerTwoMoves, playerOneMoves, NUMBER_OF_POSITIONS - currentPos, playerTwoMoney, playerOneMoney); // if someone makes an illegal bet other player wins if (playerOneBid <= 0 || playerOneBid > playerOneMoney) { illegalMove = true; System.out.println("Illegal bet. " + playerTwo.getName() + " wins."); break; } if (playerTwoBid <= 0 || playerTwoBid > playerTwoMoney) { illegalMove = true; System.out.println("Illegal bet. " + playerOne.getName() + " wins."); break; } // add the bets to the lists playerOneMoves.add(playerOneBid); playerTwoMoves.add(playerTwoBid); // in the event of a tie randomly select a winner if (playerOneBid == playerTwoBid) { // New Random to select the winner Random random = new Random(); if (random.nextBoolean()) { playerOneMoney -= playerOneBid; roundWinner = 1; currentPos--; } else { playerTwoMoney -= playerTwoBid; roundWinner = 2; currentPos++; } } else if (playerOneBid > playerTwoBid) { playerOneMoney -= playerOneBid; roundWinner = 1; currentPos--; } else { playerTwoMoney -= playerTwoBid; roundWinner = 2; currentPos++; } displayRound( playerOneMoney, playerTwoMoney, playerOneBid, playerTwoBid, roundWinner, currentPos, playerOne, playerTwo); } if (illegalMove) return; // display who wins if (currentPos == 1) { System.out.println(playerOne.getName() + " Wins!"); } // display who wins else if (currentPos == NUMBER_OF_POSITIONS) { System.out.println(playerTwo.getName() + " Wins!"); } // if both people are out of money it is a tie else if (playerOneMoney == 0 && playerTwoMoney == 0) { System.out.println("Tie game."); } // if player one spent all their money and player two has enough money left to win than player // two wins else if (playerOneMoney == 0 && playerTwoMoney >= NUMBER_OF_POSITIONS - currentPos) { System.out.println( playerOne.getName() + " is out of money, " + playerTwo.getName() + " Wins!"); } // if player two spent all their money and player one has enough money left to win than player // one wins else if (playerTwoMoney == 0 && playerOneMoney >= currentPos) { System.out.println( playerTwo.getName() + " is out of money, " + playerOne.getName() + " Wins!"); } // it is a tie else { System.out.println("Tie game."); } }