def move(self) -> StockRoundMove:
     msg = json.dumps({
         "move_type": "PASS",
         "player_id": "A",
     })
     move = Move.fromMessage(msg)
     return StockRoundMove.fromMove(move)
 def move(self) -> AuctionDecisionMove:
     msg = json.dumps({
         "player_id": "F",
         "move_type": "REJECT",
     })
     move = Move.fromMessage(msg)
     return AuctionDecisionMove.fromMove(move)
 def move(self) -> AuctionDecisionMove:
     msg = json.dumps({
         "player_id": "F",
         "move_type": "ACCEPT",
         "accepted_player_id": "B"
     })
     move = Move.fromMessage(msg)
     return AuctionDecisionMove.fromMove(move)
 def bid(self) -> AuctionBidMove:
     msg = json.dumps({
         "player_id": "A",
         "private_company_id": "1",
         "move_type": "PASS",
     })
     move = Move.fromMessage(msg)
     return AuctionBidMove.fromMove(move)
 def move(self) -> StockRoundMove:
     msg = json.dumps({
         "move_type": "SELL",
         "player_id": "A",
         "for_sale_raw": [["ABC", 10], ["DEF", 10]]
     })
     move = Move.fromMessage(msg)
     return StockRoundMove.fromMove(move)
 def bid(self, amount) -> AuctionBidMove:
     msg = json.dumps({
         "player_id": "A",
         "private_company_id": "1",
         "move_type": "BID",
         "amount": amount
     })
     move = Move.fromMessage(msg)
     return AuctionBidMove.fromMove(move)
예제 #7
0
 def _pass_move(self):
     move_json = {
         "private_company_order": 1, # Doesn't really matter at this point.
         "move_type": "PASS",
         "player_id": "A",
         "bid_amount": 265
     }
     move = Move.fromMessage(json.dumps(move_json))
     return BuyPrivateCompanyMove.fromMove(move)
 def _getMove(self):
     move_json = {
         "private_company_order": 0,
         "move_type": "BUY",
         "player_id": "A",
         "bid_amount": 0
     }
     move = Move.fromMessage(json.dumps(move_json))
     return BuyPrivateCompanyMove.fromMove(move)
 def move(self) -> StockRoundMove:
     msg = json.dumps({
         "player_id": "A",
         "public_company_id": "ABC",
         "source": "IPO",
         "move_type": "BUY",
         "ipo_price": 90
     })
     move = Move.fromMessage(msg)
     return StockRoundMove.fromMove(move)
예제 #10
0
 def move(self) -> StockRoundMove:
     msg = json.dumps({
         "move_type": "BUYSELL",
         "player_id": "A",
         "public_company_id": "GHI",
         "source": "IPO",
         "ipo_price": 76,
         "for_sale_raw": [["ABC", 10], ["DEF", 10]]
     })
     move = Move.fromMessage(msg)
     return StockRoundMove.fromMove(move)
예제 #11
0
    def pass_on_bid(player_name, privatecompany_shortname, state:MutableGameState):
        company = next(
            company for company in state.private_companies if company.short_name == privatecompany_shortname
        )
        player = next(
            player for player in state.players if player_name == player.name
        )

        move_json = {
            "move_type": "PASS",
            "private_company_order": company.order,  # Doesn't really matter at this point.
            "player_id": player.id,
        }

        move = Move.fromMessage(json.dumps(move_json))
        return BuyPrivateCompanyMove.fromMove(move)
예제 #12
0
파일: main.py 프로젝트: jmahmood/Daemon18xx
def ongoing_game(pipe_filen="/tmp/mypipe"):
    """Conveys messages from a file pipe to the running daemon process"""
    pipe_path = pipe_filen
    if not os.path.exists(pipe_path):
        os.mkfifo(pipe_path)
    # Open the fifo. We need to open in non-blocking mode or it will stalls until
    # someone opens it for writting
    pipe_fd = os.open(pipe_path, os.O_RDONLY | os.O_NONBLOCK)
    continue_game = True
    with os.fdopen(pipe_fd) as pipe:
        while continue_game:
            msg = pipe.read()
            if msg:
                yield Move.fromMessage(msg)
            print("Waiting for command.")
            time.sleep(0.5)
            continue_game = yield
    def testInitializeMove(self):
        move_json = {
            "private_company_order": 1,
            "move_type": "BUY",
            "player_id": "A",
            "bid_amount": 0
        }
        move = Move.fromMessage(json.dumps(move_json))
        private_company_purchase_move = BuyPrivateCompanyMove.fromMove(move)
        self.assertEqual(private_company_purchase_move.private_company_order,
                         1)
        self.assertEqual(private_company_purchase_move.move_type, BidType.BUY)
        self.assertEqual(private_company_purchase_move.player_id, "A")
        self.assertEqual(private_company_purchase_move.bid_amount, 0)

        self.assertIsNone(private_company_purchase_move.player)
        self.assertIsNone(private_company_purchase_move.private_company)

        game_context = MutableGameState()
        game_context.players = [fake_player("A"), fake_player("B")]
        game_context.private_companies = [
            fake_private_company(0),
            fake_private_company(1)
        ]

        private_company_purchase_move.backfill(game_context)

        self.assertEqual(private_company_purchase_move.player,
                         game_context.players[0])
        self.assertEqual(private_company_purchase_move.private_company,
                         game_context.private_companies[1])

        duck_type_checking_player = fake_player("A")
        duck_type_checking_company = fake_private_company(1)
        self.assertEqual(private_company_purchase_move.player,
                         duck_type_checking_player)
        self.assertEqual(private_company_purchase_move.private_company,
                         duck_type_checking_company)