Exemplo n.º 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": pyspiel.GameParameter(True),
            "rng_seed": pyspiel.GameParameter(FLAGS.rng_seed),
        })
    bots = [
        bluechip_bridge_wrapper.BlueChipBridgeBot(
            game, 0, _WBridge5Client(FLAGS.bot_cmd)),
        bluechip_bridge_wrapper.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]))
 def test_complete_session_east(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',
               "EAST ready for teams",
               "EAST ready to start",
               "EAST ready for deal",
               "EAST ready for cards",
               "EAST ready for WEST's bid",
               "EAST ready for NORTH's bid",
               "EAST bids 1H",
               "EAST ready for SOUTH's bid",
               "EAST ready for WEST's bid",
               "EAST ready for NORTH's bid",
               "EAST PASSES",
           ]
       })
   bot = bluechip_bridge_wrapper.BlueChipBridgeBot(game, 1, mock_client)
   state = game.deserialize_state("A86.J543.K642.A3 J.KQ962.T953.J96")
   state.apply_action(_BID_1D)
   policy, action = bot.step(state)
   self.assertEqual(action, _BID_1H)
   self.assertEqual(policy, (_BID_1H, 1.0))
   state.apply_action(action)
   state.apply_action(_BID_2H)
   policy, action = bot.step(state)
   self.assertEqual(action, bluechip_bridge_wrapper._PASS_ACTION)
   self.assertEqual(policy, (bluechip_bridge_wrapper._PASS_ACTION, 1.0))
   # 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('EAST ("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(
           "EAST's cards: S J. H K Q 9 6 2. D T 9 5 3. C J 9 6."),
       absltest.mock.call.read_line(),
       absltest.mock.call.send_line("WEST bids 1D"),
       absltest.mock.call.read_line(),
       absltest.mock.call.send_line("NORTH PASSES"),
       absltest.mock.call.read_line(),
       absltest.mock.call.read_line(),
       absltest.mock.call.send_line("SOUTH PASSES"),
       absltest.mock.call.read_line(),
       absltest.mock.call.send_line("WEST bids 2H"),
       absltest.mock.call.read_line(),
       absltest.mock.call.send_line("NORTH PASSES"),
   ])
 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_wrapper.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)