Skip to content

Commit

Permalink
Merge pull request #19 from Seven-of-Di/develop
Browse files Browse the repository at this point in the history
chore: Develop
  • Loading branch information
zdraganov authored Jan 4, 2024
2 parents d19f6e6 + 073545b commit 275ccf0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
17 changes: 12 additions & 5 deletions src/FullBoardCardPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def __init__(self, play_full_board_request) -> None:
self.vuln = VULNERABILITIES[play_full_board_request["vuln"]]
self.dealer = Direction.from_str(play_full_board_request["dealer"])
self.hands = Diag.init_from_pbn(play_full_board_request["hands"])
self.auction = play_full_board_request["auction"]

auction = []
for bid in play_full_board_request['auction']:
auction.append(bid['bid'])

self.auction = auction
self.playing_mode = PlayingMode.from_str(play_full_board_request[
"playing_mode"]) if "playing_mode" in play_full_board_request else PlayingMode.MATCHPOINTS

Expand All @@ -45,17 +50,19 @@ async def start():
continue

for message in resp["Messages"]:
req = PlayFullCardPlay(json.loads(message["Body"]))
msg_body_json = json.loads(message["Body"])

req = PlayFullCardPlay(msg_body_json)
bot = FullBoardPlayer(req.hands, req.vuln, req.dealer, req.playing_mode, MODELS)

play = await bot.get_card_play(req.auction)
message_body = {"auction": req.auction, "play": play}
play = await bot.get_card_play(req.auction, msg_body_json['lead'])
response_msg_body = {"auction": msg_body_json['auction'], "play": play}

sqs_client.send_message(
QueueUrl=response_queue_url,
MessageAttributes={
"BoardID": message["MessageAttributes"]["BoardID"]},
MessageBody=json.dumps(message_body),
MessageBody=json.dumps(response_msg_body),
)

# Mark the message as processed via deleating
Expand Down
16 changes: 10 additions & 6 deletions src/FullBoardPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_auction(self):
pass
return [bid for bid in auction if bid != "PAD_START"]

async def get_card_play(self, auction):
async def get_card_play(self, auction, raw_lead):
padded_auction = ["PAD_START"] * Direction.from_str(
self.dealer.abbreviation()
).value + auction
Expand All @@ -57,14 +57,18 @@ async def get_card_play(self, auction):
declarer = Direction.from_str(contract[-1])
dummy = declarer.offset(2)
leader = declarer.offset(1)
raw_lead = (
bots.BotLead(self.vuls, self.diag.hands[leader].to_pbn(), self.models)
.lead(auction)
.to_dict()["candidates"][0]["card"]
)

if raw_lead == None:
raw_lead = (
bots.BotLead(self.vuls, self.diag.hands[leader].to_pbn(), self.models)
.lead(auction)
.to_dict()["candidates"][0]["card"]
)

lead = lead_real_card(
self.diag.hands[leader], raw_lead, BiddingSuit.from_str(contract[1])
)

self.diag.hands[leader].remove(lead)

tricks = [[str(lead)]]
Expand Down

0 comments on commit 275ccf0

Please sign in to comment.