Skip to content

Commit

Permalink
Merge branch 'main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
zdraganov committed Oct 30, 2024
2 parents 9738063 + cf74a53 commit 4343e17
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 36 deletions.
8 changes: 2 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.9.3-stage.0](https://github.com/Seven-of-Di/ben/compare/v0.8.0-stage.0...v0.9.3-stage.0) (2024-10-29)
### [0.9.4](https://github.com/Seven-of-Di/ben/compare/v0.9.3...v0.9.4) (2024-10-01)


### Bug Fixes

* Parenthesis fix, Lia was accepting the claim too agressively ([e4a5ba2](https://github.com/Seven-of-Di/ben/commit/e4a5ba2b2c7b894270f3f7141094cc887fc63aa2))
* properly start the healthchecker and use starlette Response object ([b90471e](https://github.com/Seven-of-Di/ben/commit/b90471ef2d6674c7a0fa99ed9e1fa65e6020fe59))
* reenable healthz endpoint for Ben ([c229cb8](https://github.com/Seven-of-Di/ben/commit/c229cb858f52ea57244ba2c41fdf83390ce1b184))
* switch to simple HTTP API access healthcheck ([52087a1](https://github.com/Seven-of-Di/ben/commit/52087a1b1664198dea09d3e1f6847d4846fcd2b9))
* switch to simple HTTP API access healthcheck ([d5d2e6e](https://github.com/Seven-of-Di/ben/commit/d5d2e6e15ac36d4b0d379e955bd12c458685912f))
* revert to simple http healthcheck ([b7e747b](https://github.com/Seven-of-Di/ben/commit/b7e747b885379862229c58bc280e3cd523b1be56))
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.3-stage.0
0.9.4
8 changes: 4 additions & 4 deletions src/meta_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def replay_last_match(specific_boards: List[int] | None = None):
print(latest_file)

run_tm_btwn_ben_versions(
force_same_sequence=False,
force_same_sequence=True,
force_same_lead=True,
force_same_card_play=True,
force_same_card_play=False,
file=latest_file,
specific_boards=specific_boards,
)


if __name__ == "__main__":
# replay_last_match(specific_boards = [46])
replay_last_match([12,17,31,39,40,44,49,51,53,55])
replay_last_match(specific_boards=[5])
# replay_last_match()
14 changes: 7 additions & 7 deletions src/starlette_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,16 @@ async def alert_bid(request: Request):
logging.exception(e)
return {'error': str(e)},500

health_checker = HealthChecker()
health_checker.start()
# health_checker = HealthChecker()
# health_checker.start()

async def healthz(_: Request):
# return Response("OK", status_code=200)
healthy = health_checker.healthy()
if healthy:
return Response("OK", status_code=200)
return Response("OK", status_code=200)
# healthy = health_checker.healthy()
# if healthy:
# return Response("OK", status_code=200)

return Response("FAILURE", status_code=500)
# return Response("FAILURE", status_code=500)

class TracingHeaderMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
Expand Down
65 changes: 48 additions & 17 deletions src/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@
NEW_CARD_TIME: List[float] = [0, 0]
OLD_CARD_TIME: List[float] = [0, 0]
RECEIVING_BOT_NAME = "Ben"
RECEIVED_BOT_NAME = "Lia Gavin advanced"
RECEIVED_BOT_NAME = "Lia 2 over 1"
boards_with_different_leads = []
TIME_STAMP = datetime.datetime.now().strftime("%H-%M")
DATE = datetime.datetime.today().strftime("%m_%d_%Y")
CONVENTION_NS_OPEN = "TWO_OVER_ONE"
CONVENTION_NS_CLOSED = "GAVIN_ADVANCED"
CONVENTION_NS_CLOSED = "TWO_OVER_ONE"

CONVENTION_EW_OPEN = CONVENTION_NS_CLOSED
CONVENTION_EW_CLOSED = CONVENTION_NS_OPEN

match_name = "{} vs {}".format(RECEIVING_BOT_NAME, RECEIVED_BOT_NAME)
file_name = "{} - {} - {}.pbn".format(match_name, DATE, TIME_STAMP)


def from_lin_to_request(
lin_str: str,
Expand All @@ -54,16 +57,28 @@ def from_lin_to_request(
raise Exception("bid and play are both not None")

lin_str = lin_str.replace("%7C", "|")
lin_str = lin_str.split("lin=", maxsplit=1)[1]
board_number = lin_str.split("Board%20")[1].split("|")[0]
lin_str = lin_str.split("lin=", maxsplit=1)[1] if "lin=" in lin_str else lin_str
if "Board" in lin_str:
lin_str = lin_str.split("Board", maxsplit=1)[1]
board_number = lin_str.split("|", maxsplit=1)[0].strip()
else:
board_number = 1
vul_str = board_number_to_vul(int(board_number))
lin_str = lin_str.split("|", maxsplit=3)[3]
lin_str = lin_str.split("md|", maxsplit=1)[1]
lin_dealer_to_direction = {
"1": Direction.SOUTH,
"2": Direction.WEST,
"3": Direction.NORTH,
"4": Direction.EAST,
}
# Remove all the alerts, format is |an|alert, with a regular expression
while "|an|" in lin_str:
lin_str = (
lin_str.split("|an|", maxsplit=1)[0]
+ lin_str.split("|an|", maxsplit=1)[1].split("|", maxsplit=1)[1]
)

lin_str = lin_str.replace("|pg|", "")
dealer: Direction = lin_dealer_to_direction[lin_str[0]]
diag_lin = lin_str[1:].split("|")[0]
diag = Diag.init_from_lin(diag_lin)
Expand Down Expand Up @@ -154,7 +169,7 @@ def bidding_el_to_pbn(el: str):
"auction": bidding_str,
"next_player": turn_to_play.abbreviation(),
"tricks": play_as_list_of_list,
"cheating_diag_pbn": diag.print_as_pbn(),
# "cheating_diag_pbn": diag.print_as_pbn(),
}
)

Expand Down Expand Up @@ -215,6 +230,7 @@ def send_request(
# new_ben_called = (open_room and direction in [Direction.NORTH, Direction.SOUTH]) or (
# not open_room and direction in [Direction.EAST, Direction.WEST])
ben_called = (
(
(
open_room
and direction in [Direction.NORTH, Direction.SOUTH]
Expand All @@ -235,8 +251,12 @@ def send_request(
and direction in [Direction.NORTH, Direction.SOUTH]
and RECEIVED_BOT_NAME == "Ben"
)
) or type_of_action == "play_card"
# or type_of_action == "play_card"
)

) and not type_of_action == "place_bid"
port = "http://localhost:{}".format("5001" if ben_called else "5002")
print("Sending to port {}".format(port))
start = time.time()
res = requests.post("{}/{}".format(port, type_of_action), json=data)
request_time = time.time() - start
Expand All @@ -254,7 +274,7 @@ def send_request(
else:
OLD_BIDDING_TIME[0] += request_time
OLD_BIDDING_TIME[1] += 1
print("Sending to port {}".format(port))

print(res.json())
return res.json()

Expand All @@ -273,6 +293,7 @@ def bid_deal(deal: Deal, open_room: bool):
"auction": sequence.get_as_ben_request(),
"conventions_ew": CONVENTION_EW_OPEN if open_room else CONVENTION_EW_CLOSED,
"conventions_ns": CONVENTION_NS_OPEN if open_room else CONVENTION_NS_CLOSED,
"debug_mode": "True",
}
res = (
send_request("place_bid", data, current_player, open_room)
Expand Down Expand Up @@ -362,8 +383,17 @@ def full_card_play(
"contract_direction": contract.declarer.abbreviation(),
"next_player": current_player.abbreviation(),
"tricks": tricks,
"cheating_diag_pbn": deal.diag.print_as_pbn(),
"conventions_ew": CONVENTION_EW_OPEN if open_room else CONVENTION_EW_CLOSED,
"conventions_ns": CONVENTION_NS_OPEN if open_room else CONVENTION_NS_CLOSED,
# "cheating_diag_pbn": deal.diag.print_as_pbn(),
"playing_mode": "teams",
"logging_infos": {
"board_number": deal.board_number,
"open_room": open_room,
"receiving_bot_name": RECEIVING_BOT_NAME,
"received_bot_name": RECEIVED_BOT_NAME,
"file_name": file_name,
},
}
res = send_request(
type_of_action="play_card",
Expand Down Expand Up @@ -640,18 +670,19 @@ def compare_two_tests(set_of_boards_1: List[Board], set_of_boards_2: List[Board]


if __name__ == "__main__":
# run_tm_btwn_ben_versions(
# force_same_lead=True,
# force_same_card_play=True,
# deal_random=True,
# ditch_if_same_bidding=True,
# )
run_tm_btwn_ben_versions(
force_same_lead=True,
# force_same_card_play=True,
deal_random=True,
force_same_sequence=True,
# ditch_if_same_bidding=True,
)
# tests = run_tests()
# compare_two_tests(load_test_pbn("avant.pbn"),
# load_test_pbn("après.pbn"))
# load_test_pbn("c4f380988fc67c0fe6e5f4bc5502d67a3b45d2c0.pbn")
link = r"https://play.intobridge.com/hand?lin=pn|Marcelo,Lia,Lia,Lia|md|1SKQJHJ83DT83CAJ65,ST9HQ652DAKQJ6CQ3,S853HKD9542CK9874,SA7642HAT974D7CT2|ah|Board%203|mb|1C|mb|1D|mb|2C|mb|d|mb|p|mb|2H|mb|p|mb|3H|mb|p|mb|4H|mb|p|mb|p|mb|p|pc|C4|pc|C2|pc|CA|pc|C3|pc|C5|pc|CQ|pc|CK|pc|CT|pc|S8|pc|SA|pc|SK|pc|S9|pc|D7|pc|D8|pc|DQ|pc|D5|pc|DJ|pc|D2|pc|S2|pc|D3|pc|DA|pc|D4|pc|S4|pc|DT|pc|H2|pc|HK|pc|HA|mc|11|sv|e|&boardId=667bdcefce13c5c473353403"
print(from_lin_to_request(link, Card_.from_str("HA")))
link = r"pn|Ben,Lia 2 over 1,Ben,Lia 2 over 1|qx|c19,BOARD 19|rh||ah|Board 19|md|1S7HKJT982DAK7CAJ6,SQ86H7DQ8654C8732,SA93HA653D3CQT954|sv|e|sa|0|mb|1H|an|11-23 hcp -- 5+!H|mb|p|mb|4D|an|ART3-6!S 4-7!H 3-6!C -- Game values -- Splinter - !D|mb|4S|mb|d|an|Penalty Double|mb|p|mb|p|an|4-6!H -- |mb|p|pg||pc|DA|pc|D4|pc|D3|pc|D2|pg||pc|HJ|pc|H7|pc|HA|pc|H4|pg||pc|C5|pc|CK|pc|CA|pc|C2|pg||pc|DK|pc|D5|pc|H5|pc|D9|pg||pc|S7|pc|S6|pc|SA|pc|S5|pg||pc|CT|pc|ST|mc|8|pg||"
print(from_lin_to_request(link, Card_.from_str("D9")))
# print(from_lin_to_request(link, bid_to_remove_after="X"))

# print(from_lin_to_request(link, None))
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.9.3-stage.0"
"version": "0.9.4"
}

0 comments on commit 4343e17

Please sign in to comment.