Created
December 16, 2012 09:39
-
-
Save Sephiroth-XIII/4305885 to your computer and use it in GitHub Desktop.
This is a Simulator for The Bidding Game of Hackerrank. This will help u to compare any 2 bidding bots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
#ALL IMPORT STATEMENTS HERE | |
def calculate_bid_player1(player,pos,first_moves,second_moves): | |
#PLAYER 1 BOT HERE | |
def calculate_bid_player2(player,pos,first_moves,second_moves): | |
#PLAYER 2 BOT HERE | |
#THE SIMULATOR CODE | |
player1=100 | |
player2=100 | |
first_moves=[] | |
second_moves=[] | |
pos=5 | |
draw123=0 | |
play1=1 | |
play2=2 | |
while pos!=0 or pos!=10: | |
bid1=calculate_bid_player1(play1,pos,first_moves,second_moves) | |
bid2=calculate_bid_player2(play2,pos,first_moves,second_moves) | |
first_moves.append(int(bid1)) | |
second_moves.append(int(bid2)) | |
i=len(first_moves)-1 | |
if first_moves[i]>second_moves[i]: | |
player1-=first_moves[i] | |
pos-=1 | |
elif first_moves[i]<second_moves[i]: | |
player2-=second_moves[i] | |
pos+=1 | |
else: | |
if draw123%2==0: | |
player1-=first_moves[i] | |
pos-=1 | |
else: | |
player2-=second_moves[i] | |
pos+=1 | |
draw123+=1 | |
print "Player1 Bid : ",first_moves[i],"\tPlayer1 Balance : ",player1 | |
print "Player2 Bid : ",second_moves[i],"\tPlayer2 Balance : ",player2 | |
print "Position : ",pos | |
print "" | |
if pos==0: | |
print "PLAYER 1 WINS" | |
break | |
if pos==10: | |
print "PLAYER 2 WINS" | |
break | |
if (player2>0 and second_moves[i]<=0) or second_moves[i]<0 or (second_moves[i]>player2+second_moves[i]): | |
print "PLAYER 2 has made a wrong bet" | |
print "PLAYER 1 WINS" | |
break | |
if (player1>0 and first_moves[i]<=0) or first_moves[i]<0 or (first_moves[i]>player1+first_moves[i]): | |
print "PLAYER 1 has made a wrong bet" | |
print "PLAYER 2 WINS" | |
break | |
if player1==0 and player2==0: | |
print "Draw" | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment