当前位置: 首页>>代码示例>>Python>>正文


Python gamestate.GameState类代码示例

本文整理汇总了Python中gamestate.GameState的典型用法代码示例。如果您正苦于以下问题:Python GameState类的具体用法?Python GameState怎么用?Python GameState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GameState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_mortgage

	def test_mortgage(self):
		state = GameState(1)
		player = state.players[0]

		# Set up player to own a railroad
		state.apply(GroupOfChanges([
			GameStateChange.buy_property(state.squares[INDEX[PENNSYLVANIA_RAILROAD]],
				player, state.bank)
		]))

		# Test mortgage
		str_before = str(state)
		state.apply(GroupOfChanges([
			GameStateChange.mortgage(state.squares[INDEX[PENNSYLVANIA_RAILROAD]], state)
		]))
		str_after = str(state)
		expected_diff = [
			# Player cash
			('Cash: 1300', 'Cash: 1400'),

			# Bank cash
			('Cash: 200', 'Cash: 100'),

			# Pennsylvania Railroad stats
			('Mortgaged: False', 'Mortgaged: True')
		]
		self.assertDiffGameStates(str_before, str_after, expected_diff,
			msg='Pennsylvania Railroad was not mortgaged properly')
开发者ID:LK,项目名称:monopoly-simulator,代码行数:28,代码来源:test_gamestate_apply.py

示例2: test_unmortgage

	def test_unmortgage(self):
		state = GameState(1)
		player = state.players[0]

		# Set up player to own a mortgaged utility
		state.apply(GroupOfChanges([
			GameStateChange.buy_property(state.squares[INDEX[ELECTRIC_COMPANY]],
				player, state.bank, mortgaged=True)
		]))

		# Test unmortgage
		str_before = str(state)
		state.apply(GroupOfChanges([
			GameStateChange.unmortgage(state.squares[INDEX[ELECTRIC_COMPANY]], state)
		]))
		str_after = str(state)
		expected_diff = [
			# Player cash
			('Cash: 1425', 'Cash: 1342'),

			# Bank cash
			('Cash: 75', 'Cash: 158'),

			# Electric Company stats
			('Mortgaged: True', 'Mortgaged: False')
		]
		self.assertDiffGameStates(str_before, str_after, expected_diff,
			msg='Electric Company was not unmortgaged properly')	
开发者ID:LK,项目名称:monopoly-simulator,代码行数:28,代码来源:test_gamestate_apply.py

示例3: test_invalid_move

 def test_invalid_move(self):
     """Tests that invalid moves raise an exception"""
     GameStateTest.G.add_edge(0, 1)
     state = GameState(GameStateTest.G)
     state.make_move(0)
     state.make_move(1)
     self.assertRaises(InvalidMoveException)
开发者ID:Hydrotoast,项目名称:SnortSolver,代码行数:7,代码来源:test_gamestate.py

示例4: test_build_house

	def test_build_house(self):
		state = GameState(1)

		# Set up a player to own oranges with no houses
		player = state.players[0]
		oranges = [ST_JAMES_PLACE, TENNESSEE_AVENUE, NEW_YORK_AVENUE]
		
		changes = []
		for prop_name in oranges:
			changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]],
				player, state.bank))

		state.apply(GroupOfChanges(changes))

		# Test house build
		str_before = str(state)
		state.apply(GroupOfChanges([
			GameStateChange.build(state.squares[INDEX[NEW_YORK_AVENUE]], state)
		]))
		str_after = str(state)
		expected_diff = [
			('Cash: 940', 'Cash: 840'),          # player cash
			('Cash: 560', 'Cash: 660'),          # bank cash
			('Num houses: 0', 'Num houses: 1'),  # new york avenue
			('Houses remaining: 32', 'Houses remaining: 31')
		]
		self.assertDiffGameStates(str_before, str_after, expected_diff,
			msg='House build was not applied properly')
开发者ID:LK,项目名称:monopoly-simulator,代码行数:28,代码来源:test_gamestate_apply.py

示例5: test_transfer_money_bank_to_player

	def test_transfer_money_bank_to_player(self):
		import random

		state = GameState(1)
		player = state.players[0]

		# Transfer random amounts of money, and test that GameState is correct
		for trial in range(0, 100):
			player_cash_before = player.cash
			bank_cash_before = state.bank.cash
			amount = random.randint(1, player_cash_before)

			str_before = str(state)
			state.apply(GroupOfChanges([
				GameStateChange.transfer_money(state.bank, player, amount)]))
			str_after = str(state)
			expected_diff = [
				# Player cash
				('Cash: %d' % player_cash_before,
				 'Cash: %d' % (player_cash_before + amount)),

				# Bank cash
				('Cash: %d' % bank_cash_before,
				 'Cash: %d' % (bank_cash_before - amount))
			]
			self.assertDiffGameStates(str_before, str_after, expected_diff,
				msg='$%d was not transferred to player correctly. Here is diff:' % amount)
开发者ID:LK,项目名称:monopoly-simulator,代码行数:27,代码来源:test_gamestate_apply.py

示例6: test_init

 def test_init(self):
     """Tests the initialization of a GameState"""
     GameStateTest.G.add_edge(0, 1)
     state = GameState(GameStateTest.G)
     self.assertEquals(state.turn, labels.RED)
     self.assertFalse(state.is_gameover())
     self.assertFalse(state.is_terminal())
开发者ID:Hydrotoast,项目名称:SnortSolver,代码行数:7,代码来源:test_gamestate.py

示例7: test_buy_property_mortgaged

	def test_buy_property_mortgaged(self):
		state = GameState(1)
		player = state.players[0]

		# Test buying Pennsylvania Avenue mortgaged
		str_before = str(state)
		state.apply(GroupOfChanges([
			GameStateChange.buy_property(state.squares[INDEX[PENNSYLVANIA_AVENUE]],
				player, state.bank, mortgaged=True)
		]))
		str_after = str(state)
		expected_diff = [
			# Player stats
			('Cash: 1500', 'Cash: 1340'),
			('', 'Pennsylvania Avenue, '),
			('6: 0', '6: 1'),

			# Bank stats
			('Cash: 0', 'Cash: 160'),
			('Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, Virginia Avenue, Pennsylvania Railroad, St. James Place, Tennessee Avenue, New York Avenue, Kentucky Avenue, Indiana Avenue, Illinois Avenue, B. & O. Railroad, Atlantic Avenue, Ventnor Avenue, Water Works, Marvin Gardens, Pacific Avenue, North Carolina Avenue, Pennsylvania Avenue, Short Line Railroad, Park Place, Boardwalk, ',
				'Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, Virginia Avenue, Pennsylvania Railroad, St. James Place, Tennessee Avenue, New York Avenue, Kentucky Avenue, Indiana Avenue, Illinois Avenue, B. & O. Railroad, Atlantic Avenue, Ventnor Avenue, Water Works, Marvin Gardens, Pacific Avenue, North Carolina Avenue, Short Line Railroad, Park Place, Boardwalk, '),
			('6: 3', '6: 2'),

			# Pennsylvania Avenue stats
			('Mortgaged: False', 'Mortgaged: True')
		]
		self.assertDiffGameStates(str_before, str_after, expected_diff,
			msg='Pennsylvania Avenue was not mortgaged properly')
开发者ID:LK,项目名称:monopoly-simulator,代码行数:28,代码来源:test_gamestate_apply.py

示例8: test_change_position_landing_on_go

	def test_change_position_landing_on_go(self):
		state = GameState(1)
		player = state.players[0]

		# Set up player's initial position at Short Line Railroad
		state.apply(GroupOfChanges([
			GameStateChange.change_position(player, INDEX[SHORT_LINE_RAILROAD], state.bank,
				state.squares)
		]))

		# Test player changing position to Go
		str_before = str(state)
		state.apply(GroupOfChanges([
			GameStateChange.change_position(player, INDEX[GO], state.bank, state.squares)
		]))
		str_after = str(state)
		expected_diff = [
			# Player stats
			('Position: %d' % INDEX[SHORT_LINE_RAILROAD],
			 'Position: %d' % INDEX[GO]),
			('Cash: 1500', 'Cash: 1700'),

			# Bank stats
			('Cash: 0', 'Cash: -200')
		]
		self.assertDiffGameStates(str_before, str_after, expected_diff,
			msg='Player did not pass Go properly')
开发者ID:LK,项目名称:monopoly-simulator,代码行数:27,代码来源:test_gamestate_apply.py

示例9: test_buy_property_from_something

	def test_buy_property_from_something(self):
		state = GameState(1)
		player = state.players[0]

		# Set up player with some properties (two of the three greens)
		changes = []
		for prop_name in [PACIFIC_AVENUE, PENNSYLVANIA_AVENUE]:
			changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]],
				player, state.bank))

		state.apply(GroupOfChanges(changes))

		# Test buying North Carolina Avenue
		str_before = str(state)
		state.apply(GroupOfChanges([
			GameStateChange.buy_property(state.squares[INDEX[NORTH_CAROLINA_AVENUE]],
				player, state.bank)
		]))
		str_after = str(state)
		expected_diff = [
			# Player 1 stats
			('Cash: 880', 'Cash: 580'), 
			('Pacific Avenue, Pennsylvania Avenue, ', 'Pacific Avenue, Pennsylvania Avenue, North Carolina Avenue, '),
			('6: 2', '6: 3'),

			# Bank stats
			('Cash: 620', 'Cash: 920'),
			('Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, Virginia Avenue, Pennsylvania Railroad, St. James Place, Tennessee Avenue, New York Avenue, Kentucky Avenue, Indiana Avenue, Illinois Avenue, B. & O. Railroad, Atlantic Avenue, Ventnor Avenue, Water Works, Marvin Gardens, North Carolina Avenue, Short Line Railroad, Park Place, Boardwalk, ',
			 'Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, Virginia Avenue, Pennsylvania Railroad, St. James Place, Tennessee Avenue, New York Avenue, Kentucky Avenue, Indiana Avenue, Illinois Avenue, B. & O. Railroad, Atlantic Avenue, Ventnor Avenue, Water Works, Marvin Gardens, Short Line Railroad, Park Place, Boardwalk, '),
			('6: 1', '6: 0')
		]
		self.assertDiffGameStates(str_before, str_after, expected_diff,
			msg='North Carolina Avenue was not purchased properly')
开发者ID:LK,项目名称:monopoly-simulator,代码行数:33,代码来源:test_gamestate_apply.py

示例10: Agent

class Agent(object):
    
    def __init__(self, name="Marty"):
       self.name = name
       self.gameState = None
       
    def ingestState(self, data):
        """ Ingests the given gamestate from the network.
        """
        # ignorant agents might not do anything with the state
        if not data:
            return

        args = struct.unpack('!ffffffB',data)
        
        self.gameState = GameState(args[0],args[1],args[2],args[3],args[4],args[5])
        self.gameState.parseFlags(args[6])


    def chooseAction(self):
        """ Chooses an action, based off of a given game state.
            Returned is the bitwise or'ed set of actions.  
        """
        print "nothing"
        pass
开发者ID:leahkim,项目名称:CS194Project,代码行数:25,代码来源:agent.py

示例11: test_Copy

 def test_Copy(self):
     s = GameState()
     u = GameState()
     u.ball.pos_x = 100
     u.ball.pos_y = 200
     u.ball.vel_x = 300
     u.ball.vel_y = 400
     u.paddle_left.pos_y = -100
     u.paddle_left.vel_y = -200
     u.paddle_right.pos_y = -300
     u.paddle_right.vel_y = -400
     u.frame = 30
     u.key_flags = 300
     u.Copy(s)
     self.assertTrue(s.ball.pos_x == u.ball.pos_x)
     self.assertTrue(s.ball.pos_y == u.ball.pos_y)
     self.assertTrue(s.ball.vel_x == u.ball.vel_x)
     self.assertTrue(s.ball.vel_y == u.ball.vel_y)
     self.assertTrue(s.paddle_left.pos_y == u.paddle_left.pos_y)
     self.assertTrue(s.paddle_left.vel_y == u.paddle_left.vel_y)
     self.assertTrue(s.paddle_right.vel_y == u.paddle_right.vel_y)
     self.assertTrue(s.paddle_right.pos_y == u.paddle_right.pos_y)
     self.assertTrue(s.frame == u.frame)
     self.assertTrue(s.key_flags == u.key_flags)
     pass
开发者ID:ryutaroikeda,项目名称:triplepong,代码行数:25,代码来源:gamestate_test.py

示例12: test_Serialize_and_Deserialize

 def test_Serialize_and_Deserialize(self):
     s = GameState()
     s.ball.pos_x = 100
     s.ball.pos_y = -50
     s.ball.vel_x = -43
     s.ball.vel_y = 6
     s.paddle_left.pos_y = 90
     s.paddle_left.vel_y = 4
     s.paddle_right.pos_y = 2
     s.paddle_right.vel_y = 87
     s.key_flags = 3
     s.frame = 112734590
     s.keybits = 1 << 63
     # Ignore the EventType header.
     b = s.Serialize()[4:]
     t = GameState()
     t.Deserialize(b)
     self.assertTrue(t.ball.pos_x == s.ball.pos_x)
     self.assertTrue(t.ball.pos_y == s.ball.pos_y)
     self.assertTrue(t.ball.vel_x == s.ball.vel_x)
     self.assertTrue(t.ball.vel_y == s.ball.vel_y)
     self.assertTrue(t.paddle_left.pos_y == s.paddle_left.pos_y)
     self.assertTrue(t.paddle_left.vel_y == s.paddle_left.vel_y)
     self.assertTrue(t.paddle_right.pos_y == s.paddle_right.pos_y)
     self.assertTrue(t.paddle_right.vel_y == s.paddle_right.vel_y)
     self.assertTrue(t.key_flags == s.key_flags)
     self.assertTrue(t.frame == s.frame)
     pass
开发者ID:ryutaroikeda,项目名称:triplepong,代码行数:28,代码来源:gamestate_test.py

示例13: __init__

    def __init__(self, manager):
        GameState.__init__(self, manager)

        sys_font = Font(get_default_font(), options.font_size)
        self.message1 = sys_font.render("Andrew's Bitchin' Yars' Revenge Clone",
                                        True, options.white)
        self.message2 = sys_font.render("Press shoot button (space) to start.",
                                        True, options.white)
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:8,代码来源:title.py

示例14: __init__

    def __init__(self, manager, score, lives, next_state):
        GameState.__init__(self, manager)

        sys_font = Font(get_default_font(), options.font_size)
        self.score_text = sys_font.render(str(score), True, options.white)
        self.lives_text = sys_font.render(str(lives), True, options.white)

        self.next_state = next_state
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:8,代码来源:infoscreen.py

示例15: test_RotateRoles_1

 def test_RotateRoles_1(self):
     e = UDPGameEngine()
     s = GameState()
     s.player_size = 1
     s.roles = [GameState.ROLE_LEFT_PADDLE]
     s.players = [-1, 0]
     e.RotateRoles(s)
     self.assertTrue(s.roles == [GameState.ROLE_LEFT_PADDLE])
     self.assertTrue(s.players == [-1, 0])
开发者ID:ryutaroikeda,项目名称:triplepong,代码行数:9,代码来源:udpgameengine_test.py


注:本文中的gamestate.GameState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。