5
4
The ChatRoom is here
I love playing the card game BS, but sometimes, it just doesn't have enough oomph for my short attention span. Instead, let's play some Russian BS.
Rules
Here is a quick guide to the rules.
- The game begins with a random player declaring the card type of the round (out of 14 options:
A,2,3...10,J,Q,K,j
where thej
stands for joker) - The same player starts the round, placing down as many cards as he or she wants, which all have to be of the declared card type.
- Any player can call BS on the play. If multiple players call BS, the player closest to the player who put down the cards to the right will be the one to call BS
- If BS is called on the play, then the cards played there are checked by the moderator. If the cards were indeed valid (i.e., all of the declared type or jokers), the player who called BS will take all of the cards played in the round. Otherwise, the player who played the invalid cards will take all of them.
- If no BS is called, the next player is up to play, and must also play the declared card type.
- We also allow players to pass their turn if they don't wish to play. However, if they pass, they are not allowed to play for the rest of the round (although they can call BS)
- If every player passes, then the round ends, and the player who played the last cards will start the next round by declaring the card type.
- If BS is called, the player who played the cards will start the next round and declare if he played valid cards, else the player who called BS will start.
- The player who has no cards at the end of the game wins.
I like these rules because they don't force you to lie, but usually, players tend to lie more than in the original version of BS
Challenge
This challenge will be a king-of-the-hill challenge, with submissions providing bots to play the game. The bots will be written in Python 3, although I'll try my best to accommodate all submissions.
The submissions should consist of the following three functions:
CallBS - determines whether you seek to call BS or not on a play
PlayCards - determines what cards you want to play
StartRound - determines what the declared type of the round is, if you are chosen to pick it.
The submitted functions should be named such that their names are ***_CallBS
, ***_PlayCards
, and ***_StartRound
, where ***
is the name of your bot.
Below are example functions that describe the inputs and outputs:
def example_CallBS(self,pos,player,handSize,currCard,numCards,numPile):
'''This function will output True if the bot seeks to call BS on the
current move, or False if not. The parameters are
- self: class variable
- pos: int - how many positions away you are to the right of the player (Note: if
your function got called, that means everyone to your left before the player decided
not to call BS)
- player: str - holds the name of the bot who just played cards
- handSize: int - how many cards playing bot holds
- currCard: str - current card in play (One of A,2,3,4,5,6,7,8,9,10,J,Q,K,j)
- numCards: int - number of cards just played by player
- numPile: int - number of cards in the pile (not including played cards this turn)
'''
return True
def example_PlayCards(self,currCard,numPile,stillPlaying):
'''This function will output a sublist of the hand of the bot to play this turn, or None to pass.
The parameters are
- self: class variable
- currCard: str - current card in play (One of A,2,3,4,5,6,7,8,9,10,J,Q,K,j)
- numPile: int - number of cards in the pile
- stillPlaying: list of str - players who haven't passed this round
'''
return self.hand[:]
def example_StartRound(self):
'''This function will output a string representing the card that will be played for the coming round (One of A,2,3,4,5,6,7,8,9,10,J,Q,K,j)
The parameters are
- self: class variable
'''
return 'A'
In addition, you will be provided with the following utilities
self.obj - A blank object for your usage to store knowledge between calls
self.hand: list of card objects - Your current hand in card objects (calling card.val gives you the str value of the card)
self.numBots: int - number of competitors you have
self.getRandom(): function - outputs a random number from 0 to 1.
If you want to use any sort of randomness, you must use the self.getRandom()
function provided. You may not edit any of these objects except for self.obj
Parameters and more Rules
- The cards in this game (you'll see the class that the cards belong to in the controller below) don't have a suit since suits don't matter to this game.
- The number of cards in the game will be
14*number of bots
(numBots of each type of card) - In the output of PlayCards, you must output cards that are in your hand. The program will not like you otherwise. You also must output card objects, not strings.
- You may take at most 10 ms on average over 5 turns for
StartRound
, 50 ms averaged over 5 turns forPlayCards
, and 20 ms averaged over 5 turns forCallBS
.
Controller
In this Controller, you add your functions to the top of the program, then add a tuple of all three functions, in the order of (CallBS, PlayCards, StartRound)
to the list BotParams
. The Controller should take it from there.
Below is the controller with the example bot from earlier. This bot will not be participating, nor will any bots that obviously aren't aiming the win the competition.
import random as rn
rn.seed(12321)#Subject to change
def example_CallBS(self,pos,player,handSize,currCard,numCards,numPile):
return True
def example_PlayCards(self,currCard,numPile,stillPlaying):
return self.hand[:]
def example_StartRound(self):
return 'A'
#This is how you add your bot to the competition. Add the tuple of all three of your functions to BotParams
BotParams = [(example_CallBS,example_PlayCards,example_StartRound)]
#This is the controller
class Obj:
pass
class card:
def __init__(self, val):
self.val=val
def __eq__(self,other):
return (self.val==other or self.val=='j')
def __str__(self):
return self.val
class BSgame:
def __init__(self,BotParams):
self.numBots = len(BotParams)
self.AllCards = ['A','J','Q','K','j']+[str(i) for i in range(2,11)]
x=[card(j) for j in self.AllCards*self.numBots]
rn.shuffle(x)
self.hands = [x[14*i:14*i+14] for i in range(self.numBots)]
rn.shuffle(BotParams)
self.BotList = [BSBot(self.hands[i],len(BotParams),*BotParams[i]) for i in range(self.numBots)]
self.play = []
self.pile = []
self.isRound = False
self.isTurn = 0
self.currCard = None
self.winner=None
self.GameSummary = [str(i) for i in self.BotList]
def results(self):
print("The winner is "+self.winner)
print("Final Standings:")
for i in self.BotList:
print(i)
def checkBS(self, caller):
if min([i==self.currCard for i in self.play]):
self.BotList[caller].hand.extend(self.pile)
self.BotList[caller].hand.extend(self.play)
self.GameSummary.append(self.BotList[caller].name+" called BS but was wrong!")
if self.BotList[self.isTurn].hand==[]:
self.winner=self.BotList[self.isTurn].name
self.GameSummary.append(self.BotList[self.isTurn].name+" has won the game!")
else:
self.BotList[self.isTurn].hand.extend(self.pile)
self.BotList[self.isTurn].hand.extend(self.play)
self.GameSummary.append(self.BotList[caller].name+" called BS and was right!")
self.isTurn=caller
self.isRound=False
self.pile=[]
def isBS(self):
for i in range(1,self.numBots):
if self.BotList[(i+self.isTurn)%self.numBots].callBS(i,self.BotList[self.isTurn].name,len(self.BotList[self.isTurn].hand),self.currCard,len(self.play),len(self.pile)):
self.checkBS(i)
break
if self.isRound:
if self.BotList[self.isTurn].hand==[]:
self.winner=self.BotList[self.isTurn].name
self.GameSummary.append(self.BotList[self.isTurn].name+" has won the game!")
self.pile.extend(self.play)
def startRound(self):
self.currCard = self.BotList[self.isTurn].startRound()
for i in self.BotList:
i.inRound = True
self.isRound=True
self.GameSummary.append(self.BotList[self.isTurn].name+" started the round by picking "+self.currCard+" for the round.")
def __iter__(self):
return self
def __next__(self):
if not self.isRound:
self.startRound()
passList = [i.name for i in self.BotList if i.inRound]
self.play =self.BotList[self.isTurn].playCards(self.currCard,len(self.pile),passList)
if self.play == None:
self.BotList[self.isTurn].inRound=False
self.GameSummary.append(self.BotList[self.isTurn].name+" passed its turn.")
else:
try:
for i in self.play:
self.BotList[self.isTurn].hand.remove(i)
except:
raise Exception("You can't play a card you don't have, you dimwit")
self.GameSummary.append(self.BotList[self.isTurn].name+" played "+",".join(i.val for i in self.play)+".")
self.isBS()
if self.winner!=None:
raise StopIteration
if set(passList)!={False}:
while True:
self.isTurn=(self.isTurn+1)%self.numBots
if self.BotList[self.isTurn].inRound:
break
else:
self.GameSummary.append("Everyone passed. "+self.BotList[self.isTurn].name+" starts the next round.")
self.isRound=False
return(None)
class BSBot:
def __init__(self,myHand,numBots,CallBS,PlayCards,StartRound):
self.obj=Obj()
self.hand = myHand
self.numBots = numBots
self.name = CallBS.__name__.split('_')[0]
self.callBS = lambda pos, player, handSize, currCard, numCards, numPile: CallBS(self,pos,player, handSize, currCard, numCards, numPile)
self.playCards = lambda currCard, numPile, stillPlaying: PlayCards(self,currCard, numPile, stillPlaying)
self.startRound= lambda:StartRound(self)
def __str__(self):
if self.hand==[]:
return(self.name+': WINNER!')
return(self.name+": "+", ".join(str(i) for i in self.hand))
def getRandom(self):
return rn.random()
Mod = BSgame(BotParams)
for i in Mod:
pass
Mod.results()
Additionally, if you want to see a summary of the game, type in the following command at the end of the program:
print("\n".join(Mod.GameSummary))
Is self.numBots including yourself or not? – Quintec – 2018-09-21T20:39:36.497
3I thought this was going to be a pre-US midterm election social media analysis challenge. – ngm – 2018-09-21T20:59:35.690
@Quintec yes and ngm, lmaooo – Don Thousand – 2018-09-21T21:26:38.180
1In the controller, in the isBS function, "if self.BotList[(i+self.isTurn)%self.numBots].callBS(i,self.BotList[self.isTurn].name,len(self.BotList[isTurn].hand),self.currCard,len(self.play),len(self.pile)):"
should be
"if self.BotList[(i+self.isTurn)%self.numBots].callBS(i,self.BotList[self.isTurn].name,len(self.BotList[self.isTurn].hand),self.currCard,len(self.play),len(self.pile)):"
It's just missing a self. Apologies for the formatting; I'm not sure how to make it nicer. – Spitemaster – 2018-09-22T13:05:46.423
Also in the checkBS function, you should add a default in the min() because otherwise it throws a 'ValueError: min() arg is an empty sequence' error. – Spitemaster – 2018-09-22T13:13:50.697
@Spitemaster ok will do! – Don Thousand – 2018-09-22T13:28:42.410
Did you ever determine winner of this? – Quintec – 2018-10-20T00:55:36.657
@Quintec Nope! I'll do it this weekend. I've been crazy busy, my apologies. – Don Thousand – 2018-10-20T01:01:36.907
Bump, I'm curious :P – Quintec – 2018-11-01T01:23:36.443
@Quintec Sorry, I'll do it tonight. God I've been so busy. – Don Thousand – 2018-11-01T01:32:39.880
4I'm voting to close this question because it is already de-facto closed to new answers ("Submissions accepted until October 13th [2018]"). – pppery – 2019-09-03T03:31:06.057