コード例 #1
0
def main(argv):
    if len(argv) > 1:
        raise app.UsageError("Too many command-line arguments.")
    game = pyspiel.load_game("bridge_uncontested_bidding", {
        "relative_scoring": True,
        "rng_seed": FLAGS.rng_seed,
    })
    bots = [
        bluechip_bridge_uncontested_bidding.BlueChipBridgeBot(
            game, 0, _WBridge5Client(FLAGS.bot_cmd)),
        bluechip_bridge_uncontested_bidding.BlueChipBridgeBot(
            game, 1, _WBridge5Client(FLAGS.bot_cmd)),
    ]
    results = []

    for i_deal in range(FLAGS.num_deals):
        state = _run_once(game.new_initial_state(), bots)
        print("Deal #{}; final state:\n{}".format(i_deal, state))
        results.append(state.returns())

    stats = np.array(results)
    mean = np.mean(stats, axis=0)
    stderr = np.std(stats, axis=0, ddof=1) / np.sqrt(FLAGS.num_deals)
    print(u"Absolute score: {:+.1f}\u00b1{:.1f}".format(mean[0], stderr[0]))
    print(u"Relative score: {:+.1f}\u00b1{:.1f}".format(mean[1], stderr[1]))
コード例 #2
0
 def test_complete_session_west(self):
     game = pyspiel.load_game("bridge_uncontested_bidding")
     mock_client = absltest.mock.Mock(
         **{
             "read_line.side_effect": [
                 'Connecting "WBridge5" as ANYPL using protocol version 18',
                 "WEST ready for teams",
                 "WEST ready to start",
                 "WEST ready for deal",
                 "WEST ready for cards",
                 "WEST bids 1D Alert.",
                 "WEST ready for NORTH's bid",
                 "WEST ready for EAST's bid",
                 "WEST ready for SOUTH's bid",
                 "WEST bids 2H",
                 "WEST ready for NORTH's bid",
                 "WEST ready for EAST's bid",
                 "WEST ready for SOUTH's bid",
             ]
         })
     bot = bluechip_bridge_uncontested_bidding.BlueChipBridgeBot(
         game, 0, mock_client)
     state = game.deserialize_state("A86.J543.K642.A3 J.KQ962.T953.J96")
     policy, action = bot.step(state)
     self.assertEqual(action, _BID_1D)
     self.assertEqual(policy, (_BID_1D, 1.0))
     state.apply_action(action)
     state.apply_action(_BID_1H)
     policy, action = bot.step(state)
     self.assertEqual(action, _BID_2H)
     self.assertEqual(policy, (_BID_2H, 1.0))
     state.apply_action(action)
     # Finished - now check that the game state is correct.
     self.assertEqual(str(state),
                      "A86.J543.K642.A3 J.KQ962.T953.J96 1D-1H-2H")
     # Check that we received the expected messages.
     mock_client.assert_has_calls([
         absltest.mock.call.start(),
         absltest.mock.call.read_line(),
         absltest.mock.call.send_line('WEST ("WBridge5") seated'),
         absltest.mock.call.read_line(),
         absltest.mock.call.send_line(
             'Teams: N/S "opponents" E/W "bidders"'),
         absltest.mock.call.read_line(),
         absltest.mock.call.send_line("start of board"),
         absltest.mock.call.read_line(),
         absltest.mock.call.send_line(
             "Board number 8. Dealer WEST. Neither vulnerable."),
         absltest.mock.call.read_line(),
         absltest.mock.call.send_line(
             "WEST's cards: S A 8 6. H J 5 4 3. D K 6 4 2. C A 3."),
         absltest.mock.call.read_line(),
         absltest.mock.call.read_line(),
         absltest.mock.call.send_line("NORTH PASSES"),
         absltest.mock.call.read_line(),
         absltest.mock.call.send_line("EAST bids 1H"),
         absltest.mock.call.read_line(),
         absltest.mock.call.send_line("SOUTH PASSES"),
         absltest.mock.call.read_line(),
     ])
コード例 #3
0
 def test_invalid_fixed_message(self):
   game = pyspiel.load_game("bridge_uncontested_bidding")
   mock_client = absltest.mock.Mock(
       **{
           "read_line.side_effect": [
               'Connecting "WBridge5" as ANYPL using protocol version 18',
               "WEST ready for cards",
           ]
       })
   bot = bluechip_bridge_uncontested_bidding.BlueChipBridgeBot(
       game, 0, mock_client)
   state = game.deserialize_state("A86.J543.K642.A3 J.KQ962.T953.J96")
   with self.assertRaisesRegex(
       ValueError,
       "Received 'WEST ready for cards' but expected 'WEST ready for teams'"):
     bot.step(state)